Pattern Printing coding 11

CODE NO:- 20
Print the below pattern

#LOGIC
Take a variable and assign it with value 0(zero) then keep incrementing it by 1 in the inner loop.

#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 i,j,a=0,n;
printf("\n enter the no. of rows:");
scanf("%d",&n);
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
printf("%3d",++a);// %3d is used to display the pattern correctly
}
printf("\n");
}
/* %3d is a format specifier where
% means "print the variable here"
3 means "use at least 3 spaces to display, padding as needed"
d means integer

putting the above sentences together we can say that:
"print an integer, taking minimum 3 spaces" */

return 0;

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

Link: For other pattern printing problems

Comments

Popular posts from this blog

WHY PROGRAMMING?

Pattern Printing coding 7

Pattern Printing coding 13