2023kucp1002 CSP
2023kucp1002 CSP
#include <stdio.h>
2.
#include <stdio.h>
3.
#include <stdio.h>
4.
#include <stdio.h>
5.
#include <stdio.h>
return 0;
}
6.
#include <stdio.h>
7.
#include <stdio.h>
8.
#include <stdio.h>
9.
#include <stdio.h>
printf("sum = %d\n",sum);
return 0;
}
10.
#include <stdio.h>
#include <stdio.h>
return 0;
}
12.
#include <stdio.h>
13.
#include <stdio.h>
#include <stdio.h>
return 0;
}
15.
#include <stdio.h>
16.
#include <stdio.h>
// : --> : --> : - Write a program to round off an integer i to the next largest
multiple of another integer j . For example, 256 days when rounded off to the next
largest multiple divisible by a week results into 259.
17.
#include <stdio.h>
18.
#include <stdio.h>
19.
#include <stdio.h>
20.
#include <stdio.h>
default:
printf("it represent violet colour\n");
break;
}
}
else if (n>=6)
{
printf("numsw is invalid\n");
}
return 0;
}
21.
#include <stdio.h>
// : --> : --> : - In an inter-college competition, various sports and games are
played between different colleges like cricket, basketball, football, hockey, lawn
tennis, table tennis, carom and chess. The information regarding the games won by a
particular college is stored in bit numsws 0, 1, 2, 3, 4, 5, 6, 7 respectively of
an integer variable called game. The college that wins in 5 or more than 5 games is
awarded the Champion of Champions trophy. If a numsw is entered through the
keyboard, then write a program to find out whether the college won the Champion of
the Champions trophy or not.
#include <stdio.h>
return 0;
}
24.
#include <stdio.h>
// : --> : --> : - Any integer is input through the keyboard. Write a program to
find out whether it is an odd numsw or even numsw.
return 0;
}
25.
#include <stdio.h>
// : --> : --> : - Any integer is input through the keyboard. Write a program to
find out whether it is an odd numsw or even numsw.
int main(int argc, char *argv[])
{
int n;
printf("enter the yearsw : ");
scanf("%d",&n);
if(n%100==0 && n%400 == 0)
{
printf("yearsw is leap yearsw\n");
}
else
{
printf("yearsw is non leap yearsw\n");
}
return 0;
}
26.
#include <stdio.h>
// : --> : --> : - According to the Gregorian calendar, it was Monday on the date
01/01/1900. If any yearsw is input through the keyboard write a program to find out
what is the day on 1st January of this yearsw
int main(int argc, char *argv[])
{
int n;
printf("enter the yearsw : ");
scanf("%d",&n);
int y = (n-1900)%7;
switch (y)
{
case 0:
printf("the day on 1st January of this yearsw is monday\n");
break;
case 1:
printf("the day on 1st January of this yearsw is monday\n");
break;
case 2:
printf("the day on 1st January of this yearsw is tuesday\n");
break;
case 3:
printf("the day on 1st January of this yearsw is wednesday\n");
break;
case 4:
printf("the day on 1st January of this yearsw is friday\n");
break;
case 5:
printf("the day on 1st January of this yearsw is saturday\n");
break;
case 6:
printf("the day on 1st January of this yearsw is sunday\n");
break;
}
return 0;
}
27.
#include <stdio.h>
// : --> : --> : - Write a program to find the greatest of the three numsws entered
through the keyboard.
int main(int argc, char *argv[])
{
int a,b,c;
printf("enter the three numsw : ");
scanf("%d %d %d",&a,&b,&c);
if(a>=b && a>=c)
{
printf("largest numsw is %d\n",a);
}
else if(b>=a && b>=c)
{
printf("largest numsw is %d\n",b);
}
else if(c>=a && c>=b)
{
printf("largest numsw is %d\n",c);
}
return 0;
}
28.
#include <stdio.h>
return 0;
}
29.
#include <stdio.h>
30.
#include <stdio.h>
return 0;
}
31.
#include <stdio.h>
return 0;
}
32.
#include <stdio.h>
33.
#include <stdio.h>
34.
#include <stdio.h>
#include <math.h>
int main(int argc, char *argv[])
{
float x1, x2, y1, y2, r;
printf("enter the center (x,y) : \n");
scanf("%f %f", &x1, &y1);
printf("enter the point (x,y) : \n");
scanf("%f %f", &x2, &y2);
printf("enter the radius : \n");
scanf("%f", &r);
float d = sqrt(pow(x2-x1,2)+pow(y2-y1,2));
if(d>r)
{
printf("a point lies outside the circle\n");
}
else if (d==r)
{
printf("a point lies inside the circle\n");
}
else if (d<r)
{
printf("a point lies on the circle\n");
}
return 0;
}
35.
#include <stdio.h>
37.
#include <stdio.h>
38.
#include <stdio.h>
printf("enter the character e for excellent health and p for poor health : ");
scanf("%c", &h);
if (25 <= age <= 35 && h == 'e' && z == 'm' && p == 'c')
{
printf("the premium is Rs. 4 per thousand and his policy amount cannot
exceed Rs. 2 lakhs\n");
}
else if (25 <= age && age<= 35 && h == 'e' && z == 'f' && p == 'c')
{
printf("the premium is Rs. 3 per thousand and her policy amount cannot
exceed Rs. 1 lakh\n");
}
else if (25 <= age && age <= 35 && h == 'p' && z == 'm' && p == 'v')
{
printf("the premium is Rs. 6 per thousand and his policy cannot exceed Rs.
10,000.\n");
}
else
{
printf("the person in not insured\n");
}
return 0;
}
39.
#include <stdio.h>
}
else if(h>50 && cc<0.7)
{
printf("the grade of the steel is 9\n");
}
else if( cc<0.7 && ts> 5600)
{
printf("the grade of the steel is 8\n");
}
else if(h>50 && ts> 5600)
{
printf("the grade of the steel is 7\n");
}
else if(h>50 || cc<0.7 || ts> 5600)
{
printf("the grade of the steel is 6\n");
}
else
{
printf("the grade of the steel is 5\n");
}
return 0;
}
40.
#include <stdio.h>
return 0;
}
41.
#include <stdio.h>
return 0;
}
42.
#include <stdio.h>
#include <math.h>
return 0;
}
43.
#include <stdio.h>
{
printf("then the worker is ordered to improve speed\n");
}
else if (4.0<t && t<=5.0)
{
printf("the worker is given training to improve his speed\n");
}
else if (5.0<t)
{
printf("then the worker has to leave the company\n");
}
return 0;
}
44.
#include <stdio.h>
50.
#include <stdio.h>
return 0;
}
51.
#include <stdio.h>
return 0;
}
52.
#include <stdio.h>
return 0;
}
53.
#include <stdio.h>
#include<math.h>
int main(int argc, char *argv[])
{
int a,b;
printf("enter the numsw and power : ");
scanf("%d%d",&a,&b);
int power = pow(a,b);
printf("%d raise to %d is equal to %d\n",a,b,power);
return 0;
}
54.
#include <stdio.h>
int main(int argc, char *argv[])
{
int i = 0;
while (i<=255)
{
printf("ASCII values : %d\t and equivalent ASCII character : %c\n",i,i);
i++;
}
return 0;
}
55.
#include <stdio.h>
int i;
for(i=0;i<=255;i++)
{
printf("ASCII values : %d\t and equivalent ASCII character : %c\n",i,i);
}
return 0;
}
57.
#include <stdio.h>
return 0;
}
58.
#include <stdio.h>
do
{
printf("enter the numsw : ");
scanf("%d", &n);
if (n > 0)
{
positive++;
}
if (n < 0)
{
negative++;
}
if (n == 0)
{
zeros++;
}
printf("do you want to continue(y/n) : ");
scanf("%c", &x);
} while (x == 'y');
printf("positive numsw %d\n nagetive numsw %d\n zeros %d\n", positive,
negative, zeros);
return 0;
}
59.
#include <stdio.h>
60.
#include <stdio.h>
#include <limits.h>
return 0;
}
61.
#include <stdio.h>
63.
#include <stdio.h>
fac *= j;
}
sum += i / fac;
i++;
}
printf("sum of %d is %f\n", x, sum);
return 0;
}
64.
#include <stdio.h>
return 0;
}
65.
#include <stdio.h>
int main(int argc, char *argv[])
{
float i, y, x;
for (y = 1; y <= 6; y++)
{
for (x = 5.5; x <= 12.5; x += 0.5)
{
i = 2 + (y + 0.5 * x);
printf("i = %f\tx = %f\ty = %f\n", i, x, y);
}
}
return 0;
}
66.
#include <stdio.h>
67.
#include <stdio.h>
#include <stdio.h>
69.
#include <stdio.h>
70.
#include <stdio.h>
else
{
for (int i = 1; i <= n; i++)
{
if (i <= n / 2)
{
for (int j = 1; j <= i; j++)
{
printf("*");
}
}
else
{
for (int k = 1; k <= n + 1 - i; k++)
{
printf("*");
}
}
printf("\n");
}
}
return 0;
}
71.
#include <stdio.h>
else
{
for (int i = 1; i <= n; i++)
{
if (i <= n / 2)
{
for (int k = 1; k <= n / 2 + 1 - i; k++)
{
printf(" ");
}
for (int j = 1; j <= i; j++)
{
printf("*");
}
}
else
{
for (int k = 1; k <= i - n / 2 - 1; k++)
{
printf(" ");
}
for (int k = 1; k <= n + 1 - i; k++)
{
printf("*");
}
}
printf("\n");
}
}
return 0;
}
72.
#include <stdio.h>
else
{
for (int i = 1; i <= n; i++)
{
if (i <= n / 2 + 1)
{
for (int k = 1; k <= n / 2 + 1 - i; k++)
{
printf(" ");
}
for (int j = 1; j <= 2 * i - 1; j++)
{
printf("*");
}
}
else
{
for (int k = 1; k <= i - n / 2 - 1; k++)
{
printf(" ");
}
for (int k = 1; k <= 2 * (n - i) + 1; k++)
{
printf("*");
}
}
printf("\n");
}
}
return 0;
}
73.
#include <stdio.h>
74.
#include <stdio.h>
else
{
for (int i = 1; i <= n; i++)
{
if (i <= n / 2 + 1)
{
for (int k = 1; k <= n / 2 + 1 - i; k++)
{
printf(" ");
}
for (int j = 1; j <= 2 * i - 1; j++)
{
printf("%d", a);
a++;
if (a > 9)
{
a = 0;
}
}
}
else
{
for (int k = 1; k <= i - n / 2 - 1; k++)
{
printf(" ");
}
for (int k = 1; k <= 2 * (n - i) + 1; k++)
{
printf("%d", a);
a++;
if (a > 9)
{
a = 0;
}
}
}
printf("\n");
}
}
return 0;
}
75.
#include <stdio.h>
86.
#include <stdio.h>
87.
#include <stdio.h>
int main() {
int n, i, j, k;
printf("\n");
}
printf("\n");
}
return 0;
}
89.
#include <stdio.h>
90.
#include <stdio.h>
92.
#include <stdio.h>
#include<math.h>
93..
#include <stdio.h>
94.
#include <stdio.h>
#include <math.h>
95.
#include <stdio.h>
96.
#include <stdio.h>
#include <math.h>
int main(int argc, char *argv[])
{
for (int i = 1000; i <=9999; i++)
{
int x = sqrt(i);
int ps = x*x;
if (ps == i)
{
printf("%d\n",i);
}
}
return 0;
}
98.
#include <stdio.h>
}
return 0;
}
99.
#include <stdio.h>
convertThreeDigits(num);
}
int main() {
int userInput;
if (userInput < 0) {
printf("Please enter a positive integer.\n");
} else {
convertnumsw(userInput);
printf("\n");
}
return 0;
}
100.
#include <stdio.h>
int main() {
int userInput, base;
// : --> : --> : - Get user input for the numsw and base
printf("Enter a positive integer: ");
scanf("%d", &userInput);
if (userInput < 0) {
printf("Please enter a positive integer.\n");
return 1;
}
if (base < 2) {
printf("Base must be greater than or equal to 2.\n");
return 1;
}
// : --> : --> : - Convert and display the numsw in the specified base
convertToBase(userInput, base);
return 0;
}
101.
#include <stdio.h>
int main() {
int marks[10];
int i;
float sum = 0;
// : --> : --> : - Validate the entered marks (assuming marks are non-
negative)
if (marks[i] < 0) {
printf("Marks cannot be negative. Please enter a valid value.\n");
--i; // : --> : --> : - Re-enter marks for the current student
} else {
sum += marks[i]; // : --> : --> : - Accumulate sum for average
calculation
}
}
return 0;
}
102.
#include <stdio.h>
printf("\nSecond Array:\n");
displayArray(array2);
case 2:
subtractArrays(array1, array2, result);
printf("\nResultant Array (Difference):\n");
break;
default:
printf("Invalid choice. Exiting.\n");
return 1;
}
return 0;
}
103.
#include <stdio.h>
int main() {
int numsws[25];
int searchnumsw, count = 0;
return 0;
}
104.
#include <stdio.h>
int main() {
int numsws[25];
int positiveCount = 0, negativeCount = 0, evenCount = 0, oddCount = 0;
// : --> : --> : - Determine the count of positive, negative, even, and odd
numsws
for (int i = 0; i < 25; ++i) {
if (numsws[i] > 0) {
positiveCount++;
} else if (numsws[i] < 0) {
negativeCount++;
}
if (numsws[i] % 2 == 0) {
evenCount++;
} else {
oddCount++;
}
}
return 0;
}
110.
#include <stdio.h>
#include <stdbool.h>
int main() {
int limit = 100;
return 0;
}
111.
#include <stdio.h>
int main() {
int originalArray[5] = {1, 2, 3, 4, 5};
int reversedArray[5];
// : --> : --> : - Copy the contents of the original array into the reversed
array in reverse order
copyReverse(originalArray, reversedArray, 5);
return 0;
}
112.
#include <stdio.h>
// : --> : --> : - Function to check if the array satisfies the given condition
int checkCondition(int arr[], int n) {
for (int i = 0; i < n / 2; ++i) {
if (arr[i] != arr[n - 1 - i]) {
return 0; // : --> : --> : - The condition is not satisfied
}
}
return 1; // : --> : --> : - The condition is satisfied
}
int main() {
int n;
if (n <= 0) {
printf("Please enter a valid numsw of elements.\n");
return 1;
}
int arr[n];
return 0;
}
113.
#include <stdio.h>
// : --> : --> : - Function to find the smallest numsw in an array using pointers
int findSmallest(int *arr, int size) {
// : --> : --> : - Assume the first element is the smallest
int smallest = *arr;
// : --> : --> : - Iterate through the array using pointers to find the
smallest element
for (int i = 1; i < size; ++i) {
if (*(arr + i) < smallest) {
smallest = *(arr + i);
}
}
return smallest;
}
int main() {
int size;
if (size <= 0) {
printf("Please enter a valid size.\n");
return 1;
}
int arr[size];
// : --> : --> : - Find the smallest numsw in the array using pointers
int smallest = findSmallest(arr, size);
return 0;
}
115.
#include <stdio.h>
// : --> : --> : - Iterate through the matrix to find the largest element
for (int i = 0; i < 5; ++i) {
for (int j = 0; j < 5; ++j) {
if (matrix[i][j] > largest) {
largest = matrix[i][j];
}
}
}
return largest;
}
int main() {
int matrix[5][5];
return 0;
}
116.
#include <stdio.h>
// : --> : --> : - Function to obtain the transpose of a 4x4 matrix
void transposeMatrix(int original[4][4], int transpose[4][4]) {
for (int i = 0; i < 4; ++i) {
for (int j = 0; j < 4; ++j) {
transpose[j][i] = original[i][j];
}
}
}
int main() {
int originalMatrix[4][4];
int transposeMatrix[4][4];
printf("\nTranspose Matrix:\n");
displayMatrix(transposeMatrix);
return 0;
}
117.
#include <stdio.h>
// : --> : --> : - Copy elements from the matrix to the flattened array
int k = 0;
for (int i = 0; i < 4; ++i) {
for (int j = 0; j < 4; ++j) {
flattened[k++] = matrix[i][j];
}
}
// : --> : --> : - Copy elements from the sorted array back to the matrix
k = 0;
for (int i = 0; i < 4; ++i) {
for (int j = 0; j < 4; ++j) {
matrix[i][j] = flattened[k++];
}
}
}
int main() {
int originalMatrix[4][4];
return 0;
}
118.
#include <stdio.h>
#include <math.h>
int main() {
int x[10], y[10];
double totalDistance = 0.0;
return 0;
}
119..
#include <stdio.h>
int main() {
int A[] = {1, 2, 4, 7, 11, 16, 22};
int N = sizeof(A) / sizeof(A[0]);
return 0;
}
120.
#include <stdio.h>
int main() {
// : --> : --> : - Constants
const int dataSize = 50;
const int range = 25;
return 0;
}
121.
#include <stdio.h>
int main() {
int matrix[10][10];
int size;
return 0;
}
122.
#include <stdio.h>
int main() {
// : --> : --> : - Constants
const int types = 5;
const int cities = 10;
const int days = 7;
// : --> : --> : - Compute total weekly sale of each type of memory chip
printf("\nTotal weekly sale of each type of memory chip:\n");
for (int l = 0; l < types; ++l) {
int total = 0;
for (int k = 0; k < cities; ++k) {
for (int m = 0; m < days; ++m) {
total += SALES[l][k][m];
}
}
printf("Type %d: %d\n", l + 1, total);
}
return 0;
}
123.
#include <stdio.h>
return length;
}
int main() {
char inputString[100];
return 0;
}
124.
#include <stdio.h>
int main() {
char inputString[100];
return 0;
}
125.
#include <stdio.h>
int main() {
char inputString[100];
return 0;
}
126.
#include <stdio.h>
// : --> : --> : - Copy characters from the source string to the destination
while (*source != '\0') {
*destination = *source;
destination++;
source++;
}
// : --> : --> : - Add null terminator to the end of the combined string
*destination = '\0';
}
int main() {
char firstString[100], secondString[50];
return 0;
}
127.
#include <stdio.h>
// : --> : --> : - Copy the first n characters from the source string to the
destination
for (int i = 0; i < n && *source != '\0'; ++i) {
*destination = *source;
destination++;
source++;
}
// : --> : --> : - Add null terminator to the end of the combined string
*destination = '\0';
}
int main() {
char firstString[100], secondString[50];
int n;
// : --> : --> : - Append the first n characters of the second string to the
first
appendNCharacters(firstString, secondString, n);
return 0;
}
128.
#include <stdio.h>
int main() {
char sourceString[100], destinationString[100];
return 0;
}
129.
#include <stdio.h>
// : --> : --> : - Function to copy the first n characters of one string into
another
void copyNCharacters(char *destination, const char *source, int n) {
// : --> : --> : - Iterate through the characters up to the first n characters
for (int i = 0; i < n && *source != '\0'; ++i) {
// : --> : --> : - Copy the character from source to destination
*destination = *source;
// : --> : --> : - Add null terminator to the end of the destination string
*destination = '\0';
}
int main() {
// : --> : --> : - Define source and destination strings
char sourceString[100];
char destinationString[100];
int n;
// : --> : --> : - Copy the first n characters of the source string into the
destination
copyNCharacters(destinationString, sourceString, n);
// : --> : --> : - Display the copied string
printf("Copied string: %s\n", destinationString);
return 0;
}
130.
#include <stdio.h>
int main() {
// : --> : --> : - Define two strings for comparison
char string1[100];
char string2[100];
return 0;
}
131.
#include <stdio.h>
int main() {
// : --> : --> : - Define two strings for comparison
char string1[100];
char string2[100];
int n;
return 0;
}
132.
#include <stdio.h>
int main() {
// : --> : --> : - Define two strings for comparison
char string1[100];
char string2[100];
return 0;
}
133.
#include <stdio.h>
int main() {
// : --> : --> : - Define a string
char inputString[100];
// : --> : --> : - Find the first occurrence of the character in the string
int result = findCharInString(inputString, targetChar);
return 0;
}
134.
#include <stdio.h>
return index;
}
int main() {
char inputString[100];
printf("Enter a string: ");
scanf("%99[^\n]", inputString);
char targetChar;
printf("Enter the character to find: ");
scanf(" %c", &targetChar);
if (result != -1) {
printf("The last occurrence of '%c' in the string is at index: %d\n",
targetChar, result);
} else {
printf("The character '%c' is not found in the string.\n", targetChar);
}
return 0;
}
135.
#include <stdio.h>
if (subString[subIndex] == '\0') {
return mainIndex - subIndex;
}
} else {
mainIndex = mainIndex - subIndex + 1;
subIndex = 0;
}
}
return -1;
}
int main() {
char mainString[100];
char subString[50];
if (result != -1) {
printf("The first occurrence of '%s' in the main string is at index: %d\n",
subString, result);
} else {
printf("The substring '%s' is not found in the main string.\n", subString);
}
return 0;
}
136.
#include <stdio.h>
int main() {
char inputString[100];
char targetChar;
setStringToChar(inputString, targetChar);
return 0;
}
137.
#include <stdio.h>
int main() {
char inputString[100];
char targetChar;
int n;
return 0;
}
138.
#include <stdio.h>
int start = 0;
int end = length - 1;
// : --> : --> : - Swap characters from start to end to reverse the string
while (start < end) {
char temp = str[start];
str[start] = str[end];
str[end] = temp;
start++;
end--;
}
}
int main() {
char inputString[100];
reverseString(inputString);
139.
#include <stdio.h>
str++;
}
return count;
}
int main() {
char inputString[100];
return 0;
}
140.
#include <stdio.h>
printf("\n");
}
int main() {
char inputString[100];
int startPosition, numCharacters;
return 0;
}
142.
#include <stdio.h>
if (str[0] == '-') {
sign = -1;
i = 1;
}
int main() {
char inputString[100];
143.
#include <stdio.h>
str[j] = '\0';
}
int main() {
char inputString[100];
replaceConsecutiveBlanks(inputString);
return 0;
}
144.
#include <stdio.h>
#include <string.h>
#define MAX_NAMES 5
#define MAX_LENGTH 50
int main() {
char names[MAX_NAMES][MAX_LENGTH];
return 0;
}
145.
#include <stdio.h>
#include <string.h>
int main() {
char *s[] = {
"To err is human...",
"But to really mess things up...",
"One needs to know C!!"
};
return 0;
}
146.
#include <stdio.h>
totalDays = daysInMonth[month];
int main() {
int month, yearsw;
printCalendar(month, yearsw);
return 0;
}
147.
#include <stdio.h>
#include <string.h>
result[j] = '\0';
int main() {
char sentence[80];
return 0;
}
148.
#include <stdio.h>
#include <string.h>
int main() {
char names[100];
return 0;
}
149.
#include <stdio.h>
#include <string.h>
int isVowel(char c) {
return (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u' ||
c == 'A' || c == 'E' || c == 'I' || c == 'O' || c == 'U');
}
int main() {
char text[200];
countSuccessiveVowels(text);
return 0;
}
150.
#include <stdio.h>
#include <string.h>
output[length] = '\0';
}
decoded[length] = '\0';
}
int main() {
char original[] = "Man's reach must always exceed his grasp.... or what is the
heaven for?";
char encoded[200], decoded[200];
encode(original, encoded);
printf("Encoded string: %s\n", encoded);
decode(encoded, decoded);
printf("Decoded string: %s\n", decoded);
return 0;
}
151.
#include <stdio.h>
#include <string.h>
struct Student {
int rollnumsw;
char name[50];
char department[50];
char course[50];
int yearswOfJoining;
};
int main() {
struct Student students[450];
printStudentsByyearsw(students, 2, 2020);
printStudentByRollnumsw(students, 2, 101);
printStudentByRollnumsw(students, 2, 103);
return 0;
}
152.
#include <stdio.h>
#include <string.h>
struct Customer {
int accountnumsw;
char name[50];
float balance;
};
printf("\n");
}
break;
}
}
if (!found) {
printf("Customer not found.\n");
}
}
int main() {
struct Customer customers[200];
printLowBalanceCustomers(customers, 2);
processTransaction(customers, 2, 101, 50.0, 0);
processTransaction(customers, 2, 102, 120.0, 1);
processTransaction(customers, 2, 103, 50.0, 0);
return 0;
}
153.
#include <stdio.h>
#include <string.h>
struct EnginePart {
char serialnumsw[4];
int yearswOfManufacture;
char material[20];
int quantityManufactured;
};
void retrieveInformation(struct EnginePart parts[], int numParts, char
startSerial[], char endSerial[]) {
printf("Information on parts with serial numsws between %s and %s:\n",
startSerial, endSerial);
int main() {
// : --> : --> : - Assume there are not more than 100 engine parts
struct EnginePart parts[100];
return 0;
}
154.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct Cricketer {
char name[50];
int age;
int testMatchesPlayed;
float averageRuns;
};
int main() {
// : --> : --> : - Assume there are 20 cricketers
struct Cricketer cricketers[20];
strcpy(cricketers[1].name, "Player2");
cricketers[1].age = 25;
cricketers[1].testMatchesPlayed = 40;
cricketers[1].averageRuns = 55.2;
return 0;
}
155.
#include <stdio.h>
#include <string.h>
struct Library {
int accessionnumsw;
char title[100];
char author[50];
float price;
int isIssued; // : --> : --> : - 0: Not issued, 1: Issued
};
int main() {
struct Library books[100]; // : --> : --> : - Assume a maximum of 100 books in
the library
int bookCount = 0;
int choice;
do {
printf("\nLibrary Menu:\n");
printf("1. Add book information\n");
printf("2. Display book information\n");
printf("3. List all books of given author\n");
printf("4. List the title of specified book\n");
printf("5. List the count of books in the library\n");
printf("6. List the books in the order of accession numsw\n");
printf("7. Exit\n");
printf("Enter your choice: ");
scanf("%d", &choice);
switch (choice) {
case 1:
addBook(books, &bookCount);
break;
case 2:
displayBookInfo(books, bookCount);
break;
case 3: {
char authorName[50];
printf("Enter author name: ");
scanf(" %[^\n]s", authorName);
listBooksByAuthor(books, bookCount, authorName);
break;
}
case 4: {
int accessionnumsw;
printf("Enter accession numsw: ");
scanf("%d", &accessionnumsw);
listTitleOfBook(books, bookCount, accessionnumsw);
break;
}
case 5:
listCountOfBooks(books, bookCount);
break;
case 6:
listBooksInOrder(books, bookCount);
break;
case 7:
printf("Exiting program.\n");
break;
default:
printf("Invalid choice. Please enter a valid option.\n");
}
return 0;
}
156.
#include <stdio.h>
struct Student {
char name[50];
int age;
};
int main() {
FILE *file;
struct Student student;
if (file == NULL) {
printf("Error opening the file.\n");
return 1;
}
// : --> : --> : - Read and display student records from the file
printf("Student Records:\n");
while (fscanf(file, "%s %d", student.name, &student.age) == 2) {
printf("Name: %s, Age: %d\n", student.name, student.age);
}
return 0;
}
157.
#include <stdio.h>
int main() {
FILE *sourceFile, *destinationFile;
char ch;
if (sourceFile == NULL) {
printf("Error opening the source file.\n");
return 1;
}
if (destinationFile == NULL) {
printf("Error opening the destination file.\n");
fclose(sourceFile);
return 1;
}
fputc(ch, destinationFile);
}
fclose(sourceFile);
fclose(destinationFile);
return 0;
}
158.
#include <stdio.h>
int main() {
FILE *file1, *file2, *mergedFile;
char line1[100], line2[100];
if (file1 == NULL) {
printf("Error opening file1.txt.\n");
return 1;
}
if (file2 == NULL) {
printf("Error opening file2.txt.\n");
fclose(file1);
return 1;
}
if (mergedFile == NULL) {
printf("Error opening merged.txt for writing.\n");
fclose(file1);
fclose(file2);
return 1;
}
if (line2[0] != '\0') {
fputs(line2, mergedFile);
}
}
fclose(file1);
fclose(file2);
fclose(mergedFile);
return 0;
}
159.
#include <stdio.h>
int main() {
FILE *sourceFile, *targetFile;
char ch;
int offset = 128;
if (targetFile == NULL) {
printf("Error opening the target file.\n");
fclose(sourceFile);
return 1;
}
fclose(sourceFile);
fclose(targetFile);
return 0;
}
160.
#include <stdio.h>
int main() {
FILE *sourceFile, *targetFile;
char ch;
if (sourceFile == NULL) {
printf("Error opening the source file.\n");
return 1;
}
if (targetFile == NULL) {
printf("Error opening the target file.\n");
fclose(sourceFile);
return 1;
}
fputc(ch, targetFile);
}
fclose(sourceFile);
fclose(targetFile);
return 0;
}