C Practical
C Practical
PRACTICAL FILE
ON
‘C’ PROGRAMMING
(Session 2023-24)
2. TO CHECK WHETHER A 5
NUMBER IS EVEN OR ODD
Page no.2
‘C’ PROGRAM TO CALCULATE GROSS
SALARY OF AN EMPLOYEE
#include <stdio.h>
int main(){
float basic, gross, da, hra; /* Input basic salary of employee
*/
Page no.3
OUTPUT
Enter basic salary of an employee:
19800.00
/* Run Again */
Enter basic salary of an employee:
24660.00
/*Run Again*/
Enter basic salary of an employee:
27000
int num;
scanf("%d", &num);
if(num % 2 == 0)
else
return 0;
OUTPUT
Enter an integer num: 25
25 is odd.
/* Run Again */
512 is even
‘C’ PROGRAM SWAPPING TWO NUMbers
WITHOUT THIRD VARIABLE
include <stdio.h>
#include <conio.h>
int main(int argc, char const *argv[])
{ int m,n;
printf("before swapping value:\n ");
//input integer value from user
scanf("%d",&m);
printf("enter the value of n\n");
scanf("%d",&n);
m=m+n;
n=m- n;
m=m-n;
printf("after swapping value:\n");
printf("value of m=%d\n value of n=%d\n",m,n);
return 0;
}
OUTPUT
Before Swapping value:
Enter the value of m
251
Enter the
value of n
563
After Swapping
value: Value
of m=563
Value of n=251
MULTIPLICATION TABLE UP TO 10
#include <stdio.h>
clrscr();
2 x 2 =4 3 x 2 =6 5 x 2 =10 25 x 2 =50
2 x 3 =6 3 x 3 =9 5 x 3 =15 25 x 3 =75
int main() {
int rows, i, j;
return 0;
}
OUTPUT
* * * * *
* * * *
* * *
* *
*
MULTIPLE IF STATEMENTS
#include <stdio.h>
int main() {
int a, b, c;
if (a == b && b == c) {
printf("All three numbers are equal.\n");
} else if (a > b && a > c) {
printf("The greatest number is: %d\n", a);
} else if (b > a && b > c) {
printf("The greatest number is: %d\n", b);
} else if (c > a && c > b) {
printf("The greatest number is: %d\n", c);
} else {
printf("There are multiple numbers with the same
greatest value.\n");
}
return 0;
}
Page no.10
❖ OUTPUT
Enter three numbers?
58
64
52
b=64 is greater then a and c
/* Run Again */
Enter three
numbers? 58
58
58
a=b=c
58=58=58
Page no.11
C PROGRAM TO CHECK VOWEL OR
CONSONANT USING SWITCH CASE
#include <stdio.h>
int main() {
char ch;
switch(ch) {
case 'a':
case 'e':
case 'i':
case 'o':
case 'u':
case 'A':
case 'E':
case 'I':
case 'O':
case 'U':
printf("%c is a vowel.\n", ch);
break;
default:
printf("%c is a consonant.\n", ch);
}
return 0;
}
Page no.12
❖ OUTPUT
/* Run Again */
Enter any character:
h
Character is a consonant
/* Run Again */
Enter any character:
G
Character is a consonant
Page no.13
C PROGRAM TO FIND SUM OF
TWO MATRICES OF SIZE 3X3
#include <stdio.h>
int main() {
int matrix1[3][3], matrix2[3][3], sum[3][3];
int i, j;
// Adding matrices
for(i = 0; i < 3; i++) {
for(j = 0; j < 3; j++) {
sum[i][j] = matrix1[i][j] +
Page no.14
matrix2[i][j];
}
}
return 0;
}
❖ OUTPUT
Enter elements in matrix A of size
3x3: 2 5 6
854
691
Page no.15
CALCULATOR USING IF-ELSE-IF
CONDITION
#include <stdio.h>
int main() {
char operator;
double num1, num2, result;
// Input operator
printf("Enter an operator (+, -, *, /): ");
scanf(" %c", &operator);
return 0;
}
❖ OUTPUT
Choose your Operator (+,-,*,/,): *
Enter first no.- 15
Enter Second no.- 6
Multiplication of a and b is: 90
/* Run Again */
Page no.17
PRIME NUMBER PROGRAM IN
C
#include <stdio.h>
int main() {
int num, i, flag = 0;
return 0;
Page no.20
}
Page no.20
❖ OUTPUT
Enter the number to check prime
num: 25
Number is not prime
/* Run Again */
Enter the number to check prime
num: 39
Number is not prime
/* Run Again */
Enter the number to check prime
num: 29
Number is prime
Page no.21
Page no.22