Computer Science, asked by rithviknani8081, 1 year ago

Write a program to generate the follow 1, -2, 6, -15, 31, -56,....n

Answers

Answered by YourPalNurav
3
#include <stdio.h>
int main()
{ int n=10, a[50], i,j;
printf("Enter number of terms you need: ");
scanf("%d", &n);
printf("The series is: ");
for(i=1;i<n+1;i++)
{
if(i==1){a[i]=1;}
else{a[i]=(a[i-1]+( (i-1)*(i-1) ) );}
}

for(j=1;j<n+1;j++)
{
if(j%2==0) {a[j]=a[j]*(-1);}
else{a[j]=a[j]*(1);}
printf("%d, ", a[j]);
}

return 0;
}


If this answer was helpful, please vote this answer as BRAINLIEST ANSWER to help me get some points. Thanks ☺️
Answered by kunapadhan97
0
#include <stdio.h>
int main()
{
int n,i;
printf("Enter number of terms you need: ");
scanf("%d", &n);
printf("The series is: \n");
for(i=1;i<=n;i++)
printf("%d",n);
return 0;
}
Similar questions