[My site ]
Main » 2013 » December » 13 » 2011-2012 question 3
0:10 AM
2011-2012 question 3
write a program that reads value of x and compute the value of y from the following equation
y = -x + x^2 - x^3 + x^4 - ....... x^n

#include<stdio.h>
main()
{
int x, n, i, y=0, k=1;
printf("enter x : ");
scanf("%d", &x);
printf("enter n : ");
scanf("%d", &n);
for(i=1;i<=n;i++){
k*=x;
if(i%2==0)
y+=k;
else
y-=k;
}
printf("Y = %d", y);
getch();
return 0;
}
Category: C Programming - 1 | Views: 349 | Added by: ahansaary | Rating: 0.0/0
Total comments: 0
Only registered users can add comments.
[ Sign Up | Login ]