Practice Program







  • Program of printing first 'n' natural numbers   in reverse order.
  • Solution:through for loop
    void main()
    {
        int n,i;
    
        printf("How many natural number you  want to print: ");
        scanf("%d",&n);
    
    
        printf("First %d natural numbers are:\n",n);
        for(i=n; i>0; i--)
        {
            printf("%d\t",i);
        }
    
    
    }
    

    Output1
    How many natural number you want to print: 5

    natural numbers In reverse order are:
    5    4    3    2     1
    Output2
    How many natural number you want to print: 10

    Natural numbers in reverse are :
    10    9    8    7    6     5    4    3    2     1
    Output3
    How many natural number you want to print: 15

    Natural numbers in reverse order are:
    15    14    13    12    11    10    9    8    7    6     5    4    3    2     1





    Solution : through while loop
    void main()
    {
        int n,i;
    
        printf("How many natural number you  want to print: ");
        scanf("%d",&n);
    
    i = n
        printf("\nNatural numbers in reverse order are:");
        while(i>0)
        {
            printf("%d\t",i);
            i--;
        }
    
    
    }
    






    Solution:from do-while loop
    void main()
    {
        int n,i;
    
        printf("How many natural number you  want to print: ");
        scanf("%d",&n);
    
    i = n
        printf("Natural numbers in reverse order are:\n");
        do
        {
            printf("%d\t",i);
            i--;
        }
         while(i>0);
    
    }