Evaluate the given Polynomial
Equation
#include
#include
#include
#define maxsize 10
void main()
{
int array[maxsize];
int i, num, power;
float x, polySum;
clrscr();
printf("Enter the order of the polynomial \n");
scanf("%d", &num);
printf("Enter the value of x \n");
scanf("%f", &x);
printf("Enter %d coefficients \n", num + 1);
for (i = 0; i <= num; i++)
{
scanf("%d", &array[i]);
}
polySum = array[0];
for (i = 1; i <= num; i++)
{
polySum = polySum * x + array[i];
}
power = num;
printf("Given polynomial is: \n");
for (i = 0; i <= num; i++)
{
if (power < 0)
{
break;
}
if (array[i] > 0)
printf(" + ");
else if (array[i] < 0)
printf(" - ");
else
printf(" ");
printf("%dx^%d ", abs(array[i]), power--);
}
printf("\n Sum of the polynomial = %6.2f \n", polySum);
getch();
}
Output
Enter the order of the polynomial
2
Enter the value of x
2
Enter 3 coefficients
3
2
6
Given polynomial is:
+ 3x^2 + 2x^1 + 6x^0
Sum of the polynomial = 22.00
Enter the order of the polynomial
4
Enter the value of x
1
Enter 5 coefficients
3
-5
6
8
-9
Given polynomial is:
+ 3x^4 - 5x^3 + 6x^2 + 8x^1 - 9x^0
Sum of the polynomial = 3.00
Generate Fibonacci Series
#include
#include
void main()
{
int fib1 = 0, fib2 = 1, fib3, limit, count = 0;
clrscr();
printf("Enter the limit to generate the Fibonacci Series \n");
scanf("%d", &limit);
printf("Fibonacci Series is ...\n");
printf("%d\n", fib1);
printf("%d\n", fib2);
count = 2;
while (count < limit)
{
fib3 = fib1 + fib2;
count++;
printf("%d\n", fib3);
fib1 = fib2;
fib2 = fib3;
}
getch();
}
Output
Enter the limit to generate the Fibonacci Series
6
Fibonacci Series is ...
0
1
1
2
3
5
Compute the Surface Area &
Volume of a Cube
#include
#include
#include
void main()
{
float side, surfacearea, volume;
clrscr();
printf("Enter the length of a side \n");
scanf("%f", &side);
surfacearea = 6.0 * side * side;
volume = pow(side, 3);
printf("Surface area = %6.2f and Volume = %6.2f \n", surfacearea, volume);
getch();
}
Output
Enter the length of a side
34
Surface area = 6936.00 and Volume = 39304.00
No comments:
Post a Comment