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
Write a program to reverse a given number in c language?
What is maximum size of array in c?
What are the types of variables in c?
Is there any demerits of using pointer?
What is the use of #include in c?
Explain how can you check to see whether a symbol is defined?
void main(){ int a; a=1; while(a-->=1) while(a-->=0); printf("%d",a); }
What is extern variable in c with example?
pierrot's divisor program using c or c++ code
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
What is the general form of a C program?
What is #include stdlib h?
Why are some ANSI/ISO Standard library routines showing up as undefined, even though I've got an ANSI compiler?
What does %p mean?
How to define structures? ·