Practical File For C
Practical File For C
Program:-
#include<iostream.h>
#include<stdio.h>
main()
int number;
scanf(“%d”,& number);
if( number/2==0)
Printf(“number is even”);
else
printf(“number is odd”);
Output:-
Algorithm:-
1.input no.
Start
Input number
If
number/2 Number is even
Number is odd
Stop
Page |3
Program:-
#include<iostream.h>
#include<stdio.h>
Main ()
Int a, b,c,d,e,f,g;
Scanf(“%d%d”,&a,&b);
c=a+b;
d=a-b;
e=a*b;
f=a/b;
g=a%b;
Printf(“Addition:%d/n”,c);
Printf(“Substraction:%d/n”,d);
Printf(“Multiplication:%d/n”,e);
Printf(“Division:%d/n”,f);
Printf(“Module division:%d/n”,g);
Output:-
Enter first no a= 4;
Add.c=6
Sub.d=2
Multi.e=8
Div.f=2
Modiv.g=0
Page |4
start
c=a+b
d=a-b
e=a*b
f=a/b
g=a%b
Ptint a,b,c,d,e,f,g
stop
Page |5
# include<stdio.h>
main()
Int p,r,t,si;
printf(“enter p,r,t”);
scanf(“%d%d%d”,&p&r&t);
si== p*r*t/100;
printf(“si”);
getch();
Output:-
Enter p=10000
r=3%
t= 1 year
print si=30,000
Algorithm:-
1. input p,r,t
2. process si=(p*r*t)/100
3. output si
Page |6
start
input p,r,t
si= p*r*t/100
print SI
stop
Page |7
#include(stdio.h)
main()
int i;
clrscr()
for(i=1;i<=10;i++)
Printf(“%d”,i);
If(i==5)
break;
getch()
Output:-
1
Algorithm:-
2.Output i
Page |8
start
input i
For i=1;<=10;i++
If==5 Break
Go to for
stop
Page |9
#include<stdio.h>
main()
int i
clrscr();
for(i=1;i<=10;i++)
Printf(“%d”,i);
If(i>=5&&i<=8)
continue
getch();
Output:-
1
10
Algorithm:-
1.Check till i<=10
2.Output i
P a g e | 10
start
input i
For i=1;<=10;i++
If==5 continue
Go to for
stop
P a g e | 11
#include<stdio.h>
main()
int age;
printf(“enter the age/n”);
scanf(“%d”,&age);
Output:
Enter the age =19
Algorithm:-
1. input age
2. if age>=18 person can vote else can’t vote
3. output age
P a g e | 12
START
Input age
If age >=18
stop
P a g e | 13
#include<stdio.h>
Scanf(“%d”,&per);
if(per>=80)
Printf(“Merit”);
else if(per>=60)
Printf(“First”);
else if(per>=45)
Printf(“Second”);
else if(per>=33)
Printf(“Third”);
else
printf(“Fail”)
}
P a g e | 14
}
P a g e | 15
Input per
If per>=80
merit
Per>=60 first
Per>=60
Per>=45 second
Per>=33 third
fail
stop
P a g e | 16
#include<stdio.h>
main()
Int a,b,c,d;
Clrscr();
getch( );
Output:-
Size of integer
Size of float
Size of char
Size of double
P a g e | 17
Input
int,float,char,double
size of int
Size of float
Size of char
Size of double
stop
P a g e | 18
#include<stdio.h>
main()
Int year;
Scanf(“%d”,& year);
Output:-
Algorithm:-
1. input year
2. if year/4==0 leap year else leap year
3. output year
P a g e | 19
Start
Input year
Stop
P a g e | 20
#include<stdio.h>
Main()
Int a,b,c;
Scanf(“%d%d%d”,&&a,&&b,&&c);
If(a>b&&a>c)
Printf(“a is greater”);
If (b>a&&b>c)
Printf(“b is greater”);
Else(“c is greater”);
Output:-
C is greater
P a g e | 21
Start
If
a>b&&a>c A is greater
If
b>c&&b>a B is greater
C is greater
Stop
P a g e | 22
P a g e | 23
#include<stdio.h>
Main()
Int a,b,c;
Scanf(“%d%d%d”,&&a,&&b,&&c);
If(a>b&&a<c)
Printf(“a is middle”);
If (b>a&&b<c)
Printf(“b is middle”);
Else(“c is middle”);
Output:-
B is middle
P a g e | 24
Start
If
a>b&&a<c A is middle
If
b>a&&b<c B is middle
C is middle
Stop
P a g e | 25
Program:-
#include<iostream.h>
#include<stdio.h>
Main ()
Int a,b;
Scanf(“%d%d”,&a&b);
getch();
Output:-
Enter two number a=1,b=2
a is smaller
Algorithm:-
1. input a,b
2. conditional process
3. output a is smaller
P a g e | 26
Start
if Yes
A is smaller
b>a
No
B is smaller
Stop
P a g e | 27
#include<stdio.h>
Main ()
Int avg,sum=0;
Int i;
For (“i=0;I<=29;i++)
For (i=0;i<=29;i++)
Sum=sum+marks[i];
Avg=sum/30;
}
P a g e | 28
Output:-
Algorithm:-
1.input marks
2.For((i=0;i<=29;i++)
3.output total
4.output avg
P a g e | 29
start
For(i=1,i<=29,i++)
Sum=sum+0
Avg=sum/30
Print sum,avg
stop
P a g e | 30
#include<stdio.h>
Main()
Int x,y,rev=0;
Clrscr();
While(xǃ0)
Scanf(“%d”,&X);
X=Y;
X=X/10;
Y=Y%10;
rev=rev+y;
Output:-
enter any number 123
start
input x,y,rev=0
While(x!0)
X=Y;
X=X/10;
Y=Y%10;
rev=rev+y;
Print rev
stop
P a g e | 32
Program:-
#include<iostream.h>
#include<stdio.h>
Main()
Int a,b,i;
i=1;
clrscr();
scanf(“%d”,&a);
while(i<=10)
b=a*I;
Printf(“\n%d”,b);
i++;
getch();
8
P a g e | 33
10
12
14
16
18
20
Algorithm:-
1. Input a,b,i
2. Check i<=10
3. Calculate b=a*i
4. Output b
P a g e | 34
Start
input i
I<=10
Go to for
Break
stop
P a g e | 35
**
***
****
Program:-
#include<iostream.h>
#include<stdio.h>
Void main()
int I, j;
clrscr();
for(i=1;i<=5;i++)
for(j=1;j<=i;j++)
Printf(“*”);
Printf(“\n”);
getch();
}
P a g e | 36
Output:-
**
***
****
*****
Algorithm:-
1. Input i,j
start
Input I,j
For(i=1,j<=i;i++)
For(j=1;j<=i;j++)
Print *
Print \n
Stop
P a g e | 38
Program:-
#include<iostream.h>
#include<stdio.h>
Void main()
Char name[10],*ptr;
Clrscr();
scanf(“%s”,name);
ptr=name;
printf(“\n name=%s’’,ptr);
getch();
Output:-
Name=xyz
Algorithm:-
1. Input name,*ptr
2. Output name
P a g e | 39
start
input name
ptr=name
print ptr
stop
P a g e | 40
Program:-
#include<stdio.h>
#include<conio.h>
Void main()
Int a,i;
Clrscr();
Printf(“enter a no.”);
Scanf(“%d”,&a);
if(a==1)
for(i=2;i<=a;i++)
if(a%i==0)
Break;
if(i==a)
getch();
}
P a g e | 41
Output:-
Enter a no.=3
3 is a prime no.
Algorithm:-
1. Input a
2. Check a==1 then output prime no.
3. Check for i<=a and a%i==0 then output not a prime no.
4. Check i==a then output prime no.
P a g e | 42
Start
Input a,i
If a==1
Prime no.
for(i=2;i<=a;i++)
If a==1
Break
Prime no.
stop
P a g e | 43
Program:-
#include<stdio.h>
#include<conio.h>
Struct stud
Float per,tot;
Char name[10];
Void main()
Struct stud s;
Clrscr();
Scanf(“%d”&s.roll no.);
fflush(stdin);
printf(“enter name”);
scanf(“%s”,&s.name);
scanf(“%d%d%d”,&s.fm,&s.cm,&s.om);
s.tot=s.fm+s.cm+s.om;
s.pre=(s.tot/300)*100;
printf(“****************”);
printf(“\n\t\t\t markshee\n”);
printf(“*****************”);
P a g e | 44
printf(“\n marks”);
printf(“\n%d\t\t%d\t\t%d”,s.fm,s.cm,s.om);
printf(“\n total=%f”,s.tot”);
printf(“\n percent=%f”,s.per);
getch();
Output:-
………………………………………………………………………………………………………
Mark sheet
…………………………………………………………………………………………………......
Roll no.=50221
Name= virat
Marks=
Fundamental c office
65 76 78
Total=219.00
Present=73.00%
Algorithm:-
Start
s.tot=s.fm+s.cm+s.om
S.per=(s.tot/300)*100
stop
P a g e | 46
Program:-
#include<stdio.h>
#include<conio.h>
Void main()
Int a,b,c,I,n;
Clrscr();
a=0;
b=1;
printf(“enter trams”);
scanf(“%d”,&n);
scanf(“%d%d”,a,b);
for(i=1;i<=n-2;i==)
c =a+b;
a=b;
b=c;
printf(“c”);
getch();
01123
P a g e | 47
Algorithm:-
1. Input n
2. Output a,b
3. Check till i<n-2then c=a+b
4. a=b,b=c
5. output c
P a g e | 48
start
Input n
i=1;i<=n-2;i++
C=a+b
a=b,b=c
Print c
Stop
P a g e | 49
Program:-
#include<iostream.h>
#include<stdio.h>
Main()
Int I;
For(i=0;i<=4;i++)
Scanf(“%d”,&marks[i]);
For(i=0;i<=4;i++)
Sum=sum+marks[i];
Avg=sum/5;
}
P a g e | 50
Output:-
Avg no. 33
Algorithm:-
1.input marks
2.For((i=0;i<=4;i++)
3.output total
4.output avg
P a g e | 51
start
For(i=1,i<=4,i++)
Sum=sum+0
Avg=sum/5
Print sum,avg
stop
P a g e | 52
#include<stdio.h>
int x=100;
main()
Clrscr();
printf(“Value of x=”,X/n);
printf(“Value of ::”,X);
getch();
}
P a g e | 53
Program:-
# include<iostream.h>
# include<stdio.h>
Main()
char a,e,I,o,u;
scanf (“%char”,);
switch(a)
Case a:
Printf (“vowel”);
Break;
Case e:
Printf(“vowel”);
Break ;
Case I:
Printf (“vowel”);
Break ;
P a g e | 54
Case o:
Printf(“vowel”);
Break ;
Case u:
Printf (“vowel”);
Break ;
Default :
Printf (“consonant”);
Getch ();
Output:-
P a g e | 55
Start
Char a,e,I,o,u
Case a
Vowel
Case e
Vowel
Case i
Vowel
Case o
Vowel
Case u
Vowel
Default
Stop
P a g e | 56
# include<stdio.h>
Void main()
Char na[3];
Int a;
Clrscr();
Scanf(“%s”,&na);
a=na[0];
na[0]=a-32;
a=na[1];
na[1]=a-32;
getch();
Output:-
upper case= AB
Algorithm:-
1. Input a,name
# include<stdio.h>
Void main()
Int x;
Int*p;
Clrscr();
Scanf(“%d”,&x);
P=&x;
Printf(“address of x:\n”);
Printf(“value of x:\n”);
getch();
Output:-
Enter any number 12
Address of x
Value of x
P a g e | 58
# include<stdio.h>
Void main()
Int a=10,b=20;
Clrscr();
Printf(“%d%d”,a “and”b);
Change(a b)
getch();
X=100;
Y=200;
a=x+y;
b=x-y;
}
P a g e | 59
Output:-
Algorithm:-
1. Input a,b
2. a=x+y
b=x-y
3. print a,b
P a g e | 60
start
Input a, b
a=x+y
b=x-y
Print a,b
stop
P a g e | 61
# include<stdio.h>
Void main()
Int a=10,b=20;
Clrscr();
a=a+b;
b=a-b;
Output:-
a=20,b=10
Algorithm:-
1. Input a,b
2. a=a+b
b=a-b
3. print a,b
P a g e | 62
start
Input a, b
a=a+b
b=a-b
Print a,b
stop
P a g e | 63
Algorithm:-
1.input age
2.age>=18
3. Person can get driving license else Person can’t get driving license
P a g e | 64
START
Input age
If age >=18
stop
P a g e | 65
* *
* * *
* * * *
* * * * *
Program:-
#include<iostream.h>
#include<stdio.h>
Void main()
int i, j, k;
char c;
clrscr();
printf(“enter character”);
scanf(“%c”,&c);
for(i=j;j<=5;i++)
for(j=5;j<=i;j--)
Printf(“ ”);
for(k=j;k<=I;k++)
P a g e | 66
Printf(“%c,c”);
print(“\n”);
getch();
Output:-
Enter character *
* *
* * *
* * * *
* * * * *
Algorithm:-
1. Input i,j,k,c
3.output pattern
P a g e | 67
start
Input c
for(i=j;j<=5;i++)
for(k=j;k<=I;k++) Print c
Print \n
Stop
P a g e | 68