Lab manualsahu[et&t]
-
Upload
vivek-kumar-sinha -
Category
Engineering
-
view
18 -
download
1
Transcript of Lab manualsahu[et&t]
SHRI RAWATPURA SARKAR INSTITUTE OF TECHNOLOGY-II, NEW RAIPUR
A MANUAL OFNUMERICAL ANALYSIS USING C
LABORATORY
DEPARTMENT OF ELECTRONICS AND TELECOMMUNICATION
SEMESTER: IV PRACTICAL CODE: 322821 (22)
. SHRI RAWATPURA SARKAR INSTITUTE OF TECHNOLOGY-II NEW RAIPUR
Experiment No. 1Aim:-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 radius\n");
scanf("%f",&r);
vol= (4.0/3)*pi*r*r*r;
area=4*3.14*r*r;
printf("volume of sphere=%f\n\n\n",vol);
printf("surface area=%f",area);
getch();
}
/* Output */
enter the radius
5
volume of sphere=523.333313
surface area=314.000000
ET&T/4th/NACP Lab/Prepared by Vivek Kumar Sinha
. SHRI RAWATPURA SARKAR INSTITUTE OF TECHNOLOGY-II NEW RAIPUR
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 number\n");
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 number15234the sum of the digit=15
ET&T/4th/NACP Lab/Prepared by Vivek Kumar Sinha
. SHRI RAWATPURA SARKAR INSTITUTE OF TECHNOLOGY-II NEW RAIPUR
Experiment No. 3Aim:-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 side\n");
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
ET&T/4th/NACP Lab/Prepared by Vivek Kumar Sinha
. SHRI RAWATPURA SARKAR INSTITUTE OF TECHNOLOGY-II NEW RAIPUR
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 side\n");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 side345the traingle is phythogorean triplet
ET&T/4th/NACP Lab/Prepared by Vivek Kumar Sinha
. SHRI RAWATPURA SARKAR INSTITUTE OF TECHNOLOGY-II NEW RAIPUR
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 number\n");
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("%d\t",j);
}
getch();
}
/* Output*/
enter the first and last number
100
150
101 103 107 109 113 127 131 137 139 149
ET&T/4th/NACP Lab/Prepared by Vivek Kumar Sinha
. SHRI RAWATPURA SARKAR INSTITUTE OF TECHNOLOGY-II NEW RAIPUR
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 number\n\n");
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
ET&T/4th/NACP Lab/Prepared by Vivek Kumar Sinha
. SHRI RAWATPURA SARKAR INSTITUTE OF TECHNOLOGY-II NEW RAIPUR
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 number\n\n");
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
ET&T/4th/NACP Lab/Prepared by Vivek Kumar Sinha
. SHRI RAWATPURA SARKAR INSTITUTE OF TECHNOLOGY-II NEW RAIPUR
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 number\n");
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
ET&T/4th/NACP Lab/Prepared by Vivek Kumar Sinha
. SHRI RAWATPURA SARKAR INSTITUTE OF TECHNOLOGY-II NEW RAIPUR
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 array\n");
scanf("%d",&num);
printf("enter nummbers\n");
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 sort\n ");
for(i=0;i<num;i++)
printf("%d\t",a[i]);
ET&T/4th/NACP Lab/Prepared by Vivek Kumar Sinha
. SHRI RAWATPURA SARKAR INSTITUTE OF TECHNOLOGY-II NEW RAIPUR
getch();
}
/* 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
ET&T/4th/NACP Lab/Prepared by Vivek Kumar Sinha
. SHRI RAWATPURA SARKAR INSTITUTE OF TECHNOLOGY-II NEW RAIPUR
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 array\n");for(i=0;i<5;i++)scanf("%d",&a[i]);printf("\nEnter the 5 values for second array\n");
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("%d\t",c[i]);
}}
}
getch();}
ET&T/4th/NACP Lab/Prepared by Vivek Kumar Sinha
. SHRI RAWATPURA SARKAR INSTITUTE OF TECHNOLOGY-II NEW RAIPUR
/* Output */
Enter the 5 values for first array56147
Enter the 5 values for second array83546
Intersections of two arrays are:5 6 4
ET&T/4th/NACP Lab/Prepared by Vivek Kumar Sinha