WRITE A PROGRAM TO PRINT THE FOLLOWING OUTPUTS USING FOR
LOOPS.

A) * B) *****
*** * *
***** * *
*****

Answers were Sorted based on User's Feedback



WRITE A PROGRAM TO PRINT THE FOLLOWING OUTPUTS USING FOR LOOPS. A) * B) ***** ..

Answer / vignesh1988i

for a)
#include<stdio.h>
#include<conio.h>
void main()
{
int n;
printf("enter the number of terms :");
scanf("%d",&n);
for(int i=0;i<=n+i;i++)
{
for(int j=0;j<n-1 ;j++)
printf(" ");
for(j=0;j<=(2*i);j++)
printf("* ");
printf("\n");
n--;
}
getch();
}

for b):
#include<stdio.h>
#include<conio.h>
void main()
{
int n;
printf("enter the no. of terms :");
scanf("%d",&n);
for(int i=1;i<=5;i++)
{
printf("\n");
if(i==1 || i==n)
{
for(j=0;j<n;j++)
printf("* ");
}
else
{
printf("* ");
for(j=0;j<n-2;j++)
printf(" ");
printf("* ");
}
}
getch();
}

Is This Answer Correct ?    14 Yes 6 No

WRITE A PROGRAM TO PRINT THE FOLLOWING OUTPUTS USING FOR LOOPS. A) * B) ***** ..

Answer / vutukuru

#include<stdio.h>
main()
{
int i,j,n=5;
clrscr();
for(i=0;i<n-4;i++)
{
printf("*");
}
printf("\n");
for(i=0;i<n-2;i++)
{
printf("*");
}
printf("\n");
for(i=0;i<n;i++)
{
printf("*");
}
getch();
}

Is This Answer Correct ?    18 Yes 12 No

Post New Answer

More C Interview Questions

find the value of y y = 1.5x+3 for x<=2 y = 2x+5 for x>2

0 Answers   TCS,


Result of the following program is main() { int i=0; for(i=0;i<20;i++) { switch(i) case 0:i+=5; case 1:i+=2; case 5:i+=5; default i+=4; break;} printf("%d,",i); } } a)0,5,9,13,17 b)5,9,13,17 c)12,17,22 d)16,21 e)syntax error

8 Answers   IBM,


how to get starting address of a running C program

3 Answers  


Write a program to display the no of bit difference between any 2 given numbers eg: Num1 will 12->1100 Num2 will 7->0111 the difference in bits are 2.

4 Answers  


In c programming typeing to occupy the variables in memory space. if not useing the variable the memory space is wasted.ok, how to avoid the situation..? (the variable is used & notused)

0 Answers   Wipro,


Explain how can you restore a redirected standard stream?

0 Answers  


What is data type long in c?

0 Answers  


please tell me the logic for this C program : INPUT (string):ABCD OUTPUT :BCDA CDAB DABC

2 Answers   Mphasis,


How can you increase the size of a dynamically allocated array?

0 Answers   TISL,


Explain what does a function declared as pascal do differently?

0 Answers  


Why c is called a mid level programming language?

0 Answers  


Why n++ execute faster than n+1 ?

2 Answers  


Categories