Pattern Printing coding 7

CODE NO:- 09

Print the below pattern



#LOGIC
Take a variable and assign it with value n+2 and print this value using the inner loop whereas in the outer loop decrement the value by 1.
Here n is the no. of entered rows whereas n+2 is the first element of the pattern.
ex: if n=4 then n+2 result 6.

#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,j,k,a;
printf("\n enter the no.of rows:");
scanf("%d",&n);
a=n+2;
for(i=0;i<n;i++)
{
          for(k=0;k<n-i;k++)
  {
printf("%d ",a);
          }
          a--;// decrementing value by 1
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