Pages

Monday, September 5, 2016

Reverse number series pattern.


/*C program to print reverse number series pattern.

For n=4,

10 9 8 7
6 5 4
3 2
1
*/

#include<stdio.h>
int main()
{
     int i, j, n, count=1;
     printf("Enter your number:");
     scanf("%d", &n);
     //logic for couting first no. to be printed
     for (i=0; i<n; i++)
           for(j=0; j<=i; j++)
                count++;
     count--;
     //logic for printing pattern
     for (i=n; i>0; i--)
     {
           for(j=i; j>0; j--)
                printf("%d ", count--);
           printf("\n");  
     }
     return 0; 
}


Output of the Program:

Enter your number:4
10 9 8 7
6 5 4
3 2
1


No comments:

Post a Comment