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

What is a lookup table in c?

0 Answers  


Write a c program using for loop in switch case?

1 Answers   Infosys,


code for bubble sort?

1 Answers  


C program to find frequency of each character in a text file?

6 Answers  


How can I return multiple values from a function?

6 Answers  


int main() { int days; printf("enter days you are late"); scanf("%d",days); if (days<=5) printf("5o paisa fine"); if (days<=10&&days>=6) printf("1rs fine"); if(days>10) printf("10 rs fine"); if(days=30) printf("membership cancelled"); return 0; } tell me whats wrong in this program? is it right?

2 Answers  


What will be the outcome of the following conditional statement if the value of variable s is 10?

0 Answers  


A collection of functions,calls,subroutines or other data a) library b) header files c) set of files d) textfiles

0 Answers  


program for following output using for loop? 1 2 2 3 3 3 4 4 4 4 5 5 5 5 5

8 Answers   Aptech, Infosys,


how to set Nth bit of variable by using MACRO

3 Answers   HCL,


What are enumerated types?

0 Answers  


if the total selling price of 15 items and the total profit earned on them is input through the keyboard, write a program to find the cost price of one of the item

2 Answers  


Categories