Write a program to read a positive integer number 'n' and generate the numbers in the [5 M] following way. If entered number is 3, the output will be as follows:
9 4 1 0 1 2 3
#include <stdio.h>
int main()
{
int n;
int i;
printf("Enter positive integer number: ");
if(scanf("%d", &n) != 1 || n <= 0)
{
printf("Bad input\n");
return 1;
}
for(i = n; i > 0; --i)
{
printf("%d ", i * i);
}
for(i = 0; i <= n; ++i)
{
printf("%d", i);
if(i != n)
{
printf(" ");
}
}
printf("\n");
return 0;
}
Comments
Leave a comment