Write a program to print following pattern.
SAMPLE INPUT
4
SAMPLE OUTPUT
1
2 3
4 5 6
7 8 9 10
SOURCE CODE
#include<stdio.h>
int main() {
int n,i,j,k=1;
scanf("%d",&n);
for(i=1;i<=n;i++){
for(j=1;j<=i;j++){
printf("%d",k++);
if(j<i) printf(" ");
}
if(i<n) printf("\n");
}
return 0;
}
Write a program to print following pattern.
SAMPLE INPUT
4
SAMPLE OUTPUT
1
2 3
4 5 6
7 8 9 10
4 5 6
2 3
1
SOURCE CODE
#include<stdio.h>
int main() {
int n,i,j,k=1;
scanf("%d",&n);
for(i=1;i<=n;i++){
for(j=1;j<=i;j++){
printf("%d",k++);
if(j<i) printf(" ");
}
printf("\n");
}
k=k-j;
for(i=n-1;i>=1;i--){
k=k-i+1;
for(j=1;j<=i;j++){
printf("%d",k++);
if(j<i) printf(" ");
}
k=k-j;
if(i>1) printf("\n");
}
return 0;
}
Write a program to print following pattern.
SAMPLE INPUT
4
SAMPLE OUTPUT
1
3 2
4 5 6
10 9 8 7
SOURCE CODE
#include<stdio.h>
int main() {
int n,i,j,k=1,kk;
scanf("%d",&n);
for(i=1;i<=n;i++){
kk=k+i-1;
for(j=1;j<=i;j++){
if(i%2!=0){
printf("%d",k++);
if(j<i) printf(" ");
}
else{
printf("%d",kk--,k++);
if(j<i) printf(" ");
}
}
if(i<n) printf("\n");
}
return 0;
}
Write a program to print following pattern.
SAMPLE INPUT
4
SAMPLE OUTPUT
1
3 2
6 5 4
10 9 8 7
SOURCE CODE
#include<stdio.h>
int main() {
int n,i,j,k=0;
scanf("%d",&n);
for(i=1;i<=n;i++){
k=k+i;
for(j=1;j<=i;j++){
printf("%d",k--);
if(j<i) printf(" ");
}
k=k+j-1;
if(i<n) printf("\n");
}
return 0;
}
SAMPLE INPUT
4
SAMPLE OUTPUT
1
2 3
4 5 6
7 8 9 10
SOURCE CODE
#include<stdio.h>
int main() {
int n,i,j,k=1;
scanf("%d",&n);
for(i=1;i<=n;i++){
for(j=1;j<=i;j++){
printf("%d",k++);
if(j<i) printf(" ");
}
if(i<n) printf("\n");
}
return 0;
}
Write a program to print following pattern.
SAMPLE INPUT
4
SAMPLE OUTPUT
1
2 3
4 5 6
7 8 9 10
4 5 6
2 3
1
SOURCE CODE
#include<stdio.h>
int main() {
int n,i,j,k=1;
scanf("%d",&n);
for(i=1;i<=n;i++){
for(j=1;j<=i;j++){
printf("%d",k++);
if(j<i) printf(" ");
}
printf("\n");
}
k=k-j;
for(i=n-1;i>=1;i--){
k=k-i+1;
for(j=1;j<=i;j++){
printf("%d",k++);
if(j<i) printf(" ");
}
k=k-j;
if(i>1) printf("\n");
}
return 0;
}
Write a program to print following pattern.
SAMPLE INPUT
4
SAMPLE OUTPUT
1
3 2
4 5 6
10 9 8 7
SOURCE CODE
#include<stdio.h>
int main() {
int n,i,j,k=1,kk;
scanf("%d",&n);
for(i=1;i<=n;i++){
kk=k+i-1;
for(j=1;j<=i;j++){
if(i%2!=0){
printf("%d",k++);
if(j<i) printf(" ");
}
else{
printf("%d",kk--,k++);
if(j<i) printf(" ");
}
}
if(i<n) printf("\n");
}
return 0;
}
Write a program to print following pattern.
SAMPLE INPUT
4
SAMPLE OUTPUT
1
3 2
6 5 4
10 9 8 7
SOURCE CODE
#include<stdio.h>
int main() {
int n,i,j,k=0;
scanf("%d",&n);
for(i=1;i<=n;i++){
k=k+i;
for(j=1;j<=i;j++){
printf("%d",k--);
if(j<i) printf(" ");
}
k=k+j-1;
if(i<n) printf("\n");
}
return 0;
}