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
How do I determine whether a character is numeric, alphabetic, and so on?
Explain what does it mean when a pointer is used in an if statement?
Is it cc or c in a letter?
What are the disadvantages of external storage class?
What are the different types of constants?
typedef struct{ char *; nodeptr next; } * nodeptr ; What does nodeptr stand for?
Write a program to swap two numbers without using the third variable?
How would you obtain the current time and difference between two times?
How can I change their mode to binary?
What is the use of ?: Operator?
Can a file other than a .h file be included with #include?
Difference between pass by reference and pass by value?
What is console in c language?
What is the purpose of void in c?
What is meant by int main ()?