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
What is the difference between declaring a variable and defining a variable?
a=10;b= 5;c=3;d=3; if(a printf(%d %d %d %d a,b,c,d) else printf("%d %d %d %d a,b,c,d);
What is wild pointer in c with example?
What is the use of #include in c?
Describe the order of precedence with regards to operators in C.
to find the closest pair
Explain what are compound statements?
What does do in c?
main(){char *str;scanf("%s",str);printf("%s",str); }The error in the above program is: a) Variable 'str' is not initialised b) Format control for a string is not %s c) Parameter to scanf is passed by value. It should be an address d) none
What is structure of c program?
What is use of bit field?
What is a pointer in c?
What is gets() function?
Why do we use static in c?
How can variables be characterized?