PPS Lab Manual
PPS Lab Manual
OBJECTIVE: WAP that accepts the marks of 5 subjects and find the sum and percentage
marks obtained by student.
PROGRAM CODE:
EXPERIMENT # 2
OBJECTIVE: WAP that calculate the simple Interest and compound interest. The principal
Amount Rate of Interest and time are entered through Keyboard.
PROGRAM CODE:
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
float p,r,t,si;
float ci=0;
clrscr();
printf("Enter the principle amount\n");
scanf("%f",&p);
printf("Enter the rate of intrest\n");
scanf("%f",&r);
printf("Enter the time:\n");
scanf("%f",&t);
si=(p*r*t)/100;
ci=p*pow((1+r/100),t)-p;
printf("Simple Intrest=%f\n",si);
printf("Compound Intrest=%f",ci);
getch();
}
Output:
Enter the principle amount:
5000
Enter the rate of interest:
3
Enter the time:
5
Simple Intrest =750.000000
Compound Intrest=796.370361
EXPERIMENT # 3
OBJECTIVE: WAP to calculate area and circumference of circle.
PROGRAM CODE:
#include<stdio.h>
#include<conio.h>
void main()
{
float a,r,pai=3.14,c;
clrscr();
printf("Enter the rarius of circle:");
scanf("%f",&r);
a=pai*r*r;
c=2*pai*r;
printf("Area of circle=%f\n",a);
printf("Circumference of the circle=%f",c);
getch();
}
Output:
Enter the radius of circle: 5
Area of circle=78.500000
Circumference of the circle=31.400002
EXPERIMENT # 4
OBJECTIVE: WAP that accept temperature in Centigrade and converts into Fahrenheit using
PROGRAM CODE:
#include<stdio.h>
#include<conio.h>
void main()
{
int C,F;
clrscr();
printf("Enter the Temperature in centigrade:");
scanf("%d",&C);
F=1.8*C+32;
printf("Temperature in Fahrenheit=%d",F);
getch();
}
Output:-
Temperature in Fahrenheit=96.800003
EXPERIMENT # 5
OBJECTIVE: WAP that swaps values of two variables using a third variable.
PROGRAM CODE:
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,temp;
clrscr();
printf("Enter the value of a=");
scanf("%d",&a);
printf("Enter the value of b=");
scanf("%d",&b);
temp=a;
a=b;
b=temp;
printf("New value of a=%d\n",a);
printf("New value of b=%d",b);
getch();
}
Output:-
EXPERIMENT # 6
OBJECTIVE: WAP that checks whether the two numbers entered by the user are equal or not.
PROGRAM CODE:
#include<stdio.h>
#include<conio.h>
void main()
int x,y:
clrscr();
scanf("%d%d",&x,&y);
if(x==y)
else
getch();
Output:-
45
EXPERIMENT # 7
OBJECTIVE: WAP to find the greatest of three numbers.
PROGRAM CODE:
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c;
clrscr();
printf("Enter three numbers:");
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");
}
if((c>=a)&&(c>=b))
{
printf("c is greater");
}
getch();
}
Output:
24
C is greter
EXPERIMENT # 8
OBJECTIVE: WAP that finds where the given number is even or odd.
PROGRAM CODE:
#include<stdio.h>
#include<conio.h>
void main()
int num;
clrscr();
scanf("%d",&num);
if(num%2==0)
else
getch();
Output:-
EXPERIMENT # 9
OBJECTIVE: WAP that tells whether given year is leap year or not.
PROGRAM CODE:
#include<stdio.h>
#include<conio.h>
void main()
int year;
clrscr();
scanf("%d",&year);
else
getch();
Output:-
EXPERIMENT # 10
OBJECTIVE: WAP that accept the marks of five subjects and find the percentage and print
the grades according to the following criteria.
Between 90-100%................ Print ‘A’
80-90%..................................Print ‘B’
60-80…………………………………..Print ‘C’
Below 60%.............................Print ‘D’
PROGRAM CODE:
#include<stdio.h>
#include<conio.h>
void main()
int s1,s2,s3,s4,s5,tot;
float per;
clrscr();
scanf("%d",&s1);
scanf("%d",&s2);
scanf("%d",&s3);
scanf("%d",&s4);
scanf("%d",&s5);
tot=s1+s2+s3+s4+s5;
per=tot/5;
if((per>90)&&(per<=100))
{
printf("Grade 'A'");
if((per>80)&&(per<=90))
printf("Grade B");
if((per>60)&&(per<=80))
printf("Grade C");
if(per<60)
printf("Grade D");
getch();
Output:-
Grade B
EXPERIMENT # 11
OBJECTIVE: WAP that takes two operands and one operator from the user performs the
operation and print the result by using Switch operation.
PROGRAM CODE:
#include<stdio.h>
#include<conio.h>
void main()
int choice;
clrscr();
printf(".................\n");
printf("1 Addition\n");
printf("2 subtraction\n");
printf("3 multiplication\n");
printf("4 Division\n");
scanf("%d",&code);
switch(choice)
scanf("%d%d",&x,&y);
sum=x+y;
break;
scanf("%d%d",&x,&y);
sub=x-y;
printf("Subtraction of %d & %d =%d",x,y,sub);
break;
scanf("%d%d",&x,&y);
mult=x*y;
break;
scanf("%d%d",&x,&y);
div=x/y;
break;
getch();
Output:-
1 Addition
2 Subtraction
3 Multiplication
4 Division
EXPERIMENT # 12
OBJECTIVE: WAP to print the sum of all numbers up to a given number.
PROGRAM CODE:
#include<stdio.h>
#include<conio.h>
void main()
int i,n,sum=0;
clrscr();
scanf("%d",&n);
i=1;
while(i<=n)
sum=sum+i;
i++;
getch();
Output:-
EXPERIMENT # 13
#include<conio.h>
void main()
clrscr();
scanf("%ld",&n);
for(i=1;i<=n;i++)
fact=fact*i;
getch();
Output:-
EXPERIMENT # 14
OBJECTIVE: WAP to print the sum of even and odd numbers from 1 to N numbers.
PROGRAM CODE:
#include<stdio.h>
#include<conio.h>
void main()
int n,i,s1=0,s2=0;
clrscr();
scanf("%d",&n);
for(i=1;i<=n;i++)
if(i%2==0)
s1=s1+i;
else
s2=s2+i;
getch();
Output:-
EXPERIMENT # 15
OBJECTIVE: WAP to print the Fibonacci Series.
PROGRAM CODE:
#include<stdio.h>
#include<conio.h>
void main()
int a=0,b=1,c=0,i,n;
clrscr();
scanf("%d",&n);
printf("%d\n",a);
for(i=1;i<=n-1;i++)
{
a=b;
b=c;
c=a+b;
printf("%d\n",c);
getch();
Output:-
enter the term:8
0
1
1
2
3
5
8
13
EXPERIMENT # 16
OBJECTIVE: WAP to check whether the entered number is prime or not.
PROGRAM CODE:
#include<stdio.h>
#include<conio.h>
void main()
{
int i,n,c=0;
printf("Enter any number:");
scanf("%d",&n);
for(i=;i<=n;i++)
{
if(n%i==0)
{
c++;
}
}
if(c==2)
{
printf("Entered no is prime number");
}
else
{
printf("Entered no is not prime number");
}
getch();
}
Output:-
Enter any number: 7
Entered no is prime number
EXPERIMENT # 17
OBJECTIVE: WAP to find the sum of digits of the entered number.
PROGRAM CODE:
#include<stdio.h>
#include<conio.h>
void main()
int n,rev,d,sum=0;
clrscr();
scanf("%d",&n);
while(n>0)
d=n%10;
sum=sum+d;
n=n/10;
printf("sum of digits=%d",sum);
getch();
Output:-
Sum of digits=22
EXPERIMENT # 18
OBJECTIVE: WAP to find the reverse of the number.
PROGRAM CODE:
#include<stdio.h>
#include<conio.h>
void main()
int n,rev,d;
clrscr();
scanf("%d",&n);
while(n>0)
d=n%10;
rev=d;
n=n/10;
printf("%d",rev);
getch();
Output:-
EXPERIMENT # 19
OBJECTIVE: WAP to print Armstrong Armstrong number from 1 to 500.
PROGRAM CODE:
#include<stdio.h>
#include<math.h>
#include<conio.h>
void main()
{
int n,sum,i,t,a;
clrscr();
printf("\n\n\nThe Armstrong numbers in between 1 to 500 are : \n\n\n");
for(i=1;i<=500;i++)
{
t = i; // as we need to retain the original number
sum = 0;
while(t != 0)
{
a = t%10;
sum += a*a*a;
t = t/10;
}
if(sum == i)
printf("\n\t\t\t%d", i);
}
getch();
}
Output:
The Armstrong numbers in between 1 to 500 are :
1
153
370
371
407
EXPERIMENT # 20
OBJECTIVE: WAP to convert binary number into decimal number and vive versa.
PROGRAM CODE:
#include <stdio.h>
#include <math.h>
int convert(long long);
int main() {
long long n;
printf("Enter a binary number: ");
scanf("%lld", &n);
printf("%lld in binary = %d in decimal", n, convert(n));
return 0;
}
int convert(long long n) {
int dec = 0, i = 0, rem;
while (n != 0) {
rem = n % 10;
n /= 10;
dec += rem * pow(2, i);
++i;
}
return dec;
}
#include <stdio.h>
#include <math.h>
// function prototype
long long convert(int);
int main() {
int n;
long long bin;
return 0;
}
EXPERIMENT # 21
OBJECTIVE: WAP that simply takes elements of the array from the user and finds the sum
of these Elements.
PROGRAM CODE:
#include<stdio.h>
#include<conio.h>
void main()
{
int a[100],i,n,sum=0;
printf("Enter size of the array : ");
scanf("%d",&n);
printf("Enter elements in array : ");
for(i=0; i<n; i++)
{
scanf("%d",&a[i]);
}
for(i=0; i<n; i++)
{
sum=sum+a[i];
}
printf("sum of array is : %d",sum);
getch();
}
Output:
Enter the size of the array:5
Enter elements in array:3
4
5
6
7
Sum of array is : 25
EXPERIMENT # 22
OBJECTIVE: WAP that inputs two arrays and saves sum of corresponding elements of these
arrays in a third array and prints them.
PROGRAM CODE:
#include<stdio.h>
#include<conio.h>
void main()
{
int a[10],b[10],sum[10],I,n;
clrscr();
printf(" Enter the size of Array A and B\n");
scanf("%d" , &n);
printf(" Enter the elements of Array A\n");
for(i=0 ; i<n ; i++)
{
scanf("%d" , &a[i]);
}
printf(" Enter the elements of Array B\n");
for(i=0 ; i<n ; i++)
{
scanf("%d" , &b[i]);
}
for(i=0 ; i<n ; i++)
sum[i] = a[i] + b[i];
printf(" Sum of elements of A and B\n");
for(i=0;i<n;i++)
{
printf("%d\n" , sum[i] );
}
getch();
}
Output:
Enter the size of the array A and B: 4
Enter elements of array A:
1
2
3
4
Enter the element of array B:
5
6
7
8
Sum of the element of A and B
6
8
10
12
EXPERIMENT # 23
OBJECTIVE: WAP to find the minimum and maximum element of the array.
PROGRAM CODE:
#include<stdio.h>
#include<conio.h>
void main()
{
int a[10],i,n,max,min;
clrscr();
printf("enter the size of array: ");
scanf("%d",&n);
printf("enter n elements into array: ");
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
max=a[0];
for(i=0;i<n;i++)
{
if(a[i]>max)
{
max=a[i];
}
}
min=a[0];
for(i=0;i<n;i++)
{
if(a[i]<min){
min=a[i];
}
}
printf("the maximum element is %d: \n",max);
Output:
enter the size of array:5
Enter the element in to the array:
2
45
65
78
34
The maximum element is:78
The minimum element is:2
EXPERIMENT # 24
OBJECTIVE: WAP to search an element in an array using Linear Search.
PROGRAM CODE:
#include<stdio.h>
#include<conio.h>
void main()
{
int a[100], search, i, n;
clrscr();
printf("Enter the number of elements in array:\n");
scanf("%d",&n);
printf("Enter %d numbers\n", n);
for ( i = 0 ; i < n ; i++ )
scanf("%d",&a[i]);
printf("Enter the number to search:\n");
scanf("%d",&search);
for ( i = 0 ; i < n ; i++ )
{
if ( a[i] == search ) /* if required element found */
{
printf("%d is present at location %d.\n", search, i+1);
break;
}
}
if ( i == n )
printf("%d is not present in array.\n", search);
getch();
}
Output:
Enter the number of elements in array:5
Enter five numbers:3 4 5 6 7
Enter the number to search:6
6 is present at location 4
EXPERIMENT # 25
OBJECTIVE: WAP to Short the elements of the array in ascending order using Bubble short
technique.
PROGRAM CODE:
#include <stdio.h>
#include <conio.h>
#define MAXSIZE 10
void main()
{
int array[MAXSIZE];
int i, j, num, temp;
clrscr();
printf("Enter the value of num \n");
scanf("%d", &num);
printf("Enter the elements one by one \n");
for (i = 0; i < num; i++)
{
scanf("%d", &array[i]);
}
printf("Input array is \n");
for (i = 0; i < num; i++)
{
printf("%d\n", array[i]);
}
/* Bubble sorting begins */
for (i = 0; i < num; i++)
{
for (j = 0; j < (num - i - 1); j++)
{
if (array[j] > array[j + 1])
{
temp = array[j];
array[j] = array[j + 1];
array[j + 1] = temp;
}
}
}
printf("Sorted array is...\n");
for (i = 0; i < num; i++)
{
printf("%d\n", array[i]);
}
getch();
}
Output:
Enter the value of Num: 5
Enter the elements one by one:
6
4
8
3
9
Input array is:
6
4
8
3
9
Sorted array is:
3
4
6
8
9
EXPERIMENT # 26
OBJECTIVE: WAP to add and multiply two matrices of order nxn.
PROGRAM CODE:
#include<stdio.h>
#include<conio.h>
void main()
{
int a[3][3], b[3][3], c[3][3]={0}, d[3][3]={0};
int i,j,k,m,n,p,q;
clrscr();
printf("Enter no. of rows and columns in matrix A: ");
scanf("%d%d",&m,&n);
printf("Enter no. of rows and columns in matrix B: ");
scanf("%d%d",&p,&q);
if(m!=p || n!=q)
{
printf("Matrix Addition is not possible");
return;
}
else if(n!=p)
{
printf("Matrix Multiplication is not possible");
return;
}
else
{
printf("Enter elements of matrix A: ");
for(i=0;i<m;i++)
for(j=0;j<n;j++)
scanf("%d", &a[i][j]);
printf("Enter elements of matrix B: ");
for(i=0;i<p;i++)
for(j=0;j<q;j++)
scanf("%d", &b[i][j]);
//Matrix Addition
for(i=0;i<m;i++)
for(j=0;j<n;j++)
c[i][j] = a[i][j] + b[i][j];
printf("\nResult of Matirx Addition:\n");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
printf("%d ", c[i][j]);
printf("\n");
}
//Matrix Multiplication
for(i=0;i<m;i++)
for(j=0;j<q;j++)
for(k=0;k<p;k++)
d[i][j] += a[i][k]*b[k][j];
printf("\nResult of Matirx Multiplication:\n");
for(i=0;i<m;i++)
{
for(j=0;j<q;j++)
printf("%d ", d[i][j]);
printf("\n");
}
}
getch();
}
Output:
Enter no. of rows and columns in matrix A:
2
2
Enter no. of rows and columns in matrix B:
2
2
Enter elements of matrix A:
3
4
5
7
Enter elements of matrix B:
1
2
8
9
Result of Matrix Addition:
4 6
13 16
EXPERIMENT # 27
OBJECTIVE: WAP that finds the sum of diagonal element of mxn matrix.
PROGRAM CODE:
#include<stdio.h>
#include<conio.h>
void main()
{
int mat[12][12];
int i,j,row,col,sum=0;
clrscr();
printf("Enter the number of rows and columns for matrix:\n");
scanf("%d%d",&row,&col);
printf("Enter the elements of the matrix\n");
for(i=0;i<row;i++)
{
for(j=0;j<col;j++)
{
scanf("%d",&mat[i][j]);
}
}
printf("The matrix\n");
for(i=0;i<row;i++)
{
for(j=0;j<col;j++)
{
printf("%d\t",mat[i][j]);
}
printf("\n");
}
if(i==j)
{
sum=sum+mat[i][j];
}
}
}
printf("The sum of diagonal elements of a square matrix = %d\n",sum);
getch();
}
Output:
Enter the number of rows and columns for matrix:3
3
Enter the elements of the matrix:2
3
4
5
6
7
8
9
1
The Matrix is:
2 3 4
5 6 7
8 9 1