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
Describe wild pointers in c?
What is the default value of local and global variables in c?
Why do we use static in c?
Explain the advantages of using macro in c language?
write a programe to accept any two number and check the following condition using goto state ment.if a>b,print a & find whether it is even or odd and then print.and a
What is identifiers in c with examples?
Are comments included during the compilation stage and placed in the EXE file as well?
What does p mean in physics?
What is dynamic dispatch in c++?
What is pre-emptive data structure and explain it with example?
Why is c so popular?
What are the different data types in C?
Write a C/C++ program that connects to a MySQL server and checks if the InnoDB plug-in is installed on it. If so, your program should print the maximum number of concurrent threads that the InnoDB plug-in can create.
How can I rethow can I return a sequence of random numbers which dont repeat at all?
When should structures be passed by values or by references?