Vous êtes sur la page 1sur 14

C PROGRAMMING PRACTICAL FILE

Priya Singh.


Q. Write a program to display Hello.

Algorithm:
Start.
Display hello.
Stop.

Coding:
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
printf("Hello");
getch();
}

Output:












C PROGRAMMING PRACTICAL FILE

Priya Singh.



Q. Write a program to display your name, age and date of birth.

Algorithm:

Start.
Display name, age, date of birth.
Stop.

Coding:

#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
printf("\nPriya Singh\t\t10.04.1996\t\t18");
getch();
}

Output:









C PROGRAMMING PRACTICAL FILE

Priya Singh.


Q. Write a program to ask the user for employee ID, Age, Salary and display the
same.
Algorithm:
Start.
Take three variables-id, age, salry.
Initialize all three variables and store the values.
Display the result that is, employee id, age, salary.
Stop.
Coding:
#include<stdio.h>
#include<conio.h>
void main()
{
int id,age;
float salry;
clrscr();
printf("Enter your employee ID ");
scanf("%d",&id);
printf("Enter your age ");
scanf("%d",&age);
printf("Enter your salary ");
scanf("%f",&salry);
printf("Your ID is %d\n",id);
printf("Your age is %d\n",age);
printf("Your salary is %f\n",salry);
getch();
}
Output:




C PROGRAMMING PRACTICAL FILE

Priya Singh.

Q. Write a program to generate the following table:
1992 17421
1993 29210
1994 100523
Algorithm:
Start.
Write the statement to display the given table.
Stop.

Coding:
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
printf("\t1992\t\t17421\n\t1993\t\t29210\n\t1994\t\t100523\n");
getch();
}

Output:







C PROGRAMMING PRACTICAL FILE

Priya Singh.

Q. Write a program to display the following table:
SUBJECTS MARKS
Physics 90
Chemistry 77
Maths 69
Algorithm:
Start.
Write the statement to display the given table.
Stop.

Coding:
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
printf("SUBJECTS\t\tMARKS\nPhysics\t\t\t90\nChemistry\t\t77\nMaths\t\t\t69\n");
getch();
}
Output:







C PROGRAMMING PRACTICAL FILE

Priya Singh.

Q. Write a program to calculate marks of five subjects and find percentage.

Algorithm:
Start.
Take seven variables-eng, maths, phy, TC, C, total, per.
Initialize eng, maths, phy, TC, C.
Calculate total of all five subjects and its percentage.
Display the result that is, total and percentage.
Stop.

Coding:
#include<stdio.h>
#include<conio.h>
void main()
{
float eng,maths,phy,TC,C,total,per;
clrscr();
printf("Enter the marks for English ");
scanf("%f",&eng);
printf("Enter the marks for Maths ");
scanf("%f",&maths);
printf("Enter the marks for Physics ");
scanf("%f",&phy);
printf("Enter the marks for TC ");
scanf("%f",&TC);
printf("Enter the marks for C ");
scanf("%f",&C);
total=eng+maths+phy+TC+C;
printf("Total marks=%f\n",total);
per=(total/500)*100;
printf("Percentage=%f\n",per);

Output:


C PROGRAMMING PRACTICAL FILE

Priya Singh.

Q. Write a program to find simple interest.

Algorithm:
Start.
Take four variables-p, r, t, SI.
Initialize the value of p, r, t.
Calculate simple interest.
Display the output that is, simple interest.
Stop.

Coding:
#include<stdio.h>
#include<conio.h>
void main()
{
float p,r,t,SI;
clrscr();
printf("Enter the principle ");
scanf("%f",&p);
printf("Enter the rate ");
scanf("%f",&r);
printf("Enter the time ");
scanf("%f",&t);
SI=(p*r*t)/100;
printf("Simple interest is=%f",SI);
getch();
}

Output:



C PROGRAMMING PRACTICAL FILE

Priya Singh.

Q. Write a program to convert temperature from Celsius to Fahrenheit.

Algorithm:
Start.
Take two variables-temp, fah.
Initialize the variable temp.
Calculate temperature in Fahrenheit by using formula= (9*(temp+32))/5.
Display the output that is, temperature in Fahrenheit.
Stop.

Coding:
#include<stdio.h>
#include<conio.h>
void main()
{
floattemp,fah;
clrscr();
printf("Enter the temperature in celcius ");
scanf("%f",&temp);
fah=(9*(temp+32))/5;
printf("Temperature in fahrenheit = %f",fah);
getch();
}

Output:




C PROGRAMMING PRACTICAL FILE

Priya Singh.

Q. Write the program to find:
a) Area of circle and circumference of circle.
b) Area of triangle.
c) Area of rectangle.

a) Area of circle:
Algorithm:
Start.
Take two variables-radius, aoc.
Initialize the variable radius.
Calculate the Area of circle by using formula aoc=3.14*radius*radius.
Display the output that is, aoc.
Stop.
Coding:
#include<stdio.h>
#include<conio.h>
void main()
{
float radius,aoc;
clrscr();
printf("Enter the radius ");
scanf("%f",&radius);
aoc=3.14*radius*radius;
printf("Area of circle is %f",aoc);
getch();
}

Output:


C PROGRAMMING PRACTICAL FILE

Priya Singh.



Circumference of circle:
Algorithm:
Start.
Take two variables-r, coc.
Initialize the variable r.
Calculate the circumference of circle by using formula coc=2*3.14*r.
Display the output that is, coc.
Stop.
Coding:
#include<stdio.h>
#include<conio.h>
void main()
{
float r,coc;
clrscr();
printf("Enter the radius ");
scanf("%f",&r);
coc=2*3.14*r;
printf("Circumference of circle is %f",coc);
getch();
}

Output:



C PROGRAMMING PRACTICAL FILE

Priya Singh.


b) Area of triangle:
Algorithm:
Start.
Take three variables-b, h, aot.
Initialize the variable b, h.
Calculate the circumference of circle by using formula aot=2*3.14*r.
Display the output that is, aot.
Stop.
Coding:
#include<stdio.h>
#include<conio.h>
void main()
{
float b,h,aot;
clrscr();
printf("Enter the base ");
scanf("%f",&b);
printf("Enter the height ");
scanf("%f",&h);
aot=0.5*b*h;
printf("Area of triangle is %f",aot);
getch();
}

Output:





C PROGRAMMING PRACTICAL FILE

Priya Singh.


c) Area of rectangle:
Algorithm:
Start.
Take three variables-l, b, aor.
Initialize the variable l, b.
Calculate the circumference of circle by using formula aor=l*b.
Display the output that is, aor.
Stop.
Coding:
#include<stdio.h>
#include<conio.h>
void main()
{
int l,b,aor;
clrscr();
printf("Enter the length ");
scanf("%d",&l);
printf("Enter the breath ");
scanf("%d",&b);
aor=l*b;
printf("Area of rectangle is %d",aor);
getch();
}

Output:



C PROGRAMMING PRACTICAL FILE

Priya Singh.


Q. Write a program to show swapping of two numbers with and without using
third variable.
Using third variable:
Algorithm:
Start.
Take three variables a, b and c.
Initialize a and b.
Store the value of a in c that is, c=a
Store the value of b in c that is, a=b.
Store the value of c in b that is, b=c.
Display the value of a and b.
Stop.
Coding:
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c;
clrscr();
printf("Enter the value of a ");
scanf("%d",&a);
printf("Enter the value of b ");
scanf("%d",&b);
c=a;
a=b;
b=c;
printf("Swapped values of a and b are %d %d",a,b);
getch();
}

Output:


C PROGRAMMING PRACTICAL FILE

Priya Singh.


Without using third variable:

Algorithm:
Start.
Take two variables a, b.
Initialize a and b.
Store the value of a that is, a=a^b.
Store the value of b that is, b=a^b.
Store the value that is, a=a^b.
Display the value of a and b.
Stop.
Coding:
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b;
clrscr();
printf("Enter the value of a ");
scanf("%d",&a);
printf("Enter the value of b ");
scanf("%d",&b);
a=a^b;
b=a^b;
a=a^b;
printf("Swapped values of a and b are %d %d",a,b);
getch();
}

Output:

Vous aimerez peut-être aussi