Pattern Printing coding 8

CODE NO:- 10

Print the below pattern



#LOGIC
Take a variable and assign it with value (n*(n+1))/2 then keep decrementing it in the inner loop and print the pattern.
Here n is the no. of entered rows whereas (n*(n+1))/2 is the first value of pattern.
ex: if n=4 then (n*(n+1))/2 results 10.

#Program( In C):

In  C language we use  ' // '  for Single line comment and /*---*/ for multi line comment

#include<stdio.h>// header file for i/p and o/p
int main()
{
int n,i,k,a;
printf("\n enter the no.of rows:");
scanf("%d",&n);
a=(n*(n+1))/2;
for(i=0;i<n;i++)
{
             for(k=0;k<n-i;k++)
  {
printf("%d ",a--); // post decrementing the value
             }
printf("\n");
}
return 0;
}

We got this output by using DEV C++ (IDE)



Link: For other pattern printing problems

Comments

Post a Comment

Popular posts from this blog

WHY PROGRAMMING?

Series code 2

Pattern Printing coding 7