Practical activity
Topic 9:
Fundamentals of input and output handling
1. To find the volume of a cube, cylinder or sphere
Algorithm:
Step 1: start
Step 2: input numbers, side
Step 3: side *side*side
Step 4: output volume
Step 5: end
Coding:
#include<stdio.h>
#include<conio.h>
void main()
{
float
volume,lenght,radius,PI,volumeofcylinder,volumeofspher
e,height;
lenght= 4;
radius=6;
PI= 3.14;
height=8;
Volume=length*(length*length);
Volumeofcylinder= PI*(radius*radius)* height;
Volumeofsphere=4/3*PI*(radius*radius*radius);
Printf ("%f volume”, volume);
Printf ("%f volume of cylinder”,volumeofcylinder);
printf("%f volume of sphere",volumeofsphere);
getch();
}
2. To find the area of a triangle, parallelogram,
rhombus and trapezoid
Algorithm :
Step 1: start
Step 2: input numbers base,height
Step 3: area=base*height
Step 4: output area
Step 5: end
Coding :
#include<stdio.h>
#include<conio.h>
void main()
{
Int area,b,h,p,q,areaofparallogram,areaofrhombus;
b= 20;
p=10;
h=15;
q=8;
area=1/2*(base*height);
printf("%d area",area);
areaofparallogram= base* height;
printf("%d areaofparallogram",areaofparallogram);
areaofrhombus=(p*q)/2;
printf("%d areaofrhombus",areaofrhombus);
printf("%d area",area);
printf("%d areaofparallogram",areaofparallogram);
printf("%d areaofrhombus",areaofrhombus);
getch() ;
}
3. To calculate the exponent of a given number
Coding :
#include<math.h>
#include<stdio.h>
main()
{
int base, exp, result;
printf("Enter a base number: ");
scanf("%d", &base);
printf("Enter an exponent: ");
scanf("%d", &exp);
result = pow(base, exp);
printf("%d %d %d ", base, exp, result);
getch();
}
4. To convert Celsius to Fahrenheit temperature and
vice versa
Algorithm :
Step1: start
Step2: input number Celsius
Step3: set Fahrenheit to (Celsius*9)/5+32
Step4: output Fahrenheit
Step5: input number Fahrenheit
Step6: set Celsius to (farenhite-32 )*5/9
Step7: output Celsius
Step8: end
Coding :
#include<stdio.h>
#include<conio.h>
Main ()
{
Float Fahrenheit, Celsius;
Gets ("enter value of Celsius");
Puts ("enter value of Celsius");
Fahrenheit = (Celsius * 9) / 5 + 32;
Printf ("%f Fahrenheit, Fahrenheit");
}
5. To Prepare an electricity bill
Algorithm :
Step1: start
Coding :
#include<stdio.h>
#include<conio.h>
void main ()
{
char name[200];
printf(" Enter the customer Name ");
gets( name );
puts( name );
getch();
char address[200];
printf(" Enter the customer address ");
gets( address );
puts( address );
getch();
char billingmonth[200];
printf(" Enter the billingmonth ");
gets( billingmonth );
puts( billingmonth );
getch();
float customerid,presentreading ,previousreading ,
meternumber,unitconsumed,perunitrate,KECharges,GST,Elect
ricityDuty,totalamount ;
printf("Enter the customerid");
scanf("%f",& customerid);
getch();
printf("Enter the presentreading");
scanf("%f",& presentreading);
getch();
printf("Enter the previousreading");
scanf("%f",& previousreading);
getch();
printf("Enter the meter number");
scanf("%f",& meternumber);
getch();
printf("Enter perunitrate");
scanf("%f",& perunitrate);
getch();
printf("Enter GST");
scanf("%f",& GST );
getch();
unitconsumed=presentreading-previousreading;
printf("%f unitconsumed",unitconsumed);
getch();
KECharges=perunitrate*unitconsumed;
printf("%f KECharges",KECharges);
getch();
totalamount= KECharges+ElectricityDuty+GST;
printf("%f totalamount",totalamount);
getch();
}
6. To find the interest in an amount:
Algorithm :
Step 1: start
Step 2: input number p,r,t
Step 3: calculate interest using formula si=(p*r*t)/100
Step 4: print simple interest si
Step 5: end
Coding :
#include<stdio.h>
#include<conio.h>
main()
{
int p,r,t,iint;
p=2;
r=4;
t=6;
int i=(p*r*t)/100;
printf=("%d int",int);
getch()
}
7. To find the sum, product, and average of five given
numbers
Algorithm:
Step 1: start
Step 2: take five numbers suppose a,b,c,d and e
Step 3: declare variable sum,prod and avg
Step 4: sum=a+b+c+d+e
Step 5: prod=a*b*c*d*e
Step 6: avg=sum/5
Step 7: display result of sum,prod and avg
Step 8: end
Coding :
#include<stdio.h>
#include<conio.h>
main()
{
int add,mul,avg;
int a=40 ,b=20 ;
add = a+b;
printf("Addition of a, b is : %d\n", add);
mul = a*b;
printf("Multiplication of a, b is : %d\n", mul);
avg=sum/5;
printf("average of a,b is :%d/n",avg);
getch();
}
8. To find acceleration of a moving object with given
mass and the force applied:
Algorithm :
Step 1: start
Step 2: input numbers mass and force
Step 3: set acceleration to force/mass
Step 4: output acceleration
Step 5: end
Coding:
#include<stdio.h>
#include<conio.h>
main()
{
int m,f,a,acc;
f=50;
m=10;
a=f/m;
printf("%d acc",acc);
getch();
}