0% found this document useful (0 votes)
2 views36 pages

PPS Lab Manual

The document contains a series of programming experiments in C, each with a specific objective and corresponding code. The experiments cover various topics such as calculating sums, percentages, simple and compound interest, temperature conversion, and more. Each experiment includes sample output demonstrating the functionality of the code.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views36 pages

PPS Lab Manual

The document contains a series of programming experiments in C, each with a specific objective and corresponding code. The experiments cover various topics such as calculating sums, percentages, simple and compound interest, temperature conversion, and more. Each experiment includes sample output demonstrating the functionality of the code.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 36

EXPERIMENT # 1

OBJECTIVE: WAP that accepts the marks of 5 subjects and find the sum and percentage
marks obtained by student.

PROGRAM CODE:

//WAP for sum of Entered five subjects & their percentage //


#include<stdio.h>
#include<conio.h>
void main()
{
int s1,s2,s3,s4,s5,total;
float per;
clrscr();
printf("enter the marks of subject1\n");
scanf("%d",&s1);
printf("enter the marks of subject2\n");
scanf("%d",&s2);
printf("enter the marks of subject3\n");
scanf("%d",&s3);
printf("enter the marks of subject4\n");
scanf("%d",&s4);
printf("enter the marks of subject5\n");
scanf("%d",&s5);
total=s1+s2+s3+s4+s5;
per=total/5;
printf("total of the marks=%d\n",total);
printf("Percentage of the Marks=%f",per);
getch()
}
Output:

Enter the marks of subject1:


67
Enter the marks of subject2:
89
Enter the marks of subject3:
90
Enter the marks of subject4:
80
Enter the marks of subject1:
68

Total of the Marks=394


Percentage of the Marks=78.000000

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

the Formula C/5=(F-32)/9.

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:-

Enter the Temperature in centigrade:36

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:-

Enter the value of a=9

Enter the value of b=6

New value of a=6

New value of b=9

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();

printf("Enter two numbers:");

scanf("%d%d",&x,&y);

if(x==y)

printf("Entered numbers are equal");

else

printf("Entered numbers are not equal");

getch();

Output:-

Enter two numbers:45

45

Entered numbers are equal

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:

Enter Three Numbers: 5

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();

printf("enter the any number:");

scanf("%d",&num);

if(num%2==0)

printf("Entered Number is Even");

else

printf("Entered number is odd");

getch();

Output:-

Enter the any Number:89

Entered Number is odd

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();

printf("enter the year:");

scanf("%d",&year);

if (((year % 4 == 0) && (year%100!= 0))||(year%400 == 0))

printf("%d is a leap year", year);

else

printf("%d is not a leap year", year);

getch();

Output:-

Enter the year:2024

2024 is a leap year

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();

printf("enter the marks of subject1\n");

scanf("%d",&s1);

printf("enter the marks of subject2\n");

scanf("%d",&s2);

printf("enter the marks of subject3\n");

scanf("%d",&s3);

printf("enter the marks of subject4\n");

scanf("%d",&s4);

printf("enter the marks of subject5\n");

scanf("%d",&s5);

tot=s1+s2+s3+s4+s5;

per=tot/5;

printf("Total of the marks=%d\n",tot);

printf("Percentage of the Marks=%f\n",per);

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:-

Enter the marks of subject1: 89

Enter the marks of subject2: 78

Enter the marks of subject3: 67

Enter the marks of subject4: 90

Enter the marks of subject1: 97

Total of the marks= 421

Percentage of the Marks= 84.000000

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;

int x,y,sum, sub,mult,div;

clrscr();

printf(".................\n");

printf("1 Addition\n");

printf("2 subtraction\n");

printf("3 multiplication\n");

printf("4 Division\n");

printf("Enter the choice\n");

scanf("%d",&code);

switch(choice)

case 1: printf("enter two numbers");

scanf("%d%d",&x,&y);

sum=x+y;

printf("addition of %d & %d =%d",x,y,sum);

break;

case 2: printf("enter two numbers");

scanf("%d%d",&x,&y);

sub=x-y;
printf("Subtraction of %d & %d =%d",x,y,sub);

break;

case 3: printf("enter two numbers");

scanf("%d%d",&x,&y);

mult=x*y;

printf("multiplication of %d & %d =%d",x,y,mult);

break;

case 4: printf("enter two numbers");

scanf("%d%d",&x,&y);

div=x/y;

printf("Division of %d & %d =%d",x,y,div);

break;

default:printf("error inthe code");

getch();

Output:-

1 Addition
2 Subtraction
3 Multiplication
4 Division

Enter the choice


3
Enter two numbers:12
9
Multiplication of 12 & 9 =108

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();

printf("Enter the no. where do you want to sum:");

scanf("%d",&n);

i=1;

while(i<=n)

sum=sum+i;

i++;

printf("Total of the 1 to %d=%d",n,sum);

getch();

Output:-

Enter the no. where do you want to sum:10

Total of the 1 to 10=55

EXPERIMENT # 13

OBJECTIVE: WAP to find the factorial of given numbers.


PROGRAM CODE:
#include<stdio.h>

#include<conio.h>

void main()

long int fact=1,n,i;

clrscr();

printf("Enter any no for Factorial:");

scanf("%ld",&n);

for(i=1;i<=n;i++)

fact=fact*i;

printf("Factoril of given no is:%ld",fact);

getch();

Output:-

Enter any no for Factorial:5

Factoril of given no is:120

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();

printf("enter the value of n:");

scanf("%d",&n);

for(i=1;i<=n;i++)

if(i%2==0)

s1=s1+i;

else

s2=s2+i;

printf("sum of even no=%d\n",s1);

printf("sun of odd no=%d",s2);

getch();

Output:-

Enter the value of n:10

Sum of even no=30

Sun of odd no=25

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();

printf("enter the term:");

scanf("%d",&n);

printf("fibonacci series is:\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();

printf("Enter any four digit numbers:");

scanf("%d",&n);

while(n>0)

d=n%10;

sum=sum+d;

n=n/10;

printf("sum of digits=%d",sum);

getch();

Output:-

Enter any four digit number: 4567

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();

printf("Enter any four digit numbers:");

scanf("%d",&n);

printf("reverse of the number is:");

while(n>0)

d=n%10;

rev=d;

n=n/10;

printf("%d",rev);

getch();

Output:-

Enter any four digit number: 6895

Reverse of the number is: 5986

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;

printf("Enter a decimal number: ");


scanf("%d", &n);

// convert to binary using the convert() function


bin = convert(n);

printf("%d in decimal = %lld in binary", n, bin);

return 0;
}

// function to convert decimal to binary


long long convert(int n) {
long long bin = 0;
int rem, i = 1;
while (n != 0) {
rem = n % 2;
n /= 2;
bin += rem * i;
i *= 10;
}
return bin;
}

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);

printf("the minimum element is %d: ",min);


getch();
}

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

Result of Matrix Multiplication:


35 42
61 73

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");
}

//To add diagonal elements


for(i=0;i<row;i++)
{
for(j=0;j<col;j++)
{

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

The sum of diagonal elements of a square matrix = 9

You might also like