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
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;
}
Link: For other pattern printing problems
Nice but easy
ReplyDelete