LAB FILE
1.WAP that accepts the marks of 5 subjects and finds the
sum and percentage marks Obtained by the student.
#include <stdio.h>
#include <conio.h>
void main()
{
float phy, che, maths, bio, eng, percentage;
printf("enter marks in physic,chemistry,maths,biology,english
respectivily");
scanf("%f%f%f%f%f", &phy, &che, &maths, &bio, &eng);
percentage = (phy + che + maths + bio + eng) / 5;
printf("your percentage is:%f", percentage);
getch();
}
2.WAP that calculates the Simple Interest and Compound
Interest. The Principal, Amount, Rate of Interest and Time are
entered through the keyboard.
include <stdio.h>
#include <conio.h>
void main()
{
float A,P,R,T,SI,CI;
printf("ENTER THE AMOUNT,PRINCIPLE,TIME AND RATE RESPECTIVILY: ");
scanf("%f%f%f%f",&A,&P,&R,&T);
SI=(P*R*T)/100;
CI=A-P;
printf("Simple interest:%f \n Compound Interest:%f",SI,CI);
getch();
}
3.WAP to calculate the area and circumference of a circle.
#include <stdio.h>
#include <conio.h>
void main()
{
float r,circum,area;
printf("enter the radius of the circle: ");
scanf("%f",&r);
circum=2*3.14*r;
area=3.14*r*r;
printf("The circumference of the circle is: %f , The area of the
circle is: %f",circum,area);
getch();
}
4.WAP that accepts the temperature in Centigrade and
converts into Fahrenheit.
#include <stdio.h>
#include <conio.h>
void main()
{
float C,F;
printf("enter the temperature in centigrade: ");
scanf("%f",&C);
F=((C*9)/5)+32;
printf("the temprature in Fahrenheit is: %0.0f ",F);
getch();
}
5.WAP that swaps values of two variables without using a
third variable.
#include <stdio.h>
#include <conio.h>
void main()
{
int a,b,t;
printf("enter the two number to swap a and b ");
scanf("%d%d",&a,&b);
t=a;
a=b;
b=t;
printf("your swaped number are a:%d , b:%d ",a,b);
getch();
}
6.WAP that checks whether the two numbers entered by the
user are equal or not.
#include <stdio.h>
#include <conio.h>
void main()
{
int a,b;
printf("enter the value of a and b respectivily: ");
scanf("%d%d",&a,&b);
if(a==b)
{
printf("the value of a and b is equal");
}
else
{
printf("the value of a and b is not equal");
}
getch();
}
7.WAP to find the greatest of three numbers using nested if-
else.
#include <stdio.h>
#include <conio.h>
void main()
{
int a,b,c;
printf("enter the numbers");
scanf("%d%d%d",&a,&b,&c);
if(a>b)
{
if(a>c)
{
printf("the number:%d is the greatest",a);
}
else
{
printf("the number:%d is the greatest",c);
}
}
else
{
if(b>c)
{
printf("the number:%d is the greatest",b);
}
else
{
printf("the number:%d is the greatest",c);
}
}
getch();
}
8.WAP that finds whether a given number is even or odd.
#include <stdio.h>
#include <conio.h>
void main()
{
int num;
printf("enter number: ");
scanf("%d",&num);
if(num%2==0)
{
printf("the given number:%d is even",num);
}
else
{
printf("the given number:%d is odd",num);
}
getch();
}
9.WAP that tells whether a given year is a leap year or not.
#include <stdio.h>
#include <conio.h>
void main()
{
int year;
printf("enter the year:");
scanf("%d",&year);
if(year%400==0 || year%4==0 && year%100!=0)
{
printf("the given year:%d is leap year",year);
}
else
{
printf("the given year:%d is not a leap year",year);
}
getch();
}
10.WAP that accepts marks of five subjects and finds
percentage and prints grades according to the following
criteria:
Between 90-100%-----Print ‘A’
80-90%-----------------Print ‘B’
60-80%-----------------Print ‘C’
Below 60%-------------Print ‘D’
#include <stdio.h>
#include <conio.h>
void main()
{
float phy, che, maths, bio, eng, percentage;
printf("enter marks in physic,chemistry,maths,biology,english
respectivily: ");
scanf("%f%f%f%f%f", &phy, &che, &maths, &bio, &eng);
percentage = (phy + che + maths + bio + eng) / 5;
if(percentage<=100 && percentage>90)
{
printf("your grade is 'A'");
}
else if(percentage<=90 && percentage>80)
{
printf("your grade is 'B'");
}
else if(percentage<=80 && percentage>60)
{
printf("your grade is 'C'");
}
else if(percentage<60)
{
printf("your grade is 'D'");
}
else
{
printf("RE-ENTER");
}
getch();
}
11.WAP to check Prime number or not.
#include <conio.h>
#include <stdio.h>
void main()
{
int i, num, t = 0;
printf("Enter any numb to Check for Prime: ");
scanf("%d", &num);
for (i = 2; i <= num / 2; i++)
{
if (num % i == 0)
{
t = t + 1;
}
}
if (t == 0 && num != 1)
{
printf("%d is a Prime number", num);
}
else
{
printf("%d is not a Prime number", num);
}
getch();
}
12.WAP to print the sum of all numbers up to a given number.
#include <stdio.h>
#include <conio.h>
void main()
{
float sum=0,t;
int n;
printf("enter the number of times you want to add: ");
scanf("%d",&n);
n=n+1;
for (int i = 1; i < n; i++)
{ printf("enter the number: ");
scanf("%f",&t);
sum=sum+t;
}
printf("the sum of all numbers are: %0.f",sum);
13.WAP to find the factorial of a given number using
recursion.
#include <stdio.h>
#include <conio.h>
int fact(int n);
int fact(int n)
{ if(n==0)
{
return 1;
}
else
{
return n*fact(n-1);
}
}
void main()
{
int num,fa,t;
printf("enter the number: ");
scanf("%d",&num);
for(int i=0;i<=num;i++)
{
fa=fact(num);
}
printf("the factorial is: %d",fa);
getch();
}
14.WAP to print sum of even and odd numbers from 1 to N
numbers.
#include <stdio.h>
#include <conio.h>
void main()
{
int num,sum1=0,sum2;
printf("enter the number: ");
scanf("%d",&num);
num=num+1;
for(int i=1;i<=num;i++)
{
if(i%2==0)
{
sum1=sum1+i;
}
else
{
sum2=sum2+i;
}
}
printf("sum all even number: %d \nsum of all odd number:%d",sum1,sum2);
getch();
}
15.WAP to print the Fibonacci series upto 10 term.
#include<stdio.h>
#include<conio.h>
void main()
{int i,a=0,b=1,c;
for(int i=1;i<=10;i++)
{
printf("%d ",a);
c=a+b;
a=b;
b=c;
}
getch();
}
16.WAP to find GCD of any two given number.
#include<stdio.h>
#include<conio.h>
void main()
{int gcd=0,b,a;
printf("enter the two number to find gcd: ");
scanf("%d%d",&a,&b);
{
for(int i=1;i<=b;i++)
{
if(a%i==0 && b%i==0)
{
gcd=i;
}
}
}
printf("the gcd of two number: %d",gcd);
getch();
}
17.WAP to find the sum of digits of the entered number.
#include<stdio.h>
#include<conio.h>
void main()
{
int num,d,rev=0;
printf("enter the number: ");
scanf("%d",&num);
while(num>0)
{
d=num%10;
rev=rev+d;
num=num/10;
}
printf("the sum of your number's digit is: %d",rev);
getch();
}
18.WAP to find the reverse of a number.
#include<stdio.h>
#include<conio.h>
void main()
{
int num,d,rev=0;
printf("enter the number: ");
scanf("%d",&num);
while(num>0)
{
d=num%10;
rev=rev*10+d;
num=num/10;
}
printf("the reverse of your number is: %d",rev);
getch();
}
19.WAP to print Armstrong numbers from 1 to 100.
#include <stdio.h>
#include <conio.h>
void main()
{
int s=0,r,t,n;
for(int i=1;i<=100;i++)
{
t=i;
n=t;
while ( n!=0)
{
r = n % 10;
s = (r*r*r) +s;
n = n/10;
}
if(s==t)
{
printf("%d,",t);
}
s=0;
}
getch();
}
20.WAP to convert binary number into decimal number and
vice versa.
#include <stdio.h>
#include <conio.h>
#include <math.h>
int binaryToDecimal(long long BN)
{
int DN = 0, i = 0, R;
while (BN != 0)
{
R = BN % 10;
BN /= 10;
DN += R * pow(2, i);
++i;
}
return DN;
}
void decimalToBinary(int DN)
{
int BN[32], i = 0;
while (DN > 0) {
BN[i] = DN % 2;
DN /= 2;
++i;
}
printf("Binary number = ");
for (int j = i - 1; j >= 0; --j) {
printf("%d", BN[j]);
}
}
void main()
{
long long BN;
int DN;
printf("Enter a binary number: ");
scanf("%lld", &BN);
printf("Enter a decimal number: ");
scanf("%d", &DN);
decimalToBinary(DN);
DN = binaryToDecimal(BN);
printf("\nDecimal number = %d", DN);
getch();
}
21. WAP that simply takes elements of the array from the user
and finds the sum of these elements.
#include <stdio.h>
#include <conio.h>
void main()
{
int num,sum=0;
printf("enter the number of values you want to sum: ");
scanf("%d",&num);
int a[num];
num=num-1;
for(int i=0;i<=num;i++)
{ printf("enter the number: ");
scanf("%d",&a[i]);
sum=sum+a[i];
}
printf("the sum of all elements of array are: %d",sum);
getch();
}
22.WAP to swap two values using call by reference method.
#include <stdio.h>
#include <conio.h>
void swap(int *a,int *b);
void swap(int *a,int *b)
{ printf("enter the value of x and y respectivily: ");
scanf("%d%d",&*a,&*b);
*a=*a+*b;
*b=*a-*b;
*a=*a-*b;
}
void main()
{
int x,y;
swap(&x,&y);
printf("the swap values are x: %d and value of y: %d",x,y);
getch();
}
23.WAP to find the minimum and maximum element of the
array.
#include <stdio.h>
#include <conio.h>
void main()
{
int min,max,num;
printf("enter the number of elements you want to enter: ");
scanf("%d",&num);
int a[num];
num--;
for (int i = 0; i <= num; i++)
{
printf("enter the element: ");
scanf("%d",&a[i]);
}
min=a[0];
max=a[0];
for(int j=0;j<=num;j++)
{
if(min>a[j])
{
min=a[j];
}
else if(max<a[j])
{
max=a[j];
}
}
printf("the maximum number is: %d\n the minimun number is:
%d",max,min);
getch();
}
24.WAP to search an element in a array using Linear Search.
#include<stdio.h>
#include<conio.h>
void main()
{
int num,search;
printf("enter the number of elements in array: ");
scanf("%d",&num);
int a[num];
num--;
for (int i = 0; i < num; i++)
{
printf("enter the element: ");
scanf("%d",a[i]);
}
printf("enter the number you want to search");
scanf("%d",&search);
for (int i = 0; i < num; i++)
{
if(search==a[i])
{
printf("%d is at a[%d]",search,i);
}
}
getch();
}