100 C Programs
100 C Programs
5. Check the given number is odd or even 41. Duplication removal 74. comparing 2 strings without strcmp function
6. Check whether a character is vowel or 42. Linear Search 75. copying one string to another without using
consonant strcpy
43. Binary search
7. Find largest among three numbers 76. string concatenation without using strcat
44. Split the sorted array function
8. Leap year checking
45. Matrix addition 77. Pattern replacement
9. Positive negative checking
46. Matrix multiplication 78. Finding vowels
10. Quadratic equation
47. Inverse of a 3X3 matrix 79. Sorting in alphabetical order
Programs based on Loops Programs using Functions 80. Searching sub string in a string
11. Factorial without using function
48. Factorial using function 81. Find the frequency of a character in a string
12. Table of N and square of N
49. Min and Max of array 82. Remove characters in string except
13. Calculate x to the power y alphabets
50. Bubble Sort
14. Multiplication table 83. Reverse the given string
51. Convert: Bin to dec; dec to bin
15. Sum of natural numbers Programs using Pointers
52. Bin to oct; oct to bin
16. Fibonacci starting from any two numbers 84. Area of circle using pointers
53. Dec to Hex
17. Upper case to Lower case 85. function pointers
54. Oct to dec; dec to oct
18. Lower to upper 86. duplication removal using pointers
55. Stack operation using function
19. Pascal triangle 87. Sorting integer array using pointers
56. Factorial using recursive function
20. LCM & GCD 88. Sum of array using pointers
57. Fibonacci using recursive function
21. Prime numbers between two ranges 89. Count number of words using pointers
58. Sum of N numbers using recursion
22. Factors of a number 90. Length of a string using pointers
59. Reverse the sentence using recursion
23. Prime Factors 91. Reverse the String Using Pointers
60. Power using recursion
24. Bin to dec and oct Programs using Files
61. Towers of Hanoi
25. Count the number of digit in an integer 92. Write a sentence into a file
62. Exponent using recursion
26. Reverse the digits of given number 93. Employee file
63. GCD using recursion
27. Number palindrome 94. Employee-struct
Programs using Structures
28. Digit summation 95. Copying the content of one file into another
64. Student structure
29. Amstrong checking 96. Convert the file contents in Upper-case &
65. Players structure
Write
30. Make simple calculator in C
66. Add two polynomials using structures in
Contents in a output file
31. To find SIN(X) using SINE Series function
97. Compare two text/data files in C
32. Exponent series 67. Add two distances using structures
Programming
33. Floyds Triangle 68. Add two complex numbers
98. Reading & writing in files
Programs based on Arrays 69. Calculate difference between two time
99. ODD-EVEN splitting
period
34. Fibonacci using array 100.Copy from one text file into another
Programs using Strings
35. Largest among N numbers in an array
SOLUTIONS
1.
#include <stdio.h>
int main() {
float length, width, area;
return 0;
}
2.
#include <stdio.h>
int main() {
char ch;
return 0;
}
3.
#include <stdio.h>
int main() {
float celsius, fahrenheit;
return 0;
}
4.
#include <stdio.h>
int main() {
int a, b, temp;
temp = a;
a = b;
b = temp;
printf("After swapping, a = %d and b = %d\n", a, b);
return 0;
}
5.
#include <stdio.h>
int main() {
int num;
if (num % 2 == 0)
printf("%d is even\n", num);
else
printf("%d is odd\n", num);
return 0;
}
6.
#include <stdio.h>
int main() {
char ch;
return 0;
}
7.
#include <stdio.h>
int main() {
int num1, num2, num3;
return 0;
}
8.
#include <stdio.h>
int main() {
int year;
printf("Enter a year: ");
scanf("%d", &year);
return 0;
}
9.
#include <stdio.h>
int main() {
int num;
if (num > 0)
printf("%d is positive\n", num);
else if (num < 0)
printf("%d is negative\n", num);
else
printf("You entered zero\n");
return 0;
}
10.
#include <stdio.h>
#include <math.h>
int main() {
float a, b, c, discriminant, root1, root2, realPart, imaginaryPart;
discriminant = b * b - 4 * a * c;
if (discriminant > 0) {
root1 = (-b + sqrt(discriminant)) / (2 * a);
root2 = (-b - sqrt(discriminant)) / (2 * a);
printf("Roots are real and different: %.2f and %.2f\n", root1, root2);
}
else if (discriminant == 0) {
root1 = root2 = -b / (2 * a);
printf("Roots are real and same: %.2f and %.2f\n", root1, root2);
}
else {
realPart = -b / (2 * a);
imaginaryPart = sqrt(-discriminant) / (2 * a);
printf("Roots are complex and different: %.2f+%.2fi and %.2f-%.2fi\n", realPart, imaginaryPart, realPart,
imaginaryPart);
}
return 0;
}
11.
#include <stdio.h>
int main() {
int num, i;
unsigned long long fact = 1;
return 0;
}
12.
#include <stdio.h>
int main() {
int num, i;
return 0;
}
13.
#include <stdio.h>
#include <math.h>
int main() {
double x, y, result;
return 0;
}
14.
#include <stdio.h>
int main() {
int num, i;
return 0;
}
15.
#include <stdio.h>
int main() {
int num, sum = 0, i;
return 0;
}
16.
#include <stdio.h>
int main() {
int n, firstNum, secondNum, nextTerm, i;
printf("\n");
return 0;
}
17.
#include <stdio.h>
int main() {
char uppercase, lowercase;
return 0;
}
18.
#include <stdio.h>
int main() {
char lowercase, uppercase;
return 0;
}
19.
#include <stdio.h>
int main() {
int rows, coef = 1, space, i, j;
printf("%4d", coef);
}
printf("\n");
}
return 0;
}
20.
#include <stdio.h>
int main() {
int num1, num2;
return 0;
}
21.
#include <stdio.h>
#include <stdbool.h>
int main() {
int start, end;
printf("Enter the range (start end): ");
scanf("%d %d", &start, &end);
printf("Prime numbers between %d and %d are:\n", start, end);
for (int i = start; i <= end; ++i) {
if (isPrime(i)) {
printf("%d ", i);
}
}
printf("\n");
return 0;
}
22.
#include <stdio.h>
int main() {
int num;
printf("Enter a number: ");
scanf("%d", &num);
printf("Factors of %d are:\n", num);
for (int i = 1; i <= num; ++i) {
if (num % i == 0) {
printf("%d ", i);
}
}
printf("\n");
return 0;
}
23.
#include <stdio.h>
int main() {
int num;
printf("Enter a number: ");
scanf("%d", &num);
primeFactors(num);
return 0;
}
24.
#include <stdio.h>
#include <math.h>
int main() {
int bin;
printf("Enter a binary number: ");
scanf("%d", &bin);
printf("Decimal equivalent: %d\n", binToDec(bin));
printf("Octal equivalent: %o\n", binToDec(bin));
return 0;
}
25.
#include <stdio.h>
int main() {
int num, count = 0;
printf("Enter an integer: ");
scanf("%d", &num);
while (num != 0) {
num /= 10;
++count;
}
printf("Number of digits: %d\n", count);
return 0;
}
26.
#include <stdio.h>
int main() {
int num, reversedNum = 0, remainder;
printf("Enter a number: ");
scanf("%d", &num);
while (num != 0) {
remainder = num % 10;
reversedNum = reversedNum * 10 + remainder;
num /= 10;
}
printf("Reversed number: %d\n", reversedNum);
return 0;
}
27.
#include <stdio.h>
int main() {
int num, reversedNum = 0, originalNum, remainder;
printf("Enter a number: ");
scanf("%d", &num);
originalNum = num;
while (num != 0) {
remainder = num % 10;
reversedNum = reversedNum * 10 + remainder;
num /= 10;
}
if (originalNum == reversedNum) {
printf("%d is a palindrome\n", originalNum);
} else {
printf("%d is not a palindrome\n", originalNum);
}
return 0;
}
28.
#include <stdio.h>
int main() {
int num, sum = 0, digit;
printf("Enter a number: ");
scanf("%d", &num);
while (num != 0) {
digit = num % 10;
sum += digit;
num /= 10;
}
printf("Sum of digits: %d\n", sum);
return 0;
}
29.
#include <stdio.h>
#include <math.h>
int main() {
int num, originalNum, remainder, n = 0, result = 0;
printf("Enter a number: ");
scanf("%d", &num);
originalNum = num;
while (originalNum != 0) {
originalNum /= 10;
++n;
}
originalNum = num;
while (originalNum != 0) {
remainder = originalNum % 10;
result += pow(remainder, n);
originalNum /= 10;
}
if (result == num) {
printf("%d is an Armstrong number\n", num);
} else {
printf("%d is not an Armstrong number\n", num);
}
return 0;
}
30.
#include <stdio.h>
int main() {
char operator;
double num1, num2;
switch (operator) {
case '+':
printf("%.2lf + %.2lf = %.2lf\n", num1, num2, num1 + num2);
break;
case '-':
printf("%.2lf - %.2lf = %.2lf\n", num1, num2, num1 - num2);
break;
case '*':
printf("%.2lf * %.2lf = %.2lf\n", num1, num2, num1 * num2);
break;
case '/':
if (num2 != 0)
printf("%.2lf / %.2lf = %.2lf\n", num1, num2, num1 / num2);
else
printf("Error! Division by zero.\n");
break;
default:
printf("Invalid operator!\n");
}
return 0;
}
31.
#include <stdio.h>
#include <math.h>
double factorial(int n) {
if (n == 0) return 1;
return n * factorial(n - 1);
}
int main() {
double x;
int n;
printf("Enter the value of x in radians: ");
scanf("%lf", &x);
printf("Enter the number of terms in the series: ");
scanf("%d", &n);
printf("sin(%.2lf) = %.6lf\n", x, sineSeries(x, n));
return 0;
}
32.
#include <stdio.h>
#include <math.h>
int main() {
double x;
int n;
printf("Enter the value of x: ");
scanf("%lf", &x);
printf("Enter the number of terms in the series: ");
scanf("%d", &n);
printf("e^%.2lf = %.6lf\n", x, exponentSeries(x, n));
return 0;
}
33.
#include <stdio.h>
int main() {
int rows, num = 1;
printf("Enter the number of rows: ");
scanf("%d", &rows);
printf("Floyd's Triangle:\n");
for (int i = 1; i <= rows; ++i) {
for (int j = 1; j <= i; ++j) {
printf("%d ", num);
++num;
}
printf("\n");
}
return 0;
}
34.
#include <stdio.h>
int main() {
int n;
printf("Enter the number of terms: ");
scanf("%d", &n);
int fibonacci[n];
fibonacci[0] = 0;
fibonacci[1] = 1;
printf("Fibonacci series:\n%d %d ", fibonacci[0], fibonacci[1]);
for (int i = 2; i < n; ++i) {
fibonacci[i] = fibonacci[i - 1] + fibonacci[i - 2];
printf("%d ", fibonacci[i]);
}
printf("\n");
return 0;
}
35.
#include <stdio.h>
int main() {
int n;
printf("Enter the number of elements: ");
scanf("%d", &n);
int arr[n];
printf("Enter %d elements:\n", n);
for (int i = 0; i < n; ++i) {
scanf("%d", &arr[i]);
}
int largest = arr[0];
for (int i = 1; i < n; ++i) {
if (arr[i] > largest) {
largest = arr[i];
}
}
printf("Largest element: %d\n", largest);
return 0;
}
36.
#include <stdio.h>
int main() {
int n;
printf("Enter the number of elements: ");
scanf("%d", &n);
int arr[n];
printf("Enter %d elements:\n", n);
for (int i = 0; i < n; ++i) {
scanf("%d", &arr[i]);
}
int smallest = arr[0];
for (int i = 1; i < n; ++i) {
if (arr[i] < smallest) {
smallest = arr[i];
}
}
printf("Smallest element: %d\n", smallest);
return 0;
}
37.
#include <stdio.h>
int main() {
int n;
printf("Enter the number of elements: ");
scanf("%d", &n);
int arr[n];
printf("Enter %d elements:\n", n);
for (int i = 0; i < n; ++i) {
scanf("%d", &arr[i]);
}
printf("Original array:\n");
for (int i = 0; i < n; ++i) {
printf("%d ", arr[i]);
}
printf("\nReversed array:\n");
for (int i = n - 1; i >= 0; --i) {
printf("%d ", arr[i]);
}
printf("\n");
return 0;
}
38.
#include <stdio.h>
int main() {
int n, pos, element;
printf("Enter the number of elements: ");
scanf("%d", &n);
int arr[n + 1];
printf("Enter %d elements:\n", n);
for (int i = 0; i < n; ++i) {
scanf("%d", &arr[i]);
}
printf("Enter the position where you want to insert: ");
scanf("%d", &pos);
printf("Enter the element to insert: ");
scanf("%d", &element);
for (int i = n; i >= pos; --i) {
arr[i] = arr[i - 1];
}
arr[pos - 1] = element;
printf("Array after insertion:\n");
for (int i = 0; i < n + 1; ++i) {
printf("%d ", arr[i]);
}
printf("\n");
return 0;
}
39.
#include <stdio.h>
int main() {
int n, pos;
printf("Enter the number of elements: ");
scanf("%d", &n);
int arr[n];
printf("Enter %d elements:\n", n);
for (int i = 0; i < n; ++i) {
scanf("%d", &arr[i]);
}
printf("Enter the position of element to delete: ");
scanf("%d", &pos);
if (pos < 0 || pos >= n) {
printf("Invalid position!\n");
} else {
for (int i = pos; i < n - 1; ++i) {
arr[i] = arr[i + 1];
}
printf("Array after deletion:\n");
for (int i = 0; i < n - 1; ++i) {
printf("%d ", arr[i]);
}
printf("\n");
}
return 0;
}
40.
#include <stdio.h>
#define ROWS 3
#define COLS 3
int main() {
int matrix[ROWS][COLS], transpose[COLS][ROWS];
printf("Enter elements of the matrix:\n");
for (int i = 0; i < ROWS; ++i) {
for (int j = 0; j < COLS; ++j) {
scanf("%d", &matrix[i][j]);
}
}
printf("Original matrix:\n");
for (int i = 0; i < ROWS; ++i) {
for (int j = 0; j < COLS; ++j) {
printf("%d ", matrix[i][j]);
transpose[j][i] = matrix[i][j];
}
printf("\n");
}
printf("Transpose of the matrix:\n");
for (int i = 0; i < COLS; ++i) {
for (int j = 0; j < ROWS; ++j) {
printf("%d ", transpose[i][j]);
}
printf("\n");
}
return 0;
}
41.
#include <stdio.h>
int main() {
int arr[] = {1, 2, 3, 4, 2, 3, 5};
int n = sizeof(arr) / sizeof(arr[0]);
removeDuplicates(arr, n);
return 0;
}
42.
#include <stdio.h>
int main() {
int arr[] = {10, 20, 30, 40, 50};
int n = sizeof(arr) / sizeof(arr[0]);
int key = 30;
int index = linearSearch(arr, n, key);
if (index != -1)
printf("Element %d found at index %d\n", key, index);
else
printf("Element %d not found\n", key);
return 0;
}
43.
#include <stdio.h>
int main() {
int arr[] = {10, 20, 30, 40, 50};
int n = sizeof(arr) / sizeof(arr[0]);
int key = 30;
int index = binarySearch(arr, 0, n - 1, key);
if (index != -1)
printf("Element %d found at index %d\n", key, index);
else
printf("Element %d not found\n", key);
return 0;
}
44.
#include <stdio.h>
int main() {
int arr[] = {10, 20, 30, 40, 50};
int n = sizeof(arr) / sizeof(arr[0]);
int key = 25;
splitArray(arr, n, key);
return 0;
}
45.
#include <stdio.h>
#define ROWS 3
#define COLS 3
int main() {
int mat1[ROWS][COLS] = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};
int mat2[ROWS][COLS] = {{9, 8, 7}, {6, 5, 4}, {3, 2, 1}};
int result[ROWS][COLS];
matrixAddition(mat1, mat2, result);
printf("Matrix 1:\n");
displayMatrix(mat1);
printf("Matrix 2:\n");
displayMatrix(mat2);
printf("Resultant Matrix:\n");
displayMatrix(result);
return 0;
}
46.
#include <stdio.h>
#define ROWS1 3
#define COLS1 3
#define ROWS2 3
#define COLS2 3
int main() {
int mat1[ROWS1][COLS1] = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};
int mat2[ROWS2][COLS2] = {{9, 8, 7}, {6, 5, 4}, {3, 2, 1}};
int result[ROWS1][COLS2];
matrixMultiplication(mat1, mat2, result);
printf("Matrix 1:\n");
displayMatrix(mat1);
printf("Matrix 2:\n");
displayMatrix(mat2);
printf("Resultant Matrix:\n");
displayMatrix(result);
return 0;
}
47.
#include <stdio.h>
int main() {
int mat[3][3] = {{4, 3, 2}, {2, 1, 3}, {3, 2, 1}};
int adj[3][3], det;
det = determinant(mat, 3);
if (det == 0)
printf("Singular matrix, can't find its inverse\n");
else {
adjoint(mat, adj);
printf("Inverse of the matrix:\n");
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
printf("%d ", adj[i][j] / det);
}
printf("\n");
}
}
return 0;
}
48.
#include <stdio.h>
int main() {
int n;
printf("Enter a number: ");
scanf("%d", &n);
printf("Factorial of %d = %llu\n", n, factorial(n));
return 0;
}
49.
#include <stdio.h>
int main() {
int arr[] = {10, 20, 5, 15, 30};
int n = sizeof(arr) / sizeof(arr[0]);
minMaxArray(arr, n);
return 0;
}
50.
#include <stdio.h>
int main() {
int arr[] = {64, 34, 25, 12, 22, 11, 90};
int n = sizeof(arr) / sizeof(arr[0]);
printf("Original array: ");
displayArray(arr, n);
bubbleSort(arr, n);
printf("Sorted array: ");
displayArray(arr, n);
return 0;
}
51.
#include <stdio.h>
int main() {
long long binaryNumber;
int decimalNumber;
return 0;
}
52.
#include <stdio.h>
int main() {
long long binaryNumber;
int octalNumber;
return 0;
}
53.
#include <stdio.h>
int main() {
int decimalNumber;
printf("Enter a decimal number: ");
scanf("%d", &decimalNumber);
decimalToHexadecimal(decimalNumber);
return 0;
}
54.
#include <stdio.h>
int main() {
int octalNumber, decimalNumber;
printf("Enter an octal number: ");
scanf("%d", &octalNumber);
printf("Decimal equivalent: %d\n", octalToDecimal(octalNumber));
return 0;
}
55.
#include <stdio.h>
#include <stdlib.h>
#define MAX 5
int stack[MAX];
int top = -1;
int isFull() {
return top == MAX - 1;
}
int isEmpty() {
return top == -1;
}
int pop() {
if (isEmpty()) {
printf("Stack Underflow\n");
return -1;
}
return stack[top--];
}
void display() {
if (isEmpty()) {
printf("Stack is empty\n");
return;
}
printf("Stack elements: ");
for (int i = top; i >= 0; i--)
printf("%d ", stack[i]);
printf("\n");
}
int main() {
push(10);
push(20);
push(30);
display();
printf("%d popped from stack\n", pop());
display();
return 0;
}
56.
#include <stdio.h>
int main() {
int n;
printf("Enter a number: ");
scanf("%d", &n);
printf("Factorial of %d = %llu\n", n, factorial(n));
return 0;
}
57.
#include <stdio.h>
int fibonacci(int n) {
if (n <= 1)
return n;
else
return fibonacci(n - 1) + fibonacci(n - 2);
}
int main() {
int n;
printf("Enter the number of terms: ");
scanf("%d", &n);
printf("Fibonacci Series: ");
for (int i = 0; i < n; ++i) {
printf("%d ", fibonacci(i));
}
printf("\n");
return 0;
}
58.
#include <stdio.h>
int sum(int n) {
if (n == 0)
return 0;
else
return n + sum(n - 1);
}
int main() {
int n;
printf("Enter a positive integer: ");
scanf("%d", &n);
printf("Sum of first %d natural numbers = %d\n", n, sum(n));
return 0;
}
59.
#include <stdio.h>
#include <string.h>
void reverseSentence() {
char c;
scanf("%c", &c);
if (c != '\n') {
reverseSentence();
printf("%c", c);
}
}
int main() {
printf("Enter a sentence: ");
reverseSentence();
return 0;
}
60.
#include <stdio.h>
int main() {
double base;
int exponent;
printf("Enter base and exponent: ");
scanf("%lf %d", &base, &exponent);
printf("%.2lf ^ %d = %.2lf\n", base, exponent, power(base, exponent));
return 0;
}
61.
#include <stdio.h>
int main() {
int n;
printf("Enter the number of disks: ");
scanf("%d", &n);
towersOfHanoi(n, 'A', 'C', 'B');
return 0;
}
62.
#include <stdio.h>
int main() {
int base, exponent;
printf("Enter base and exponent: ");
scanf("%d %d", &base, &exponent);
printf("%d ^ %d = %d\n", base, exponent, power(base, exponent));
return 0;
}
63.
#include <stdio.h>
int main() {
int a, b;
printf("Enter two positive integers: ");
scanf("%d %d", &a, &b);
printf("GCD of %d and %d is %d\n", a, b, gcd(a, b));
return 0;
}
64.
#include <stdio.h>
struct Student {
int rollNumber;
char name[50];
float marks;
};
int main() {
struct Student s;
printf("Enter Roll Number: ");
scanf("%d", &s.rollNumber);
printf("Enter Name: ");
scanf("%s", s.name);
printf("Enter Marks: ");
scanf("%f", &s.marks);
printf("\nStudent Details:\n");
printf("Roll Number: %d\n", s.rollNumber);
printf("Name: %s\n", s.name);
printf("Marks: %.2f\n", s.marks);
return 0;
}
65.
#include <stdio.h>
struct Player {
int playerID;
char name[50];
int score;
};
int main() {
struct Player players[5];
printf("Enter details of 5 players:\n");
for (int i = 0; i < 5; ++i) {
printf("\nEnter Player %d details:\n", i + 1);
printf("ID: ");
scanf("%d", &players[i].playerID);
printf("Name: ");
scanf("%s", players[i].name);
printf("Score: ");
scanf("%d", &players[i].score);
}
printf("\nPlayers details:\n");
for (int i = 0; i < 5; ++i) {
printf("\nPlayer %d details:\n", i + 1);
printf("ID: %d\n", players[i].playerID);
printf("Name: %s\n", players[i].name);
printf("Score: %d\n", players[i].score);
}
return 0;
}
66.
#include <stdio.h>
typedef struct {
int coef;
int exp;
} PolynomialTerm;
void addPolynomials(PolynomialTerm poly1[], int n1, PolynomialTerm poly2[], int n2, PolynomialTerm
result[]) {
int i = 0, j = 0, k = 0;
while (i < n1 && j < n2) {
if (poly1[i].exp > poly2[j].exp)
result[k++] = poly1[i++];
else if (poly1[i].exp < poly2[j].exp)
result[k++] = poly2[j++];
else {
result[k].exp = poly1[i].exp;
result[k++].coef = poly1[i++].coef + poly2[j++].coef;
}
}
while (i < n1)
result[k++] = poly1[i++];
while (j < n2)
result[k++] = poly2[j++];
}
int main() {
PolynomialTerm poly1[MAX_TERMS] = {{5, 2}, {4, 1}, {2, 0}};
PolynomialTerm poly2[MAX_TERMS] = {{-3, 2}, {2, 1}, {1, 0}};
PolynomialTerm result[MAX_TERMS];
int n1 = 3, n2 = 3;
printf("Polynomial 1: ");
displayPolynomial(poly1, n1);
printf("Polynomial 2: ");
displayPolynomial(poly2, n2);
addPolynomials(poly1, n1, poly2, n2, result);
printf("Sum: ");
displayPolynomial(result, n1 + n2);
return 0;
}
67.
#include <stdio.h>
typedef struct {
int feet;
float inch;
} Distance;
int main() {
Distance d1 = {5, 8.5};
Distance d2 = {3, 10.2};
Distance result;
addDistances(d1, d2, &result);
printf("Sum: %d feet %.1f inches\n", result.feet, result.inch);
return 0;
}
68.
#include <stdio.h>
typedef struct {
float real;
float imaginary;
} Complex;
typedef struct {
int hours;
int minutes;
int seconds;
} Time;
int main() {
Time start, end, diff;
printf("Enter start time (hh:mm:ss): ");
scanf("%d:%d:%d", &start.hours, &start.minutes, &start.seconds);
printf("Enter end time (hh:mm:ss): ");
scanf("%d:%d:%d", &end.hours, &end.minutes, &end.seconds);
difference(start, end, &diff);
printf("Difference: %d:%d:%d\n", diff.hours, diff.minutes, diff.seconds);
return 0;
}
70.
#include <stdio.h>
int main() {
char c;
int blanks = 0, tabs = 0, newlines = 0;
printf("Enter some text and press Ctrl+D (Unix/Linux) or Ctrl+Z (Windows) to end:\n");
while ((c = getchar()) != EOF) {
if (c == ' ')
blanks++;
else if (c == '\t')
tabs++;
else if (c == '\n')
newlines++;
}
printf("Blanks: %d\n", blanks);
printf("Tabs: %d\n", tabs);
printf("Newlines: %d\n", newlines);
return 0;
}
71.
#include <stdio.h>
#include <string.h>
#include <ctype.h>
int main() {
char str[100];
printf("Enter a string: ");
fgets(str, sizeof(str), stdin);
str[strcspn(str, "\n")] = '\0'; // Removing the newline character
if (isPalindrome(str))
printf("%s is a palindrome.\n", str);
else
printf("%s is not a palindrome.\n", str);
return 0;
}
72.
#include <stdio.h>
int main() {
char name[100];
printf("Enter a name: ");
fgets(name, sizeof(name), stdin);
convertToASCII(name);
return 0;
}
73.
#include <stdio.h>
int main() {
char str[100];
printf("Enter a string: ");
fgets(str, sizeof(str), stdin);
printf("Length of the string: %d\n", stringLength(str));
return 0;
}
74.
#include <stdio.h>
int main() {
char str1[100], str2[100];
printf("Enter first string: ");
fgets(str1, sizeof(str1), stdin);
printf("Enter second string: ");
fgets(str2, sizeof(str2), stdin);
if (compareStrings(str1, str2) == 0)
printf("Strings are equal.\n");
else
printf("Strings are not equal.\n");
return 0;
}
75.
#include <stdio.h>
int main() {
char source[100], destination[100];
printf("Enter a string: ");
fgets(source, sizeof(source), stdin);
stringCopy(source, destination);
printf("Copied string: %s\n", destination);
return 0;
}
76.
#include <stdio.h>
int main() {
char str1[100], str2[100];
printf("Enter first string: ");
fgets(str1, sizeof(str1), stdin);
printf("Enter second string: ");
fgets(str2, sizeof(str2), stdin);
stringConcatenate(str1, str2);
printf("Concatenated string: %s\n", str1);
return 0;
}
77.
#include <stdio.h>
#include <string.h>
int main() {
char str[100], pattern[100], replacement[100];
printf("Enter a string: ");
fgets(str, sizeof(str), stdin);
printf("Enter the pattern to replace: ");
fgets(pattern, sizeof(pattern), stdin);
printf("Enter the replacement string: ");
fgets(replacement, sizeof(replacement), stdin);
str[strcspn(str, "\n")] = '\0'; // Removing the newline character
pattern[strcspn(pattern, "\n")] = '\0'; // Removing the newline character
replacement[strcspn(replacement, "\n")] = '\0'; // Removing the newline character
replacePattern(str, pattern, replacement);
printf("String after replacement: %s\n", str);
return 0;
}
78.
#include <stdio.h>
#include <ctype.h>
int main() {
int n;
printf("Enter the number of strings: ");
scanf("%d", &n);
char strings[n][100];
printf("Enter %d strings:\n", n);
for (int i = 0; i < n; ++i) {
scanf("%s", strings[i]);
}
sortStrings(strings, n);
printf("Strings in alphabetical order:\n");
for (int i = 0; i < n; ++i) {
printf("%s\n", strings[i]);
}
return 0;
}
80.
#include <stdio.h>
#include <string.h>
int main() {
char str[100], sub[100];
printf("Enter a string: ");
fgets(str, sizeof(str), stdin);
printf("Enter a substring to search: ");
fgets(sub, sizeof(sub), stdin);
str[strcspn(str, "\n")] = '\0'; // Removing the newline character
sub[strcspn(sub, "\n")] = '\0'; // Removing the newline character
int index = findSubstring(str, sub);
if (index != -1)
printf("Substring found at index %d\n", index);
else
printf("Substring not found\n");
return 0;
}
81.
#include <stdio.h>
int main() {
char str[100], ch;
printf("Enter a string: ");
fgets(str, sizeof(str), stdin);
printf("Enter the character to find its frequency: ");
scanf("%c", &ch);
printf("Frequency of '%c' in the string: %d\n", ch, countFrequency(str, ch));
return 0;
}
82.
#include <stdio.h>
#include <ctype.h>
int main() {
char str[100];
printf("Enter a string: ");
fgets(str, sizeof(str), stdin);
removeNonAlphabetic(str);
printf("String after removing non-alphabetic characters: %s\n", str);
return 0;
}
83.
#include <stdio.h>
#include <string.h>
int main() {
char str[100];
printf("Enter a string: ");
fgets(str, sizeof(str), stdin);
str[strcspn(str, "\n")] = '\0'; // Removing the newline character
reverseString(str);
printf("Reversed string: %s\n", str);
return 0;
}
84.
#include <stdio.h>
#define PI 3.14159
int main() {
float radius, area;
printf("Enter the radius of the circle: ");
scanf("%f", &radius);
calculateArea(radius, &area);
printf("Area of the circle with radius %.2f = %.2f\n", radius, area);
return 0;
}
85.
#include <stdio.h>
int add(int a, int b) {
return a + b;
}
int main() {
int (*funcPtr)(int, int);
int result;
funcPtr = &add;
result = funcPtr(10, 5);
printf("Result of addition: %d\n", result);
funcPtr = &subtract;
result = funcPtr(10, 5);
printf("Result of subtraction: %d\n", result);
return 0;
}
86.
#include <stdio.h>
int main() {
char str[100];
printf("Enter a string: ");
fgets(str, sizeof(str), stdin);
removeDuplicates(str);
printf("String after removing duplicates: %s\n", str);
return 0;
}
87.
#include <stdio.h>
int main() {
int arr[] = {5, 2, 9, 1, 7};
int size = sizeof(arr) / sizeof(arr[0]);
sortArray(arr, size);
return 0;
}
88.
#include <stdio.h>
int main() {
int arr[] = {5, 2, 9, 1, 7};
int size = sizeof(arr) / sizeof(arr[0]);
int sum = sumArray(arr, size);
printf("Sum of array elements: %d\n", sum);
return 0;
}
89.
#include <stdio.h>
#include <stdbool.h>
int main() {
char str[100];
printf("Enter a string: ");
fgets(str, sizeof(str), stdin);
printf("Number of words in the string: %d\n", countWords(str));
return 0;
}
90.
#include <stdio.h>
int main() {
char str[100];
printf("Enter a string: ");
fgets(str, sizeof(str), stdin);
printf("Length of the string: %d\n", stringLength(str));
return 0;
}
91.
#include <stdio.h>
#include <string.h>
int main() {
char str[100];
printf("Enter a string: ");
fgets(str, sizeof(str), stdin);
str[strcspn(str, "\n")] = '\0'; // Removing the newline character
reverseString(str);
printf("Reversed string: %s\n", str);
return 0;
}
92.
#include <stdio.h>
int main() {
FILE *file;
char sentence[100];
if (file == NULL) {
printf("File cannot be opened.\n");
return 1;
}
// Close file
fclose(file);
return 0;
}
93.
#include <stdio.h>
struct Employee {
int empID;
char name[50];
float salary;
};
int main() {
FILE *file;
struct Employee emp;
if (file == NULL) {
printf("File cannot be opened.\n");
return 1;
}
// Get employee details from user
printf("Enter employee ID: ");
scanf("%d", &emp.empID);
printf("Enter employee name: ");
scanf("%s", emp.name);
printf("Enter employee salary: ");
scanf("%f", &emp.salary);
// Close file
fclose(file);
return 0;
}
94.
#include <stdio.h>
struct Employee {
int empID;
char name[50];
float salary;
};
int main() {
struct Employee emp;
// Get employee details from user
printf("Enter employee ID: ");
scanf("%d", &emp.empID);
printf("Enter employee name: ");
scanf("%s", emp.name);
printf("Enter employee salary: ");
scanf("%f", &emp.salary);
return 0;
}
95.
#include <stdio.h>
int main() {
FILE *sourceFile, *destinationFile;
char ch;
if (sourceFile == NULL) {
printf("Source file cannot be opened.\n");
return 1;
}
if (destinationFile == NULL) {
printf("Destination file cannot be opened.\n");
fclose(sourceFile);
return 1;
}
// Close files
fclose(sourceFile);
fclose(destinationFile);
return 0;
}
96.
#include <stdio.h>
#include <ctype.h>
int main() {
FILE *inputFile, *outputFile;
char ch;
if (outputFile == NULL) {
printf("Output file cannot be opened.\n");
fclose(inputFile);
return 1;
}
// Close files
fclose(inputFile);
fclose(outputFile);
return 0;
}
97.
#include <stdio.h>
#include <stdbool.h>
int main() {
FILE *file1, *file2;
// Compare files
if (compareFiles(file1, file2)) {
printf("Files are identical.\n");
} else {
printf("Files are different.\n");
}
// Close files
fclose(file1);
fclose(file2);
return 0;
}
98.
#include <stdio.h>
int main() {
FILE *file;
char data[100];
if (file == NULL) {
printf("File cannot be opened.\n");
return 1;
}
// Close file
fclose(file);
// Open file in read mode
file = fopen("file.txt", "r");
if (file == NULL) {
printf("File cannot be opened.\n");
return 1;
}
// Close file
fclose(file);
return 0;
}
99.
#include <stdio.h>
int main() {
int arr[] = {5, 2, 9, 1, 7, 4, 6};
int size = sizeof(arr) / sizeof(arr[0]);
splitOddEven(arr, size);
return 0;
}
100.
#include <stdio.h>
int main() {
FILE *sourceFile, *destinationFile;
char ch;
if (sourceFile == NULL) {
printf("Source file cannot be opened.\n");
return 1;
}
if (destinationFile == NULL) {
printf("Destination file cannot be opened.\n");
fclose(sourceFile);
return 1;
}
// Close files
fclose(sourceFile);
fclose(destinationFile);
return 0;
}