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
1 2 2 3 3 3 4 4 4 4 5 5 5 5 5
Code:
#include<stdio.h> int main(){ int n,i,j,k=1,a=1; scanf("%d",&n); for(i=0;i<n;i++){ for(j=1;j<=k;j++){ printf("%d ",a); } k++; a++; printf("\n"); } return 0; }
#include
ReplyDeleteint main(){
int n,i,j,a=1;
scanf("%d",&n);
for(i=0;i<n;i++){
for(j=1;j<=a;j++){
printf("%d ",a);
}
a++;
printf("\n");
}
return 0;
}
Why to use k variable not needed