Write a program to print the following pattern.
1
12
123
1234
Write a program to print the following pattern.
1
12
123
1234
SOLUTION:
Write a program to print the following pattern.
1234
123
12
1
SOLUTION
Write a program to print the following pattern.
4321
321
21
1
SOLUTION
1
12
123
1234
Solution in | C | JAVA | PYTHON |
---|
#include<stdio.h>
int main() {
int n,i,j;
scanf("%d",&n);
for(i=1;i<=n;i++){
for(j=1;j<=i;j++){
printf("%d",j);
}
if(i<n) printf("\n");
}
return 0;
}
int main() {
int n,i,j;
scanf("%d",&n);
for(i=1;i<=n;i++){
for(j=1;j<=i;j++){
printf("%d",j);
}
if(i<n) printf("\n");
}
return 0;
}
Write a program to print the following pattern.
1
12
123
1234
SOLUTION:
#include<stdio.h>
int main() {
int n,i,j;
scanf("%d",&n);
for(i=1;i<=n;i++){
if(i<n) printf("%*c",n-i,' ');
for(j=1;j<=i;j++){
printf("%d",j);
}
if(i<n) printf("\n");
}
return 0;
}
int main() {
int n,i,j;
scanf("%d",&n);
for(i=1;i<=n;i++){
if(i<n) printf("%*c",n-i,' ');
for(j=1;j<=i;j++){
printf("%d",j);
}
if(i<n) printf("\n");
}
return 0;
}
Write a program to print the following pattern.
1234
123
12
1
SOLUTION
#include<stdio.h>
int main() {
int n,i,j;
scanf("%d",&n);
for(i=n;i>=1;i--){
if(i<n) printf("%*c",n-i,' ');
for(j=1;j<=i;j++){
printf("%d",j);
}
if(i>1) printf("\n");
}
return 0;
}
int main() {
int n,i,j;
scanf("%d",&n);
for(i=n;i>=1;i--){
if(i<n) printf("%*c",n-i,' ');
for(j=1;j<=i;j++){
printf("%d",j);
}
if(i>1) printf("\n");
}
return 0;
}
Write a program to print the following pattern.
4321
321
21
1
SOLUTION
#include<stdio.h>
int main() {
int n,i,j;
scanf("%d",&n);
for(i=n;i>=1;i--){
if(i<n) printf("%*c",n-i,' ');
for(j=i;j>=1;j--){
printf("%d",j);
}
if(i>1) printf("\n");
}
return 0;
}
int main() {
int n,i,j;
scanf("%d",&n);
for(i=n;i>=1;i--){
if(i<n) printf("%*c",n-i,' ');
for(j=i;j>=1;j--){
printf("%d",j);
}
if(i>1) printf("\n");
}
return 0;
}