Professional Documents
Culture Documents
All C programs
All C programs
All C programs
(Take element
form the user from console).
→#include <stdio.h>
void main() {
int matrix[100][100], transpose[100][100];
int row, col, i, j;
printf("Enter the number of rows and columns of the matrix: ");
scanf("%d %d", &row, &col);
printf("Enter elements of the matrix:\n");
for(i = 0; i < row; i++) {
for(j = 0; j < col; j++) {
printf("Enter element [%d][%d]: ", i, j);
scanf("%d", &matrix[i][j]);
}
}
for(i = 0; i < row; i++) {
for(j = 0; j < col; j++) {
transpose[j][i] = matrix[i][j];
}
}
printf("Transpose of the matrix:\n");
for(i = 0; i < col; i++) {
for(j = 0; j < row; j++) {
printf("%d\t", transpose[i][j]);
}
printf("\n");
}
}
1
2. Write a program to sum up all the elements of diagonal of 4x4 Matrix.
→ #include <stdio.h>
void main() {
// Declare variables
int matrix[4][4];
int i, j, sum = 0;
void main() {
// Declare variables
int matrix1[10][10], matrix2[10][10], result[10][10];
int row1, col1, row2, col2, i, j, k;
2
for(j = 0; j < col1; j++) {
printf("Enter element [%d][%d]: ", i, j);
scanf("%d", &matrix1[i][j]);
}
}
3
4. WAP to find greatest among three numbers.
→ #include <stdio.h>
void main() {
// Declare variables
int num1, num2, num3, greatest;
4
5. WAP to count the number of vowels in the given String.
→ #include <stdio.h>
#include <string.h>
void main() {
// Declare variables
char str[100];
int i, vowels = 0;
5
6. WAP to find if given number is Armstrong.
→ #include <stdio.h>
#include <math.h>
void main() {
// Declare variables
int num, originalNum, remainder, result = 0, n = 0;
6
7. WAP to prepare the pay slip of an employee Structure. Input the
employee’s name, employee number and basic pay. Calculate the DA,
HRA, PF, PT, Gross Pay and Net Pay as follows:
If Basic < 40000, DA = 50% of Basic, HRA = 12% of Basic, PF = 12% of
Gross Pay, PT = 250.Otherwise DA = 40% of Basic, HRA = 10% of
Basic, PF = 13% of Gross, PT= 300. Gross Pay = Basic + DA + HRA
and Net Pay = Gross Pay – PF – PT.
→ #include <stdio.h>
void main() {
// Declare structure variable
struct Employee emp;
7
// Input employee details
printf("Enter employee name: ");
scanf("%s", emp.name);
8
8. WAP to enter the information of student (name, roll number, marks in
six subjects) in student structure array and Compute and print the result.
For passing, student should get at least 35 in each subject, otherwise
result is “FAIL”. If the student passes and if percentage >= 70, result is
DISTINCTION; If percentage is < 70 and >= 60, result is FIRST CLASS;
if percentage is < 60 and >=50, result is SECOND CLASS; otherwise,
result is PASS CLASS. Get the output of all students in a tabular form
with proper column headings.
→ #include <stdio.h>
struct Student {
char name[50];
int rollNumber;
int marks[6];
float percentage;
char result[20];
};
void main() {
int n;
printf("Enter the number of students: ");
scanf("%d", &n);
9
struct Student students[n];
10
9.WAP to read a string and to find the number of alphabets, digits,
spaces and special characters. (without using character functions)
→
#include <stdio.h>
void main() {
char str[100];
int alphabets = 0, digits = 0, spaces = 0, specialChars = 0;
int i = 0;
11
10. WAP to accept String from the user and print the string in reverse
without using function.
→ #include <stdio.h>
void main() {
char str[100];
int length = 0;
12
11. WAP to read a string and to find the number of alphabets, digits,
spaces and special characters. (use character functions)
→ #include <stdio.h>
#include <ctype.h>
void main() {
char str[100];
int alphabets = 0, digits = 0, spaces = 0, specialChars = 0;
int i = 0;
13
12. WAP to accept String from the user and check if it is palindrome.
→ #include <stdio.h>
#include <string.h>
void main() {
char str[100];
int i, j;
int isPalindrome = 1; // Assume string is a palindrome by default
14
13. WAP to accept a number and check whether it is a palindrome
number.
→ #include <stdio.h>
void main() {
int num, reversedNum = 0, originalNum;
15
14. Write ‘C’ program to accept a number and check whether it is an
Armstrong number.
→ #include <stdio.h>
#include <math.h>
void main() {
int num, originalNum, remainder, result = 0, n = 0;
16
15. Write a Program to find the Area and circumference of the Circle.
→ #include <stdio.h>
#define PI 3.14159 // Define the value of PI
void main() {
float radius, area, circumference;
17
16. Write a program to check if the given number is prime number. (Use
ternary operator)
→ #include <stdio.h>
void main() {
int num, i;
int isPrime;
18
17. Write a Program to convert centimetres to meter and vice versa.
(Ask User an option to choose)
→ #include <stdio.h>
void main() {
int option;
float length, convertedLength;
19
18. WAP to print follow pattern
*****
* *
* *
* *
*****
→ #include <stdio.h>
void main() {
int rows, cols, i, j;
20
19. WAP to print follow pattern
a
aba
abcba
abcdcba
abcdedcba
→ #include <stdio.h>
void main() {
int rows, i, j, k;
char ch;
21
20. Write a program to make the following pattern
$
$ $
$ $ $
$ $ $ $
→ #include <stdio.h>
void main() {
int rows, i, j;
22
21. WAP to print the following pattern
1
22
333
55555
7777777
999999999
→ #include <stdio.h>
void main() {
int rows, i, j, num;
23
22. WAP to accept number(n) and find the sum of the series
11+22+33+44……..+nn
→ #include <stdio.h>
void main() {
int n, i;
int sum = 0;
23. WAP to accept number(n) and find the sum of the series 1! + 3! + 5!
…… + n!
→ #include <stdio.h>
// Function to calculate the factorial of a number
int factorial(int n) {
if (n == 0 || n == 1) {
return 1;
} else {
return n * factorial(n - 1);
}
}
void main() {
int n, i;
int sum = 0;
24
// Calculate the sum of the series
for (i = 1; i <= n; i += 2) {
sum += factorial(i);
}
24. WAP to accept number(n) and find the sum of the series
1!+2!+3!+4!....+n!.
→ #include <stdio.h>
// Function to calculate the factorial of a number
int factorial(int n) {
if (n == 0 || n == 1) {
return 1;
} else {
return n * factorial(n - 1);
}
}
void main() {
int n, i;
int sum = 0;
25
25.WAP to print n number of Fibonacci series.
→ #include <stdio.h>
void main() {
int n, i;
int fib1 = 0, fib2 = 1, nextTerm;
printf("\n");
}
26
26. WAP to accept n number and find the sum of the series
1!/1+2!/2+3!/3…..+n!/n
→
#include <stdio.h>
// Function to calculate the factorial of a number
int factorial(int n) {
if (n == 0 || n == 1) {
return 1;
} else {
return n * factorial(n - 1);
}
}
void main() {
int n, i;
float sum = 0;
27
27. WAP to copy the content of one file into another file.
→ #include <stdio.h>
void main() {
FILE *sourceFile, *destinationFile;
char ch;
28
28. WAP to find number of vowels in the given file.
→ #include <stdio.h>
#include <ctype.h>
void main() {
FILE *file;
char ch;
int vowelCount = 0;
29
29. WAP to find the number of digit and character (Excluding special
character) in the given file
→ #include <stdio.h>
#include <ctype.h>
void main() {
FILE *file;
char ch;
int digitCount = 0, charCount = 0;
// Read characters from the file and count digits and characters
(excluding special characters)
while ((ch = fgetc(file)) != EOF) {
// Check if the character is a digit
if (isdigit(ch)) {
digitCount++;
}
// Check if the character is an alphabet
else if (isalpha(ch)) {
charCount++;
}
}
30