Pattern Printing coding 4

CODE NO:- 04

Print the below pattern


#LOGIC

In each row first, try to print spaces then in same row print the pattern, i.e for first-row print 3 spaces then 1(required pattern).
Now proceed in the same manner.

#Program

In  C language we use  ' // ' for single line comment

#include<stdio.h>
int main()
{
int n,i,j,k;
printf("\n enter the no.of rows:");
scanf("%d",&n);
for(i=0;i<n;i++)
{
         for(j=0;j<n-i-1;j++)// loop for printing the required spaces
  {
printf(" ");
         }
        for(k=0;k<=i;k++) // loop for printing the required pattern
  {
printf("%d",i+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

Pattern Printing coding 7