C programming practical
1. Write a C program to take the input from the user
of 5 numbers and calculate the avg of these 5 no’s.
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c,d,e,sum;
float avg;
clrscr();
printf(“Enter the value of a”);
scanf(“%d”,&a);
printf(“Enter the value of b”);
scanf(“%d”,&b);
printf(“Enter the value of c”);
scanf(“%d”,&c);
printf(“Enter the value of d”);
scanf(“%d”,&d);
printf(“Enter the value of e”);
scanf(“%d”,&e);
sum a+b+c+d+e;
avg=sum/5;
printf(“”\nThe avg of 5 numbers is
%0.2f”,avg);
getch();
}
OUTPUT:-
Enter value of a 1
Enter value of b 2
Enter value of c 3
Enter value of d 4
Enter value of e 5
The avg of 5 numbers is 3:00
2. Write a C program to calculate the simple interest.
#include<stdio.h>
#include<conio.h>
void main()
{
Int p,n,r,si;
clrscr();
printf(“Enter principle amount”);
scanf(“%d”,&p);
printf(“Enter no of months”);
scanf(“%d”,&n);
printf(“Enter rate of interest”);
scanf(“%d”,&r);
si=(p*n*r)/100;
printf(“\n the simple interest is %0.2f”,si);
getch();
}
OUTPUT:-
Enter principle amount 2000
Enter no of monthd 12
Enter rate of interest 9
The simple interest is 2160.00
3. Write a C program to create a user choice-based
week days using switch case.
#include<stdio.h>
#include<conio.h>
void main()
{
int day;
printf(“”\n Enter week days no between 1-
7:”);
scanf(“%d”,&day);
switch(day)
{
Case 1:
Printf(“\n Monday”);
Break;
Case 2:
Printf(“\n Tuesday”);
Break;
Case 3:
Printf(“\n Wednesday”);
Break;
Case 4:
Printf(“\n Thursday”);
Break;
Case 5:
Printf(“\n Friday”);
Break;
Case 6:
Printf(“\n Saturday”);
Break;
Case 7:
Printf(“\n Sunday”);
Break;
Default;
Printf(“\n Invalid day”);
}
Getch();
}
OUTPUT:-
Enter the week days no between 1-7: 3
Wednesday
4. Write a C program to find the lowest of 3 nos.
#include<stdio.h>
#include<string.h>
Void main()
{
Int a,b,c;
Printf(“Enter the value of a”);
Scanf(“%d”,&a);
Printf(“Enter the value of b”);
Scanf(“%d”,&b);
Printf(“Enter the value of c”);
Scanf(“%d”,&c);
If(a<b && a<c)
{
Printf(“a is the slowest”);
}
If(“b<a && b<c”);
{
Printf(“b is the lowest”);
}
Else
{
Print(“C is the lowest”);
}
}
OUTPUT:-
Enter the value of a 4
Enter the value of a 6
Enter the value of a 9
a is the lowest
5. Write a C program to implement the use of pass
statement using for loop.
#include<stdio.h>
Int main()
{
For(int i=0; i<10; i++)
{
if(i % 2=1)
{
Continue;
}
Printf(“%d”,i);
}
Return 0;
}
OUTPUT:-
02468
6. Write a C program to create an array of fruits.
#include <stdio.h>
int main() {
char* fruits[] = {"cherry", "orange",
"blueberry", "pear", "grape"};
printf("The fruits are:\n");
for (int i = 0; i < 5; i++) {
printf("%s\n", fruits[i]);
}
return 0;
}
OUTPUT:-
The fruits are:
cherry
orange
blueberry
pear
grape
7. Write a C program to check whether the gives
alphabet is a vowel or consonant.
#include<stdio.h>
#include<string.h>
Void main()
{
Char letter;
Printf(“Enter any alphabet”);
Scanf(“%c”,&letter);
If(letter == ‘a’ || letter == ‘A’ || letter == ‘e’ ||
letter == ‘E’ || letter == ‘i’ || letter == ‘I’ ||
letter == ‘o || letter == ‘O’ || letter == ‘u’ ||
letter == ‘U’)
{
Printf(“%c is a vowel”,letter)
}
Else
{
Printf(“%c is a consonant”,letter);
}
}
OUTPUT:-
Enter any alphabet a
a is a vowel.
Enter any alphabet z
Z is a consonant.
8. Write a C program to find out the year of a birth of
user is a leap year or not.
#include<stdio.h>
void main()
{
int year;
printf("Enter the value of year in which you
were born");
scanf("%d",&year);
if(year %4==0)
{
printf("You were born in leap year");
}
else
{
printf("You were not born in leap year");
}
}
OUTPUT:-
Enter the year of birth:2005
2005 is not a leap year.
Enter the year of birth:2024
2024 is a leap year.
---------------x--------------x--------------