0
The given program reads n and finds sum of product of consecutive numbers. If n=7 and numbers are 4,5,2,5,6,4,7 the output shoul
//To find (x1+x2)*x3 +(x2+x3)*x4 + (x3+x4)*x5 #include <stdio.h> int main() { int x[20], sum, i, n; printf("How many numbers"); scanf("%d", &n); for(i=1;i<=n;i++) { printf("Give %d th number", i); scanf("%d", &x[i]); } sum=0; for(i=1;i<=n-2;i++) sum+=sum+(x[i]+x[i+1])*x[i+2]; printf("%d",sum); return 0; }
1 Réponse
0
#include <stdio.h>
int main()
{
int x[20], sum, i, n;
printf("How many numbers");
scanf("%d", &n);
for(i=1;i<=n;i++)
{
printf("Give %d th number", i);
scanf("%d", &x[i]);
}
sum=0;
for(i=1;i<=n-4;i++)
sum+=sum+((x[i]+x[i+1])*x[i+2]);
printf("%d",sum);
return 0;
}