Answer to Question #169497 in C for Mayank

Question #169497

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


1
Expert's answer
2021-03-06T09:59:22-0500
#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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS