Write a program to generate the following series 0,2,8,14,...,34. Input format: The input is an integer which denotes 'n'. Output format: Print the series and refer the sample output for formatting. Sample Input: 6 Sample Output: 0 2 8 14 24 34
Answers
Answered by
1
Answer:
Input: N = 4
Output: 2, 1, 4, 3
Explanation:
Nth Term = (N % 2 == 0) ? (N - 1) : (N + 1)
1st term = (1 % 2 == 0) ? (1 - 1) : (1 + 1)
= (1 + 1)
= 2
2nd term = (2 % 2 == 0) ? (2 - 1) : (2 + 1)
= (2 - 1)
= 1
3rd term = (3 % 2 == 0) ? (3 - 1) : (3 + 1)
= (3 + 1)
= 4
4th term = (4 % 2 == 0) ? (4 - 1) : (4 + 1)
= (4 - 1)
= 3
Therefore, Series = 2, 1, 4, 3
Input: N = 7
Output: 2, 1, 4, 3, 6, 5, 8
Hope this helps you
Shakuntalam
Answered by
6
Answer:
#include<stdio.h>
int main()
{
int n,i;
printf("enter the value of n\n");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
if(i%2!=0)
printf("%d ",(i*i)-1);
else
printf("%d ",(i*i)-2);
}
}
Explanation:
(1*1)-1, (2*2)-2, (3*3)-1, (4*4)-2.............
Similar questions
Math,
5 months ago
Biology,
5 months ago
Computer Science,
5 months ago
Chemistry,
10 months ago
India Languages,
10 months ago
Biology,
1 year ago
Math,
1 year ago