Fundamentals of Computer – C – programs Lab Programs (Manual)

Fundamentals of Computer – C – programs 

 

1) Write a program to input the rainfall of three consecutive days in CMS and find its average.


# include <stdio.h>
# include <conio.h>
void main()
{
float a,b,c,avg;
clrscr();
printf("Enter the rainfalls of three days in Cms:");
scanf("%f %f %f",&a,&b,&c);
avg=(a+b+c)/3;
printf("Average rainfall is %g ",avg);
getche();
}

OUTPUT
Enter the rainfalls of three days in Cms: 95 78 85
Average rainfall is 86


Explanation In the above program rainfall of three days are entered. Their sum is and average are calculated. Average is displayed.

2) Find the simple interest. Inputs are principal amount, period in year and rate of  interest.

 

# include <stdio.h>
# include <conio.h>
void main()
{
int p,n;
float r,si;
clrscr();
printf("Enter principle amount(p),period(n)in year & rate(r):\n");
scanf("%d%d%f",&p,&n,&r);
si=p*n*r/100;
printf("Simple interest =%.2f ",si);
getche();
}


OUTPUT


Enter principle amount(p),period(n)in year & rate(r):
2000 2 12
Simple interest =480.00


Explanation In the above program principle amount, period year and rate are entered.  The interest calculated and stored. In variable si. The value of si is displayed with printf () statement. It is a simple interest.
 
3) Write a program to find total number of minutes of 12 hours.

# include <stdio.h>
# include <conio.h>
void main()
{
int m,h=12;
clrscr();
m=h*60;
printf("Total no. of minutes in 12 hours =%d",m);
getche();

 


OUTPUT


Total no. of minutes in 12 hours =720
Explanation The total number of hours are multiplied by 60 to obtain total minutes and stored in variable m. The value of m is displayed on the screen.

4) Find the area and perimeter of a) square b) rectangle. Input the side(s) through the keyboard.

# include <stdio.h>
# include <conio.h>
void main()
{
float s,b,w,as,ar,ps,pr;
clrscr();
printf("Enter the side of square(s),breath(b) and width(w) of rectangle:\n");
scanf("%f%f%f",&s,&b,&w);
as=s*s;
ar=b*w;
ps=4*s;
pr=2*(b+w);
printf("Area of square =%.2f\nArea of rectangle =%.2f",as,ar);
printf("\nPerimeter of square=%.2f\nPerimeter of rectangle=%.2f",ps,pr);
getche();

 


OUTPUT


Enter the side of square(s),breath(b) and width(w) of rectangle:
10 5 20
Area of square =100.00
Area of rectangle =100.00
Perimeter of square=40.00
Perimeter of rectangle=50.00


Explanation the values such as breath, width are entered. Using appropriate formulas area of square, area of rectangle, perimeter of square and perimeter of rectangle are calculated.


5) Accept any three numbers and find their squares and cubes.

# include <stdio.h>
# include <conio.h>
void main()
{
float n1,n2,n3,s1,s2,s3,c1,c2,c3;
clrscr();
printf("Enter the three Nos.:");
scanf("%f%f%f",&n1,&n2,&n3);
s1=n1*n1;
s2=n2*n2;
s3=n3*n3;
c1=n1*n1*n1;
c2=n2*n2*n2;
c3=n3*n3*n3;
printf("Number=%.2f its square =%.2f its cube =%.2f",n1,s1,c1);
printf("\nNumber=%.2f its square =%.2f its cube =%.2f",n2,s2,c2);
printf("\nNumber=%.2f its square =%.2f its cube =%.2f",n3,s3,c3);
getche();
}

OUTPUT


Enter the three Nos.:2 3 4
Number=2.00 its square =4.00 its cube =8.00
Number=3.00 its square =9.00 its cube =27.00
Number=4.00 its square =16.00 its cube =64.00
Explanation In the above program two numbers are entered. Square and cube are calculated and displayed.

6) The speed of a van is 80 km / hour. Find the number of hours required for
covering a distance of 500 km.Write a program in this regard.


# include <stdio.h>
# include <conio.h>
void main()
{
float s=80,d=500,t;
clrscr();
t=d/s;
printf("Time required for van is %.2f hours:",t);
getche();
}
 


OUTPUT


Time required for van is 6.25 hours:
Explanation In the above program total distance is divided by speed /hour. The obtained
value is nothing but required hours.

7) Write a program to convert Inches to Centimeters.


# include <stdio.h>
# include <conio.h>
void main()
{
float i,c;
clrscr();
printf("Enter the no. of Inches:");
scanf("%f",&i);
c=2.54*i;
printf("%.2f inches =%.2fCms",i,c);
getche();
}

OUTPUT


Enter the no. of Inches:36
36.00 inches =91.44Cms
Explanation In the above program no. of inches are entered. To convert it in CMS, inches are multiplied by 2.54 and stored in variable c. The value of c is displayed on the screen.

8) Write a program to enter the name of this book and display it.

# include <stdio.h>
# include <conio.h>
void main()
{
char b[40];
clrscr();
printf("Enter the name of this book:");
gets(b);
printf("Name of this book is %s",b);
getche();
}

OUTPUT


Enter the name of this book: Programming with ANSI and Turbo C
Name of this book is Programming with ANSI and Turbo C
Explanation In the above program a character array b [40] is displayed. Using gets () the
name of book is entered. It is displayed using printf () statement.

9) Write a program to store and interchange two float numbers in variables a & b.


# include <stdio.h>
# include <conio.h>
void main()
{
float a,b,c;
clrscr();
printf("Enter any two Nos:");
scanf("%f%f",&a,&b);
c=a;
a=b;
b=c;
printf("Nos.after interchanging a=%.2f b=%.2f",a,b);
getche();
}

OUTPUT


Enter any two Nos:4.8 9.6
Nos.after interchanging a=9.60 b=4.80


Explanation Two float values are entered. Using third variable values are interchanged.
 
10) Write a program to enter text with gets () and display it using printf () statement also find the length of the text.

# include <stdio.h>
# include <conio.h>
# include <string.h>
void main()
{
char text[20];
int l;
clrscr();
printf("Enter the text:");
gets (text);
printf("Entered text is: %s",text);
l=strlen(text);
printf("\nThe length of entered text is %d",l);
getche();
}


 
OUTPUT
 
Enter the text:kamthane
Entered text is: kamthane
The length of entered text is 8


Explanation Using gets () string is entered. Using printf () statement without format string, string is displayed. The printf () statement returns total number of characters displayed. The return value is stored in variable l and displayed.
 
11) Write a program to ensure that the subtraction of any two-digit number and its reverse is always multiple of nine. For example entered number is 54 and it’s reverse is 45. The difference between them is 9.


# include <stdio.h>
# include <conio.h>
# include <math.h>
void main()
{
int n,a,b,rn,s=0;
clrscr();
printf("Enter any two digit no.");
scanf("%d",&n);
a=n/10;
b=n%10;
rn=(10*b)+a; //reverse of no.
printf("Reverse of No. is %d",rn);
s=abs(rn-n);
printf("\n Substraction of above Nos is %d",s);
if (s%9==0)
printf("\n Which is a multiple of 9\n");
else
printf("\n Substraction is not multiple of 9");
getche();
}

OUTPUT


Enter any two digit no.25
Reverse of No. is 52
Substraction of above Nos is 27
Which is a multiple of 9


Explanation In the above program an integer is entered and its reverse number is obtained. Modular operation with nine is performed on variable s. The difference between them is obtained. It absolute value is taken. Modular operation with nine is performed on absolute value. If the remainder is zero, the difference of the above number is multiple of nine.
 
12) Write a program to convert kilograms to grams.


# include <stdio.h>
# include <conio.h>
# include <string.h>
void main()
{
float k,g;
clrscr();
printf("Enter weight in kilogram:");
scanf("%f",&k);
g=k*1000;
printf("The calculated weight in grams is: %.2f",g);
getche();
}


OUTPUT
Enter weight in kilogram:3.5
The calculated weight in grams is: 3500.00
 
13) Write a program to find the total amount when there are 5 notes of Rs.100 , 3 notes of Rs.50 & 20 notes of Rs.20.


# include <stdio.h>
# include <conio.h>
void main()
{
int h=100,f=50,t=20,g;
clrscr();
g=5*h+3*f+20*t;
printf("The total amount in Rs is %d",g);
getche();
}


OUTPUT


The total amount in Rs is 1050
Explanation In the above program using multiplication operation sum of rupees is calculated and displayed.
 
14) Write a program to enter the temperature in Fahrenheit and convert it to
Celsius. Formula to be used is tc= ((tf-32)*5)/9 where tc and tf are temperatures in Celsius and Fahrenheit respectively.


# include <stdio.h>
# include <conio.h>
# include <string.h>
void main()
{
float tc,tf;
clrscr();
printf("Enter the temperature in Fahrenheit:");
scanf("%f",&tf);
tc=((tf-32)*5)/9;
printf("The calculated temperature in Celsius is: %.2f",tc);
getche();
}


OUTPUT
Enter the temperature in Fahrenheit: 100
The calculated temperature in Celsius is: 37.78
 
15) Write a program to display list of c program files and directories. Use system () function to execute Dos commands.


#include <stdio.h>
#include <conio.h>
# include <process.h>
void main ()
{
clrscr();
system("dir *.c");
}


Explanation In the above program the system () function is used to invoke dos
command. The command “dir *.c” is given as argument in the system command.

1 comment:

  1. I recently came across this post, and I just had to leave a comment to express my appreciation. Renting Laptops near me

    ReplyDelete