1
1 2
1 2 3
1 2 3 4
1 2 3
1 2
1
generate this output using for loop

Answers were Sorted based on User's Feedback



1 1 2 1 2 3 1 2 3 4 ..

Answer / varsha shukla

#include<conio.h>
#include<stdio.h>
void main()
{
int i,j,k,l;
for(i=1;i<=4;i++)
{
for(k=i;k<=4;k++)
{
printf(" ");
}
for(j=1;j<=i;j++)
{
printf(" %d",j);
}
printf("\n");
}
for(i=3;i>0;i--)
{
for(l=i;l<=3;l++)
{
printf(" ");
}
for(j=1;j<=i;j++)
{
printf(" %d",j);
}
printf("\n");
}
getch();

Is This Answer Correct ?    4 Yes 1 No

1 1 2 1 2 3 1 2 3 4 ..

Answer / 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

More C Interview Questions

what are the 10 different models of writing an addition program in C language?

0 Answers  


How can you print HELLO WORLD without using "semicolon"?

7 Answers   HCL, Infosys,


if the area was hit by a virus and so the decrease in the population because of death was x/3 and the migration from other places increased a population by 2x then annually it had so many ppl. find our the population in the starting.

1 Answers   TCS,


an algorithem for the implementation of circular doubly linked list

1 Answers  


can anyone please tell me wat is backlogs... i was looking for the job openings where i read this.. eligibility criteria minimum 70% in degree without backlogs. is that arrear.. if so is it standing arrear or history of arrears... please help me...

11 Answers   CTS, Indian Navy, L&T, Microsoft, SSB, TCE, TCS,






What are identifiers and keywords in c?

0 Answers  


Explain what are compound statements?

0 Answers  


Can you tell me how to check whether a linked list is circular?

1 Answers  


What is the difference between int main and void main in c?

0 Answers  


What is a function in c?

0 Answers  


What is c language & why it is used?

0 Answers  


Hai what is the different types of versions and their differences

0 Answers  


Categories