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

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

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



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Write a program to reverse a given number in c language?

629


What is maximum size of array in c?

588


What are the types of variables in c?

585


Is there any demerits of using pointer?

636


What is the use of #include in c?

587






Explain how can you check to see whether a symbol is defined?

667


void main(){ int a; a=1; while(a-->=1) while(a-->=0); printf("%d",a); }

1265


What is extern variable in c with example?

547


pierrot's divisor program using c or c++ code

1736


any function have arguments one or more OR not . it is compulsary a) any function compulsary have one or more arguments b) any function did not have arguments. It is not compulsary c) it is optional it is not compulsary d) none of the above

649


What is the general form of a C program?

606


What is #include stdlib h?

624


Why are some ANSI/ISO Standard library routines showing up as undefined, even though I've got an ANSI compiler?

673


What does %p mean?

603


‎How to define structures? · ‎

639