8th International Conference on Soft Computing, Mathematics and Control (SMC ...
Pslb lab manual
1. Shri Rawatpura Sarkar Institute of Technology-II New Raipur (C.G.)
CSE/3rd/PSLBLab/PreparedbyVivekKumarSinha
Experiment No. 1
Aim:-Write a C-Program to take the radius of sphere as input and print the volume and surface
area of that sphere.
/* Program for finding volume and surface area */
#include<stdio.h>
#include<conio.h>
#define pi 3.14
int main()
{
float r,vol,area;
printf("enter the radiusn");
scanf("%f",&r);
vol= (4.0/3)*pi*r*r*r;
area=4*3.14*r*r;
printf("volume of sphere=%fnnn",vol);
printf("surface area=%f",area);
getch();
}
/* Output */
enter the radius
5
volume of sphere=523.333313
surface area=314.000000
2. Shri Rawatpura Sarkar Institute of Technology-II New Raipur (C.G.)
CSE/3rd/PSLBLab/PreparedbyVivekKumarSinha
Experiment No. 2
Aim:-Write a C-Program to take a five digit number as input and calculate the sum of its digits.
/* Program to calculate the sum of five digit number*/
#include<stdio.h>
#include<conio.h>
int main()
{
int num,a,b,c,d,total=0;
printf("enter any five digit numbern");
scanf("%d",&num);
a=num%10;
num=num/10;
b=num%10;
num=num/10;
c=num%10;
num=num/10;
d=num%10;
num =num/10;
total=num+a+b+c+d;
printf("the sum of the digit=%d",total);
getch();
}
/* Output */
enter any five digit number
15234
the sum of the digit=15
3. Shri Rawatpura Sarkar Institute of Technology-II New Raipur (C.G.)
CSE/3rd/PSLBLab/PreparedbyVivekKumarSinha
Experiment No. 3
Aim:-Write a C-Program to take three side of a triangle as input and verify weather the triangle
is an isosceles, scalene or an equilateral triangle.
/* Program to Verify triangle property*/
#include<stdio.h>
#include<conio.h>
int main()
{
int a,b,c;
printf("enter the value of three siden");
scanf("%d%d%d",&a,&b,&c);
if(a==b&&b!=c||b==c&&c!=a||c==a&&a!=b)
{
printf("the triangle is iso scales");
}
else if(a==b&&b==c)
{
printf("triangle is eqilatrel");
}
else
{
printf("the traingle is scalanes");
}
getch();
}
/* Output*/
enter the value of three side
2
2
5
the triangle is iso scales
4. Shri Rawatpura Sarkar Institute of Technology-II New Raipur (C.G.)
CSE/3rd/PSLBLab/PreparedbyVivekKumarSinha
Experiment No. 4
Aim:-Write a C-Program that will take three positive integer as input and verify weather they
form a Phythagorean triplet or not.
/* Program to verify triangle is Phythagorean triplet or not */
#include<stdio.h>
#include<conio.h>
int main()
{
int a,b,c;
printf("enter the value of siden");
scanf("%d%d%d",&a,&b,&c);
if((a*a==b*b+c*c)||(b*c==c*c+a*a)||(c*c==a*a+b*b))
printf("the traingle is phythogorean triplat");
else
printf("the traingle is not phythogorean triplat");
getch();
}
/* Output */
enter the value of side
3
4
5
the traingle is phythogorean triplet
5. Shri Rawatpura Sarkar Institute of Technology-II New Raipur (C.G.)
CSE/3rd/PSLBLab/PreparedbyVivekKumarSinha
Experiment No. 5
Aim:-Write a C-Program to print all prime number between a given ranges of numbers.
/* Program to print prime numberes between given of ranges */
#include<stdio.h>
#include<conio.h>
int main()
{
int first,last,i,j;
printf("enter the first and last numbern");
scanf("%d%d",&first,&last);
for(i=first;i<=last;i++)
{
for(j=2;j<i;j++)
{
if(i%j==0)
{
break;
}
}
if(j==i)
printf("%dt",j);
}
getch();
}
/* Output*/
enter the first and last number
100
150
101 103 107 109 113 127 131 137 139 149
6. Shri Rawatpura Sarkar Institute of Technology-II New Raipur (C.G.)
CSE/3rd/PSLBLab/PreparedbyVivekKumarSinha
Experiment No. 6
Aim:-Write a C-Program to define a function that will take an integer as argument and return
the sum of digits of that integer.
/* Program to calculate the sum of digits using functions*/
#include<stdio.h>
#include<conio.h>
void sum(int x);
int main()
{
int num;
printf("enter any numbernn");
scanf("%d",&num);
sum(num);
getch();
}
void sum(int a)
{
int sum=0,b;
while(a!=0)
{
b=a%10;
a=a/10;
sum=sum+b;
}
printf("sum of digit=%d",sum);
return;
}
/* Output */
enter any number
2356
sum of digit=16
7. Shri Rawatpura Sarkar Institute of Technology-II New Raipur (C.G.)
CSE/3rd/PSLBLab/PreparedbyVivekKumarSinha
Experiment No. 7
Aim:-Write a C-Program to define a recursive function that will print the reverse of its integer
argument.
* Program print the reverse number using recursive function*/
#include<stdio.h>
#include<conio.h>
void rev(int x);
int main()
{
int num;
printf("enter any numbernn");
scanf("%d",&num);
rev(num);
getch();
}
void rev(int a)
{
int b;
if(a<=0)
return;
else
printf("%d",b=a%10);
a=a/10;
rev(a);
}
/* Output */
enter any number
5687236
6327865
8. Shri Rawatpura Sarkar Institute of Technology-II New Raipur (C.G.)
CSE/3rd/PSLBLab/PreparedbyVivekKumarSinha
Experiment No. 8
Aim:-Write a C-Program to print the sum of first N even number using recursive function.
/* Program to find the sum of first N numbers*/
#include<stdio.h>
#include<conio.h>
int sum(int);
int main()
{
int num,s;
printf("enter any numbern");
scanf("%d",&num);
s=sum(num);
printf("n sum of first%d even numbers is =%d",num,s);
getch();
}
int sum(int x)
{
int add;
if(x<=0)
return(0);
else
add=2*x+sum(x-1);
return(add);
}
/* Output */
enter any number
5
sum of first5 even numbers is =30
9. Shri Rawatpura Sarkar Institute of Technology-II New Raipur (C.G.)
CSE/3rd/PSLBLab/PreparedbyVivekKumarSinha
Experiment No. 9
Aim:-Write a C-Program to sort an array using bubble sort technique.
*Program to sort an array using bubble sort*/
#include<stdio.h>
#include<conio.h>
int main()
{
int i,j,num,a[10],temp;
printf("enter total number to store in arrayn");
scanf("%d",&num);
printf("enter nummbersn");
for(i=0;i<num;i++)
scanf("%d",&a[i]);
for(i=0;i<num;i++)
{
for(j=0;j<num-i;j++)
{
if(a[j]>a[j+1])
{
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
}
}
printf("stored array using bubble sortn ");
for(i=0;i<num;i++)
printf("%dt",a[i]);
getch();
}
10. Shri Rawatpura Sarkar Institute of Technology-II New Raipur (C.G.)
CSE/3rd/PSLBLab/PreparedbyVivekKumarSinha
/* Output */
enter total number to store in array
7
enter nummbers
12
15
6
8
3
9
5
stored array using bubble sort
3 5 6 8 9 12 15
11. Shri Rawatpura Sarkar Institute of Technology-II New Raipur (C.G.)
CSE/3rd/PSLBLab/PreparedbyVivekKumarSinha
Experiment No. 10
Aim:-Write a C-Program that will take the elements of two integer array of 5 element each and
insert the common element of both the array into a third array.
/*Program to find the intersection of two array values*/
#include<stdio.h>
#include<conio.h>
int main()
{
int a[5],b[5],c[5];
int i,j;
printf("nEnter the 5 values for first arrayn");
for(i=0;i<5;i++)
scanf("%d",&a[i]);
printf("nEnter the 5 values for second arrayn");
for(i=0;i<5;i++)
scanf("%d",&b[i]);
printf("n Intersection of two array are:n");
for(i=0;i<5;i++)
{
for(j=0;j<5;j++)
{
if(a[i]==b[j])
{
c[i]=a[i];
printf("%dt",c[i]);
}
}
}
getch();
}
12. Shri Rawatpura Sarkar Institute of Technology-II New Raipur (C.G.)
CSE/3rd/PSLBLab/PreparedbyVivekKumarSinha
/* Output */
Enter the 5 values for first array
5
6
1
4
7
Enter the 5 values for second array
8
3
5
4
6
Intersections of two arrays are:
5 6 4