1
1 2
1 2 3
1 2 3 4
1 2 3
1 2
1
generate this output using for loop
Answer Posted / narasimharao
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,k,n;
printf("Enter n value:");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
for(k=i;k<n;k++)
{
printf(" ");
}
for(j=1;j<=i;j++)
{
printf("%d",j);
for(k=i;k<i+1;k++)
{
printf(" ");
}
}
printf("\n");
}
for(i=n-1;i>=1;i--)
{
for(k=i;k<n;k++)
{
printf(" ");
}
for(j=1;j<=i;j++)
{
printf("%d",j);
for(k=i;k<i+1;k++)
{
printf(" ");
}
}
printf("\n");
}
getch();
}
Is This Answer Correct ? | 1 Yes | 2 No |
Post New Answer View All Answers
Do you know the difference between exit() and _exit() function in c?
Why we use break in c?
What is call by reference in functions?
What is the meaning of ?
An instruction which is analysed and acted upon by the processor prior to the compiler going its work a) directive b) constructive c) constant d) absolute mode
What are the application of c?
What are comments and how do you insert it in a C program?
How many loops are there in c?
#include
How is a structure member accessed?
What is the difference between new and malloc functions?
What is the 'named constructor idiom'?
What is the size of enum in c?
What is the purpose of & in scanf?
Explain bitwise shift operators?