Ppa Lab Mannual
Ppa Lab Mannual
Ppa Lab Mannual
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 per;
scanf("%d",&hindi);
scanf("%d",&english);
scanf("%d",&science);
scanf("%d",&math);
scanf("%d",&computer);
sum=hindi+english+science+math+computer;
printf("Sum of marks=%d",sum);
per=(float)sum/5;
printf("Percentage of marks=%f",per);
getch( );
}
Output:
Sum of marks=341
Percentage of marks=68.199997
PROGRAM NO. 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( )
printf("Enter Principle=");
scanf("%f",&p);
printf("Enter Rate=");
scanf("%f",&r);
printf("Enter Time=");
scanf("%f",&t);
si=(p*r*t)/100;
printf("Simple Interest=%f",si);
ci = a - p;
printf("\nCompound Interest=%f",ci);
getch( );
Output:
Enter Principle=100
Enter Rate=10
Enter Time=3
Simple Interest=30.000000
Compound Interest=33.100010
PROGRAM NO. 3
#include<stdio.h>
# include<conio.h>
void main()
float r,c,a,pi=3.14;
printf("Enter radius=");
scanf("%f",&r);
c=2*pi*r;
a=pi*r*r;
getch ( );
Output:
Enter radius=7
Circumference of a circle=43.960003
Area of a circle=153.860016
PROGRAM NO.4
#include<stdio.h>
# include<conio.h>
void main()
float c,f;
printf("Enter Centigrade=");
scanf("%f",&c);
f=(9*c)/5+32;
printf("Fahrenheit=%f",f);
getch( );
Output:
Enter Centigrade=36
Fahrenheit=96.800003
PROGRAM NO. 5
#include<stdio.h>
# include<conio.h>
void main( )
int a,b,temp;
printf("Enter a=");
scanf("%d",&a);
printf("Enter b=");
scanf("%d",&b);
temp=a;
a=b;
b=temp;
printf("\n a=%d",a);
printf("\n b=%d",b);
getch( );
Output:
Enter a=10
Enter b=20
After swapping
a=20 b=10
PROGRAM NO. 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 a=");
scanf("%d",&a);
printf("Enter b=");
scanf("%d",&b);
if(a==b)
else
getch( );
Output:
Enter a=10
#include<stdio.h>
# include<conio.h>
void main( )
int a,b,c;
printf("Enter a=");
scanf("%d",&a);
printf("Enter b=");
scanf("%d",&b);
printf("Enter c=");
scanf("%d",&c);
if(a>b)
if(a>c)
printf("\n a is greatest.");
else
printf("\n c is greatest.");
}
else
if(b>c)
printf("\n b is greatest.");
else
printf("\n c is greatest.");
getch( );
Output:
Enter a=10
Enter b=15
Enter c=12
b is greatest.
PROGRAM NO. 8
#include<stdio.h>
# include<conio.h>
void main( )
int n;
printf("Enter a number=");
scanf("%d",&n);
if(n%2==0)
else
Output:
Enter a number=15
n is odd number.
PROGRAM NO. 9
#include<stdio.h>
# include<conio.h>
void main( )
int year;
printf("Enter a number=");
scanf("%d",&year);
if((year%4==0||year%400==0)&&year%100!=0)
else
getch( );
Output:
Enter a number=1600
WAP that accepts marks of five subjects and finds percentage and
prints grades according to the following criteria:
80-90%—————————-Print „B‟
60-80%—————————Print „C‟
#include<stdio.h>
# include<conio.h>
void main( )
float per;
scanf("%d",&hindi);
scanf("%d",&english);
scanf("%d",&science);
scanf("%d",&math);
scanf("%d",&computer);
sum=hindi+english+science+math+computer;
printf("\n Sum of marks=%d",sum);
per=(float)sum/5;
if(per>=90&&per<=100)
else if(per>=80&&per<90)
else if(per>=60&&per<80)
else if(per<60)
getch( );
Output:
Sum of marks=342
Percentage of marks=68.400002
Grade C
PROGRAM NO. 11
WAP that takes two operands and one operator from the user and
perform the operation and prints the result by using Switch
statement.
#include<stdio.h>
# include<conio.h>
void main( )
int choice,a,b;
printf("1- Add:\n");
printf("2- Sub:\n");
printf("3- Mul:\n");
printf("4- Div:\n");
printf("5- Mod:\n");
scanf("%d",&a);
scanf("%d",&b);
scanf("%d",&choice);
switch(choice)
case 1:
case 2:
break;
case 3:
break;
case 4:
break;
case 5:
break;
default:
printf("Wronf choice.");
Output:
1- Add:
2- Sub:
3- Mul:
4- Div:
5- Mod:
Enter number a=7
Mul of a and b 35
PROGRAM NO. 12
#include <stdio.h>
# include<conio.h>
void main( )
scanf("%d", &n);
scanf("%d", &value);
getch( );
OUTPUT:
Enter 4 integers
2
3
#include <stdio.h>
# include<conio.h>
void main( )
int n, i;
scanf("%d", &n);
if (n < 0)
else {
fact *= i;
getch( );
Output:
Enter an integer: 10
Factorial of 10 = 3628800
PROGRAM NO. 14
#include<stdio.h>
# include<conio.h>
void main( )
int i,n,sumEven=0,sumOdd=0;
printf("Enter number=");
scanf("%d",&n);
for(i=1;i<=n;i++)
if(i%2==0)
sumEven=sumEven+i;
else
sumOdd=sumOdd+i;
getch ( );
}
Output: Enter number=10
#include<stdio.h>
# include<conio.h>
void main( )
int i,n,a=0,b=1,c;
printf("Enter number=");
scanf("%d",&n);
for(i=1;i<=n;i++)
printf("%d\n",a);
c=a+b;
a=b;
b=c;
getch ( );
3
5
13
PROGRAM NO. 16
#include<stdio.h>
# include<conio.h>
void main( )
int i,n,prime=1;
printf("Enter number=");
scanf("%d",&n);
for(i=2;i<=n/2;i++)
if(n%i==0)
prime=0;
break;
if(prime==1)
printf("Prime Number");
else
getch( );
Output:
Enter number=29
Prime Number
PROGRAM NO. 17
#include<stdio.h>
# include<conio.h>
void main( )
int n,r,sumDigits=0;
printf("Enter number=");
scanf("%d",&n);
while(n>0)
r=n%10;
sumDigits=sumDigits+r;
n=n/10;
printf("Sum of Digits=%d",sumDigits);
getch ( );
Output:
Enter number=12345
Sum of Digits=15
PROGRAM NO. 18
#include<stdio.h>
# include<conio.h>
void main()
int n,r,rev=0;
printf("Enter number=");
scanf("%d",&n);
while(n>0)
r=n%10;
rev=rev*10+r;
n=n/10;
printf("Reverse number=%d",rev);
getch ( );
Output:
Enter number=1234
Reverse number=4321
PROGRAM NO. 19
(1*1*1)+(5*5*5)+(3*3*3) = 153
#include<stdio.h>
# include<conio.h>
void main( )
int i=1,r,aNum=0,num;
for(i=1;i<=1000;i++)
num=i;
aNum=0;
while(num>0)
r=num%10;
aNum=aNum+r*r*r;
num=num/10;
if(i==aNum)
printf("Armstrong Number=%d\n",i);
}
}
getch( );
Output:
Armstrong Number=1
Armstrong Number=153,371
WAP to convert binary number into decimal number and vice versa.
#include<stdio.h>
#include<math.h>
# include<conio.h>
void main( )
int n,r,rev=0,p=0;
scanf("%d",&n);
while(n>0)
r=n%10;
if(r!=0)
rev= rev+(int)pow(2,p);
n=n/10;
p++;
printf("Decimal number=%d",rev);
getch( );
}
Output:
Decimal number=11
PROGRAM NO. 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 arr[100];
printf(“arr[i]=%d”,i);
getch( );
WAP that inputs two arrays and saves sum of corresponding elements
of these arrays in a third array and prints them.
#include<stdio.h>
# include<conio.h>
void main( )
int i,ar1[10],ar2[10],sum[10];
for(i=0;i<=9;i++)
printf("ar1[%d]=",i);
scanf("%d",&ar1[i]);
for(i=0;i<=9;i++)
printf("ar2[%d]=",i);
scanf("%d",&ar2[i]);
for(i=0;i<=9;i++)
sum[i]=ar1[i]+ar2[i];
printf("\nsum[%d]=%d",i,sum[i]);
}
getch( );
Output:
ar1[0]=1
ar1[1]=2
ar1[2]=3
ar1[3]=4
ar1[4]=5
ar1[5]=6
ar1[6]=7
ar1[7]=8
ar1[8]=9
ar1[9]=10
ar2[0]=11
ar2[1]=22
ar2[2]=33
ar2[3]=44
ar2[4]=55
ar2[5]=66
ar2[6]=77
ar2[7]=88
ar2[8]=99
ar2[9]=100
Sum of arrays:-
sum[0]=12
sum[1]=24
sum[2]=36
sum[3]=48
sum[4]=60
sum[5]=72
sum[6]=84
sum[7]=96
sum[8]=108
sum[9]=110
PROGRAM NO. 23
#include<stdio.h>
# include<conio.h>
void main( )
int i,ar[10],min,max;
printf("Enter array:-\n");
for(i=0;i<=9;i++)
printf("ar[%d]=",i);
scanf("%d",&ar[i]);
min=ar[0];
max=ar[0];
for(i=0;i<=9;i++)
min=ar[i];
max=ar[i];
}
printf("\nMin=%d",min);
printf("\nMax=%d",max);
getch ( );
Output:
Enter array:-
ar[0]=4
ar[1]=6
ar[2]=12
ar[3]=21
ar[4]=36
ar[5]=47
ar[6]=5
ar[7]=8
ar[8]=9
ar[9]=2
Min=2
Max=47
PROGRAM NO. 24
#include<stdio.h>
# include<conio.h>
void main( )
int i,ar[10],n,pos=-1;
printf("Enter array:-\n");
for(i=0;i<=9;i++)
printf("ar[%d]=",i);
scanf("%d",&ar[i]);
scanf("%d",&n);
for(i=0;i<=9;i++)
if(n==ar[i])
pos=i+1;
if(pos==-1)
{
else
printf("Position=%d",pos);
getch ( );
Output:
Enter array:-
ar[0]=15
ar[1]=24
ar[2]=65
ar[3]=45
ar[4]=78
ar[5]=34
ar[6]=20
ar[7]=74
ar[8]=49
ar[9]=39
Position=6
PROGRAM NO. 25
WAP to sort the elements of the array in ascending order using Bubble
Sort technique.
# include<stdio.h>
# include<conio.h>
void main( )
int i,j,ar[10],temp;
printf("Enter array:-\n");
for(i=0;i<=9;i++)
printf("ar[%d]=",i);
scanf("%d",&ar[i]);
for(i=0;i<=9;i++)
for(j=0;j<=9-i;j++)
if(ar[j]>ar[j+1])
temp=ar[j];
ar[j]=ar[j+1];
ar[j+1]=temp;
}
}
printf("Sorted array:-");
for(i=0;i<=9;i++)
printf("\n%d",ar[i]);
getch( );
Output:
Enter array:-
ar[0]=2
ar[1]=5
ar[2]=4
ar[3]=12
ar[4]=21
ar[5]=32
ar[6]=45
ar[7]=15
ar[8]=16
ar[9]=34
Sorted array:-
5
12
15
16
21
32
34
41
PROGRAM NO. 26
#include<stdio.h>
# include<conio.h>
void main( )
int i,j,k,m1[3][3],m2[3][3],mul[3][3];
for(i=0;i<=2;i++)
for(j=0;j<=2;j++)
scanf("%d",&m1[i][j]);
for(i=0;i<=2;i++)
for(j=0;j<=2;j++)
scanf("%d",&m2[i][j]);
for(i=0;i<=2;i++)
{
for(j=0;j<=2;j++)
mul[i][j]=0;
for(k=0;k<=2;k++)
mul[i][j]=mul[i][j]+(m1[i][k]*m2[k][j]);
printf("Multiplication of metrices:-\n");
for(i=0;i<=2;i++)
for(j=0;j<=2;j++)
printf("%d ",mul[i][j]);
printf("\n");
getch( );
Output:
2
3
Multiplication of metrices:-
21 17 39
55 36 82
45 23 57
PROGRAM NO. 27
#include<stdio.h>
# include<conio.h>
void main( )
int i,j,k,matrix[3][3],sum=0;
printf("Enter matrix:-\n");
for(i=0;i<=2;i++)
for(j=0;j<=2;j++)
scanf("%d",&matrix[i][j]);
printf("Matrix is:-\n");
for(i=0;i<=2;i++)
for(j=0;j<=2;j++)
printf("%d ",matrix[i][j]);
printf("\n");
}
for(i=0;i<=2;i++)
for(j=0;j<=2;j++)
if(i==j)
getch( );
Output:
Enter matrix:-
9
Matrix is:-
123
456
789
Sum of diagonal is = 15
PROGRAM NO. 28
#include<stdio.h>
# include<conio.h>
#include <string.h>
void main( )
char st[20]={'H', 'e', 'l', 'l', 'o', ' ', 'W', 'o', 'r', 'l','d', '\0'};
strcat(wd1,wd2);
char st2[20];
strcpy(st2,st1);
getch ( );
Output:
#include<stdio.h>
# include<conio.h>
int main( )
int a = 10;
int b = 20;
swap(&a,&b);
int temp;
temp = *a;
*a=*b;
*b=temp;
getch( );
Output:
WAP to compare the contents of two files and determine whether they
are same or not.
#include <stdio.h>
#include <string.h>
FILE *fp1 ;
FILE *fp2 ;
int cnt1 = 0;
int cnt2 = 0;
int flg = 0;
printf("Insufficient Arguments!!!\n");
return -1;
fp1 = fopen(argv[1],"r");
return -1;
}
// move file pointer to end and get total number of bytes
fseek(fp1,0,SEEK_END);
cnt1 = ftell(fp1);
fp2 = fopen(argv[2],"r");
return -1;
fseek(fp2,0,SEEK_END);
cnt2 = ftell(fp2);
fseek(fp1,0,SEEK_SET);
fseek(fp2,0,SEEK_SET);
else
while( ! feof(fp1) )
{
flg = 1;
break;
fclose(fp1);
fclose(fp2);
return 0;
Output
WAP to check whether a given word exists in a file or not. If yes then
find the number of times it occurs.
this is a boy
i am good
#include<stdio.h>
void main()
FILE* filePointer;
int wordExist=0;
char search[100];
scanf("%s",search);
char line[bufferLength];
if (ptr != NULL)
wordExist=1;
break;
}
fclose(filePointer);
if (wordExist==1)
printf("Word exists.");
else
getch( );
Output:
Word exists.