PPS LAB PROG File
PPS LAB PROG File
PROGRAM NO. :- 1
Area=√(s(s-a)(s-b)(s-c))
where
s=(a+b+c)/2
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
int a,b,c;
float s,area;
printf("Enter the sides of the tringle");
scanf("%d%d%d",&a,&b,&c);
s=(a+b+c)/2;
area=sqrt(s*(s-a)*(s-b)*(s-c));
printf("Area of tringle is %f",area);
getch();
}
LAB-1
PROGRAM NO. :- 2
The basic salary of an employee is input through the keyboard. The DA
(Dearness Allowance) is 25% of the basic salary while HRA(House
Rant Allowance) is 15% of the basic salary. The PF (Provident Fund) is
deducted at the rate of 10% of the Gross Salary (GS=BS+DA+HRA).
Write a program to calculate the Net Salary (GS-PF).
#include<stdio.h>
#include<conio.h>
void main()
{
float bs,da,hra,gs,pf,NetS;
printf("Enter the basic salary");
scanf("%f",&bs);
da=(bs*25)/100;
hra=(bs*15)/100;
gs=bs+da+hra;
pf=(gs*10)/100;
NetS=gs-pf;
printf("Net salary of an employee=%f",NetS);
getch();
}
LAB-2
PROGRAM NO. :-3
Write a program to find the largest of three numbers.
#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("%d is largest",a);
}
else if(b>a&&b>c)
{
printf("%d is largest",b);
}
else
{
printf("%d is largest",c);
}
getch();
}
LAB-2
PROGRAM NO. :- 4
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c;
char op;
float div;
printf("Enter the expresion");
scanf("%d%c%d",&a,&op,&b);
if(op=='+')
{
c=a+b;
printf("Addition=%d",c);
}
else if(op=='-')
{
c=a-b;
printf("Subtraction=%d",c);
}
else if(op=='*')
{
c=a*b;
printf("Multiplication=%d",c);
}
else if(op=='/')
{
div=a/b;
printf("Quotient =%f",div);
}
else if(op=='%')
{
c=a%b;
printf("Remainder =%d",c);
}
else
{
printf("Invalid Input");
}
getch();
}
LAB-3
PROGRAM NO. :- 5
#include<stdio.h>
#include<conio.h>
void main()
{
int i,n,n1=0,n2=1,n3;
printf("Enter the value of n :");
scanf("%d",&n);
printf("%d %d ",n1,n2);
for(i=2;i<n;i++)
{
n3=n1+n2;
printf("%d ",n3);
n1=n2;
n2=n3;
}
getch();
}
LAB-3
PROGRAM NO. :- 6
#include<stdio.h>
#include<conio.h>
void main()
{
int n,d,sum=0,temp;
clrscr();
printf("Enter the number");
scanf("%d",&n);
temp=n;
while(n>0)
{
d=n%10;
sum=sum+d*d*d;
n=n/10;
}
if(temp==sum)
{
printf("the given number is amstrong");
}
else
{
printf("the given number is not amstrong");
}
getch();
}
LAB-4
#include<stdio.h>
#include<conio.h>
void main()
{
int n,i;
clrscr();
printf("Enter the number :\n");
scanf("%d",&n);
for(i=2;i<=n;i++)
{
if(n%i==0)
{
break;
}
}
if(i==n)
{
printf("the given number is prime");
}
else
{
printf("the given number is not prime");
}
getch();
}
LAB-4
PROGRAM NO. :-8
#include<stdio.h>
#include<conio.h>
void main()
{
int n,d,sum=0,temp;
clrscr();
printf("Enter the number :-\n");
scanf("%d",&n);
temp=n;
while(n>0)
{
d=n%10;
sum=sum*10+d;
n=n/10;
}
if(temp==sum)
{
printf("The given number is Palindrom");
}
else
{
printf("The given number is not Palindrom");
}
getch();
}
LAB-5
#include<stdio.h>
#include<conio.h>
int factorial(int a);
void main()
{
int n,fact;
clrscr();
printf("Enter the number\n");
scanf("%d",&n);
fact=factorial(n);
printf("Factorial of %d is =%d",n,fact);
getch();
}
int factorial(int a)
{
if(a==0)
{
return 1;
}
else
{
return a*factorial(a-1);
}
}
LAB-5
PROGRAM NO. :-10
#include<stdio.h>
#include<conio.h>
void swap(int x, int y);
void main()
{
int a,b;
clrscr();
printf("Enter two values to swap :- ");
scanf("%d%d",&a,&b);
printf("Before swaping:- a=%d \t b=%d",a,b);
swap(a,b);
getch();
}
void swap( int x, int y)
{
int z;
z=x;
x=y;
y=z;
printf("\nAfter swaping:- a=%d \t b=%d",x,y);
}
b) Call by reference
#include<stdio.h>
#include<conio.h>
void swap(int *x, int *y);
void main()
{
int a,b;
clrscr();
printf("Enter two values to swap :- ");
scanf("%d%d",&a,&b);
printf("Before swaping:- a=%d \t b=%d",a,b);
swap(&a,&b);
getch();
}
void swap( int *x, int *y)
{
int z;
z=*x;
*x=*y;
*y=z;
printf("\nAfter swaping :- a=%d \t b=%d",*x,*y);
}
LAB-6
PROGRAM NO. :-11
#include<stdio.h>
#include<conio.h>
void main()
{
int a[3][3],i,j,sum=0;
clrscr();
printf("Enter a 3*3 square matrix :-\n");
for(i=0;i<3;i++)
{
for(j=0; j<3; j++)
{
scanf("%d",&a[i][j]);
}
}
for(i=0;i<3;i++)
{
for(j=0; j<3; j++)
{
if(i==j)
{
sum=sum+a[i][j];
}
}
}
printf("sum of diagonal is =%d",sum);
getch();
}
LAB-6
PROGRAM NO. :-12
Write a program to print the multiplication of two
3*3 square matrix.
#include<stdio.h>
#include<conio.h>
void main()
{
int a[3][3],b[3][3],c[3][3],i,j,k;
clrscr();
printf("Enter matrix A:-\n");
for(i=0;i<3;i++)
{
for(j=0; j<3; j++)
{
scanf("%d",&a[i][j]);
}
}
printf("Enter matrix B:-\n");
for(i=0;i<3;i++)
{
for(j=0; j<3; j++)
{
scanf("%d",&b[i][j]);
}
}
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
c[i][j]=0;
for(k=0;k<3;k++)
{
c[i][j]=c[i][j]+a[i][k]*b[k][j];
}
}
}
printf("Multiplication of matrix A and B is :-");
for(i=0;i<3;i++)
{
printf("\n");
for(j=0;j<3;j++)
{
printf("%d ",c[i][j]);
}
}
getch();
}
LAB-7
PROGRAM NO. :-13
#include<string.h>
#include<stdio.h>
#include<conio.h>
void main()
{
char a[10];
clrscr();
printf("Enter a String\n");
gets(a);
printf("Length of String=%d",strlen(a));
printf("\nReverse String is :-");
puts(strrev(a));
getch();
}
LAB-7
PROGRAM NO. :- 14
#include<stdio.h>
#include<conio.h>
void main()
{
int a[2][3],b[3][2],i,j;
clrscr();
printf("Enter a Matrix\n");
for(i=0;i<2;i++)
{
for(j=0;j<3;j++)
{
scanf("%d",&a[i][j]);
}
}
printf("Matrix's Transpose is :-\n");
for(i=0;i<3;i++)
{
for(j=0;j<2;j++)
{
printf("%d ",b[i][j]=a[j][i]);
}
printf("\n");
}
getch();
}
LAB-8
PROGRAM NO. :-15
#include<stdio.h>
#include<conio.h>
void main()
{
struct data
{
int dd,mm,yy;
};
struct data date1,date2;
clrscr();
printf("Enter First Date:-\t");
scanf("%d%d%d",&date1.dd,&date1.mm,&date1.yy);
printf("Enter Second Date:-\t");
scanf("%d%d%d",&date2.dd,&date2.mm,&date2.yy);
if(date1.dd==date2.dd&&date1.mm==date2.mm&&date1.yy==date2.yy)
printf("Both Dates are Equal");
else
printf("\tDates are not Equal");
getch();
}
LAB-8
#include<stdio.h>
#include<conio.h>
void main()
{
struct student
{
int rollno,age;
char name[20];
char branch[15];
}x[5];
clrscr();
for(int i=0;i<5;i++)
{
printf("Enter Information of student- %d\n",i+1);
scanf("%d%s%d%s",&x[i].rollno,x[i].name,&x[i].age,x[i].branch);
}
for(i=0;i<5;i++)
{
printf("Information of student- %d\n",i+1);
printf("RollNo=%d\nName=",x[i].rollno);
puts(x[i].name);
printf("Age=%d\nBranch=",x[i].age);
puts(x[i].branch);
}
getch();
}
LAB-9
PROGRAM NO. :-17
#include<stdio.h>
#include<conio.h>
void main()
{
int list[10],temp,i,j;
printf("Enter 10 elements of the list\n");
for(i=0;i<10;i++)
{
scanf("%d",&list[i]);
}
for(i=0;i<10;i++)
{
for(j=0;j<9;j++)
{
if(list[j]>list[j+1])
{
temp=list[j];
list[j]=list[j+1];
list[j+1]=temp;
}
}
}
printf("Sorted List:-\n");
for(i=0;i<10;i++)
{
printf("%d ",list[i]);
}
getch();
}
LAB-9
PROGRAM NO. :- 18
#include<stdio.h>
#include<conio.h>
void main()
{
int list[10],temp,min,i,j;
printf("Enter 10 elements of the list\n");
for(i=0;i<10;i++)
{
scanf("%d",&list[i]);
}
for(i=0;i<9;i++)
{
min=i;
for(j=i+1;j<10;j++)
{
if(list[min]>list[j])
{
min=j;
}
}
if(min!=i)
{
temp=list[i];
list[i]=list[min];
list[min]=temp;
}
}
printf("Sorted List:-\n");
for(i=0;i<10;i++)
{
printf("%d ",list[i]);
}
getch();
}
LAB-10
PROGRAM NO :-19
#include<stdio.h>
#include<conio.h>
void main()
{
int arr[50],i,n,key,lb,ub,mid;
clrscr();
printf("Enter number of elements of array = ");
scanf("%d",&n);
printf("Enter %d Elements of array\n",n);
for(i=0;i<n;i++)
{
scanf("%d",&arr[i]);
}
printf("Enter value to find\n");
scanf("%d",&key);
lb=0;
ub=n-1;
mid=(lb+ub)/2;
while(lb<=ub)
{
if(arr[mid]==key)
{
printf("%d found at location %d\n",key,mid+1);
break;
}
else if(arr[mid]<key)
{
lb=mid+1;
}
else
{
ub=mid-1;
}
mid=(lb+ub)/2;
}
if(lb>ub)
{
printf("Not found! %d is not present in the list.",key);
}
getch();
}
LAB-10
PROGRAM NO. :- 20
#include<stdio.h>
#include<conio.h>
void main()
{
int arr[50],key,n,i;
clrscr();
printf("Enter number of elements of array = ");
scanf("%d",&n);
printf("Enter %d Elements of array\n",n);
for(i=0;i<n;i++)
{
scanf("%d",&arr[i]);
}
printf("Enter value to find\n");
scanf("%d",&key);
for(i=0;i<n;i++)
{
if(arr[i]==key)
{
printf("%d found at location %d\n",key,i+1);
break;
}
}
if(i==n)
{
printf("Not found! %d is not present in the list.",key);
}
getch();
}