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 are the general description for loop statement and available loop types in c?
What does c mean?
If a five digit number is input through the keyboard, write a program to print a new number by adding one to each of its digits.For example if the number that is input is 12391 then the output should be displayed as 23402
What is typedef example?
Explain the difference between malloc() and calloc() in c?
What is FIFO?
What are Macros? What are its advantages and disadvantages?
What are different types of pointers?
Write a program to identify if a given binary tree is balanced or not.
What is the behavioral difference when include header file in double quotes (“”) and angular braces (<>)?
What is a global variable in c?
What are the advantages of external class?
What is the use of pragma in embedded c?
How many levels of pointers can you have?
What are unions in c?