Write a program to print the given pattern.
Input Format:
Input consists of a single integer.
Output Format:
Refer sample output. There is a trailing space at the end of each line.
Sample Input:
5
Sample Output:
5 4 4 3 3 3 2 2 2 2 1 1 1 1 1
Code:
#include<stdio.h>
int main()
{
int n,i,j,k=1,a;
scanf("%d",&n);
a=n;
for(i=0;i<n;i++)
{
for(j=1;j<=k;j++)
printf("%d ",a);
k++;
a--;
printf("\n");
}
return 0;
}
This is wrong program if both j and k keeps increasing then it will run as an infinite loop
ReplyDelete01
ReplyDelete#include
02
int main()
03
{
04
int n,i,j;
05
scanf("%d",&n);
06
for(i=n;i>0;i--)
07
{
08
for(j=i;j<=n;j++)
09
{
10
printf("%d ",i);
11
}
12
13
printf("\n");
14
}
15
return 0;
16
}