Write a C program that will show the following output: 20 14 8 2 -4 -10 … …. (n terms, where you can specify n).
A required C program is as follows,
#include <stdio.h>
int main()
{
//Declare the variables
int n, i;
//Declare and initialize necessary variable
int value=20;
//Prompt the user to enter number of terms
printf("Enter number of terms: ");
//Get number of terms
scanf("%d", &n);
//Execute for n terms
for(i=0;i<n;i++)
{
//Print the value
printf("%d ",value);
//Update the value
value=value-6;
}
return 0;
}
outputs
Get Answers For Free
Most questions answered within 1 hours.