PREM
PREM
TECH(IT)
/*
*/
#include <stdio.h>
int main() {
char operator;
scanf(" %c", &operator); // Note the space before %c to handle newline character
switch (operator) {
case '+':
break;
case '-':
break;
case '*':
1|Page
NAME : PREM MUTHA IAR:15961 B.TECH(IT)
break;
case '/':
if (num2 != 0) {
} else {
break;
default:
break;
return 0;
OUTPUT :-
Enter an operator (+, -, *, /): *
2|Page
NAME : PREM MUTHA IAR:15961 B.TECH(IT)
#include <stdio.h>
int main() {
scanf("%f", &base);
scanf("%f", &height);
return 0;
OUTPUT :-
Enter the base of the triangle: 3
3|Page
NAME : PREM MUTHA IAR:15961 B.TECH(IT)
#include <stdio.h>
int main() {
scanf("%f", &principal);
scanf("%f", &rate);
scanf("%f", &years);
return 0;
OUTPUT :-
Enter the principal amount: 1000
4|Page
NAME : PREM MUTHA IAR:15961 B.TECH(IT)
#include <stdio.h>
int main() {
scanf("%f", ¢igrade);
return 0;
OUTPUT :-
Enter temperature in Celsius: 25
5|Page
NAME : PREM MUTHA IAR:15961 B.TECH(IT)
int main() {
scanf("%d", &num1);
scanf("%d", &num2);
printf("Before swapping:\n");
temp = num1;
num1 = num2;
num2 = temp;
printf("After swapping:\n");
return 0;
6|Page
NAME : PREM MUTHA IAR:15961 B.TECH(IT)
OUTPUT :-
Enter the first number: 5
Before swapping:
First number = 5
Second number = 10
After swapping:
First number = 10
Second number = 5
7|Page
NAME : PREM MUTHA IAR:15961 B.TECH(IT)
/*
#include <stdio.h>
int main() {
scanf("%f", &basic);
8|Page
NAME : PREM MUTHA IAR:15961 B.TECH(IT)
printf("-------------------------------\n");
printf("-------------------------------\n");
return 0;
OUTPUT :-
Enter the basic salary: 5000
DA (10%) : 500.00
MA : 300.00
PF (12.5%) : 625.00
-------------------------------
-------------------------------
9|Page
NAME : PREM MUTHA IAR:15961 B.TECH(IT)
/*
7. Write a program to find out the sum of the first and last digit of a given number.
*/
#include <stdio.h>
int main() {
scanf("%d", &num);
firstDigit = num;
firstDigit /= 10;
printf("The sum of the first and last digit is: %d\n", sum);
return 0;
}OUTPUT :-
10 | P a g e
NAME : PREM MUTHA IAR:15961 B.TECH(IT)
/*
8. Write a program to read marks of a student from keyboard whether the student is pass
or fail (using if else)
*/
#include <stdio.h>
int main() {
passMarks = 40; // You can adjust this value as per your criteria
scanf("%d", &marks);
} else {
return 0;
OUTPUT :-
Enter the marks obtained by the student: 75
11 | P a g e
NAME : PREM MUTHA IAR:15961 B.TECH(IT)
/*
9. Write a C program to find that the accepted number is Negative, or Positive or Zero.
*/
#include <stdio.h>
int main() {
int num;
scanf("%d", &num);
if (num > 0) {
} else {
return 0;
OUTPUT :-
Enter a number: 15
Enter a number: -8
Enter a number: 0
12 | P a g e
NAME : PREM MUTHA IAR:15961 B.TECH(IT)
/*
10. Write a program to read marks from keyboard and your program should display
equivalent grade according to following table (if else ladder)
Marks Grade
100 - 80 Distinction
79 - 60 First Class
59 - 40 Second Class
< 40 Fail
*/
#include <stdio.h>
int main() {
int marks;
scanf("%d", &marks);
printf("Grade: Distinction\n");
printf("Grade: Fail\n");
} else {
return 0;
13 | P a g e
NAME : PREM MUTHA IAR:15961 B.TECH(IT)
OUTPUT :-
Enter the marks obtained by the student: 88
Grade: Distinction
Grade: Fail
14 | P a g e
NAME : PREM MUTHA IAR:15961 B.TECH(IT)
/*
11. Write a program to read three numbers from the keyboard and find the maximum out
of these three. (Nested if else)
*/
#include <stdio.h>
int main() {
scanf("%d", &num1);
scanf("%d", &num2);
scanf("%d", &num3);
} else {
} else {
15 | P a g e
NAME : PREM MUTHA IAR:15961 B.TECH(IT)
} else {
return 0;
OUTPUT :-
Enter the first number: 15
16 | P a g e
NAME : PREM MUTHA IAR:15961 B.TECH(IT)
/*
12. Write a C program to check whether the entered character is capital, small letter, digit
or any special character.
*/
#include <stdio.h>
int main() {
char ch;
scanf("%c", &ch);
if (isupper(ch)) {
} else if (islower(ch)) {
} else if (isdigit(ch)) {
} else {
return 0;
OUTPUT :-
Enter a character: 99
Enter a character: %
17 | P a g e
NAME : PREM MUTHA IAR:15961 B.TECH(IT)
/*
13. Write a C program to read no 1 to 7 and print relatively day Sunday to Saturday.
*/
#include <stdio.h>
int main() {
int dayNumber;
scanf("%d", &dayNumber);
// Determine and print the day of the week using a switch statement
switch(dayNumber) {
case 1:
break;
case 2:
break;
case 3:
break;
case 4:
break;
case 5:
break;
case 6:
18 | P a g e
NAME : PREM MUTHA IAR:15961 B.TECH(IT)
break;
case 7:
break;
default:
break;
return 0;
OUTPUT :-
Enter a number between 1 and 7: 3
19 | P a g e
NAME : PREM MUTHA IAR:15961 B.TECH(IT)
/*
#include <stdio.h>
void main() {
int n, i;
double factorial = 1;
scanf("%d", &n);
if (n < 0) {
else {
// Calculate factorial
OUTPUT :-
Enter a positive integer: 5
Factorial of 5 = 120.00
Factorial of 5 = 120.00
20 | P a g e
NAME : PREM MUTHA IAR:15961 B.TECH(IT)
/*
#include <stdio.h>
void main() {
scanf("%d", &num);
while (num != 0) {
reversed = reversed * 10 + remainder; // Shift reversed number left by 1 digit and add remainder
OUTPUT :-
Enter an integer: 5643
21 | P a g e
NAME : PREM MUTHA IAR:15961 B.TECH(IT)
/*
#include <stdio.h>
void main() {
scanf("%d", &n);
if (i <= 1) {
} else {
OUTPUT :-
Enter the number of terms: 5
Fibonacci Series: 0 1 1 2 3
Fibonacci Series: 0 1 1 2 3 5 8 13 21
22 | P a g e
NAME : PREM MUTHA IAR:15961 B.TECH(IT)
/*
17. Write a program to check whether the given number is prime or not.
*/
#include <stdio.h>
void main() {
scanf("%d", &num);
if (num < 2) {
} else {
// Loop to check if the number has any divisors other than 1 and itself
isPrime = 0;
if (isPrime == 1) {
} else {
23 | P a g e
NAME : PREM MUTHA IAR:15961 B.TECH(IT)
/* 18. Write a C program to find the sum and average of different numbers which are
accepted by user as many as user wants
*/
#include <stdio.h>
void main() {
float average;
scanf("%d", &n);
// Loop to get each number from the user and calculate the sum
scanf("%d", &num);
average = (float)sum / n;
OUTPUT :-
How many numbers do you want to enter? 5
Enter number 1: 8
Enter number 2: 11
Enter number 3: 6
Enter number 4: 15
Enter number 5: 21
Sum = 61
Average = 12.20
24 | P a g e
NAME : PREM MUTHA IAR:15961 B.TECH(IT)
a) *
**
***
****
*****
*/
#include <stdio.h>
void main() {
int n;
scanf("%d", &n);
printf("*");
OUTPUT :-
Enter the number of rows: 5
**
***
****
*****
25 | P a g e
NAME : PREM MUTHA IAR:15961 B.TECH(IT)
b) * * * * *
****
***
**
*
#include <stdio.h>
int main()
int rows = 5;
printf(" ");
printf("* ");
printf("\n");
return 0;
OUTPUT :-
*****
****
***
**
*
26 | P a g e
NAME : PREM MUTHA IAR:15961 B.TECH(IT)
c) *
**
***
****
*****
int main()
int rows = 5;
printf(" ");
printf("* ");
printf("\n");
return 0;
OUTPUT :-
*
**
***
****
*****
27 | P a g e
NAME : PREM MUTHA IAR:15961 B.TECH(IT)
/*
#include <stdio.h>
int main() {
int n, i;
scanf("%d", &n);
float arr[n];
scanf("%f", &arr[i]);
sum += arr[i];
average = sum / n;
return 0;
OUTPUT :-
Enter the number of elements: 5
Element 1: 1
Element 2: 2
Element 3: 3
Element 4: 4
Element 5: 5
28 | P a g e
NAME : PREM MUTHA IAR:15961 B.TECH(IT)
#include <stdio.h>
int main() {
int i, j;
scanf("%d", &rows);
scanf("%d", &cols);
scanf("%d", &matrix1[i][j]);
scanf("%d", &matrix2[i][j]);
29 | P a g e
NAME : PREM MUTHA IAR:15961 B.TECH(IT)
printf("\n");
return 0;
OUTPUT :-
Enter the number of rows: 3
Element [1][1]: 1
Element [1][2]: 6
Element [2][1]: 3
Element [2][2]: 4
Element [3][1]: 5
Element [3][2]: 8
Element [1][1]: 8
Element [1][2]: 4
Element [2][1]: 7
Element [2][2]: 5
Element [3][1]: 6
Element [3][2]: 1
9 10
10 9
11 9
30 | P a g e
NAME : PREM MUTHA IAR:15961 B.TECH(IT)
#include <stdio.h>
return a + b;
int main() {
scanf("%d", &num1);
scanf("%d", &num2);
return 0;
OUTPUT :-
Enter the first number: 51
31 | P a g e
NAME : PREM MUTHA IAR:15961 B.TECH(IT)
/* 23. Write a program that defines a function to find the factorial of a number using
recursion.*/
#include <stdio.h>
int factorial(int n) {
return 1;
else
int main() {
int num;
scanf("%d", &num);
if (num < 0) {
} else {
return 0;
OUTPUT :-
Enter a positive integer: 9
32 | P a g e
NAME : PREM MUTHA IAR:15961 B.TECH(IT)
/*24. Define a structured employee that would contain employee id, department id, and
salary. Using this structure read information of 5 employees and print the same on
screen.*/
#include <stdio.h>
struct Employee {
int emp_id;
int dept_id;
float salary;
};
int main() {
scanf("%d", &employees[i].emp_id);
scanf("%d", &employees[i].dept_id);
printf("Salary: ");
scanf("%f", &employees[i].salary);
printf("\nEmployee Details:\n");
33 | P a g e
NAME : PREM MUTHA IAR:15961 B.TECH(IT)
return 0;
OUTPUT :-
Enter details for Employee 1:
Employee ID: 1
Department ID: 12
Salary: 3000
Employee ID: 2
Department ID: 13
Salary: 5000
Employee ID: 3
Department ID: 14
Salary: 8000
Employee ID: 4
Department ID: 15
Salary: 9000
Employee ID: 5
Department ID: 16
Salary: 10000
Employee Details:
34 | P a g e
NAME : PREM MUTHA IAR:15961 B.TECH(IT)
Employee 1:
Employee ID: 1
Department ID: 12
Salary: 3000.00
Employee 2:
Employee ID: 2
Department ID: 13
Salary: 5000.00
Employee 3:
Employee ID: 3
Department ID: 14
Salary: 8000.00
Employee 4:
Employee ID: 4
Department ID: 15
Salary: 9000.00
Employee 5:
Employee ID: 5
Department ID: 16
Salary: 10000.00
35 | P a g e
NAME : PREM MUTHA IAR:15961 B.TECH(IT)
/* 25. Using cricket, declare an array player with 5 elements and write a C program to read
the information about all the 5 players and print a team wise list containing names of
players with their batting average.*/
#include <stdio.h>
#include <string.h>
struct Player {
char name[50];
char team[50];
float batting_average;
};
int main() {
char team_name[50];
printf("Name: ");
printf("Team: ");
scanf("%f", &players[i].batting_average);
// Iterate over each player’s team and print players belonging to that team
int already_printed = 0;
36 | P a g e
NAME : PREM MUTHA IAR:15961 B.TECH(IT)
if (strcmp(players[i].team, players[j].team) == 0) {
already_printed = 1;
break;
// If the team has not been printed, print all players from that team
if (!already_printed) {
printf("-----------------------------\n");
if (strcmp(players[i].team, players[k].team) == 0) {
return 0;
OUTPUT :-
Enter details for Player 1:
Name: PREM
Team: GUJARAT
Batting Average: 50
Name: OM
Team: RAJASTHAN
Batting Average: 72
Name: DHONI
37 | P a g e
NAME : PREM MUTHA IAR:15961 B.TECH(IT)
Team: CHENNAI
Batting Average: 43
Name: ROHIT
Team: MUMBAI
Batting Average: 38
Name: VIRAT
Team: BANGLURU
Batting Average: 46
Team: GUJARAT
-----------------------------
PREM 50.00
Team: RAJASTHAN
-----------------------------
OM 72.00
Team: CHENNAI
-----------------------------
DHONI 43.00
Team: MUMBAI
-----------------------------
ROHIT 38.00
Team: BANGLURU
-----------------------------
VIRAT 46.00
38 | P a g e
NAME : PREM MUTHA IAR:15961 B.TECH(IT)
39 | P a g e