Program:
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
float h,a,b,n,x[20],y[20],sum=0,itgl;
int i;
clrscr();
printf("enter the values of a,b,n");
scanf("%f%f%f",&a,&b,&n);
printf("enter the values of x");
for(i=0;i<=n;i++)
{
scanf("%f",&x[i]);
}
printf("\n enter the values of y"); for(i=0;i<=n;i++)
{
scanf("%f",&y[i]);
}
h=(b-a)/n;
a=x[0];
b=x[n];
for(i=0;i<=(n-2);i++)
{
x[i]=x[i]+h;
if(i%2==0)
{
sum=sum+4*y[i];
}
else
{
sum=sum+2*y[i];
}
}
itgl=sum*(h/3);
printf("integral value%f",itgl);
getch();
}
Input/Output:
Enter the values of a,b,n 1 2 3
Enter the value of x 4 5 6 7
Enter the values of y 8 9 1 2
Integral value is 5.555556
Conclusion: The program is error free
VIVA QUESTIONS
1) Define Binary search ?
Ans: Binary search is a vast improvement over the sequential search. For binary search to work, the item in the list must be in assorted order. The approach employed in the binary search is divid and conquer. If the list to be sorted for a specific item is not sorted, binary search fails.
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
float h,a,b,n,x[20],y[20],sum=0,itgl;
int i;
clrscr();
printf("enter the values of a,b,n");
scanf("%f%f%f",&a,&b,&n);
printf("enter the values of x");
for(i=0;i<=n;i++)
{
scanf("%f",&x[i]);
}
printf("\n enter the values of y"); for(i=0;i<=n;i++)
{
scanf("%f",&y[i]);
}
h=(b-a)/n;
a=x[0];
b=x[n];
for(i=0;i<=(n-2);i++)
{
x[i]=x[i]+h;
if(i%2==0)
{
sum=sum+4*y[i];
}
else
{
sum=sum+2*y[i];
}
}
itgl=sum*(h/3);
printf("integral value%f",itgl);
getch();
}
Input/Output:
Enter the values of a,b,n 1 2 3
Enter the value of x 4 5 6 7
Enter the values of y 8 9 1 2
Integral value is 5.555556
Conclusion: The program is error free
VIVA QUESTIONS
1) Define Binary search ?
Ans: Binary search is a vast improvement over the sequential search. For binary search to work, the item in the list must be in assorted order. The approach employed in the binary search is divid and conquer. If the list to be sorted for a specific item is not sorted, binary search fails.
No comments:
Post a Comment