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


Please Help Members By Posting Answers For Below Questions

How do I determine whether a character is numeric, alphabetic, and so on?

618


Explain what does it mean when a pointer is used in an if statement?

613


Is it cc or c in a letter?

556


What are the disadvantages of external storage class?

584


What are the different types of constants?

636






typedef struct{ char *; nodeptr next; } * nodeptr ; What does nodeptr stand for?

1066


Write a program to swap two numbers without using the third variable?

591


How would you obtain the current time and difference between two times?

719


How can I change their mode to binary?

687


What is the use of ?: Operator?

660


Can a file other than a .h file be included with #include?

679


Difference between pass by reference and pass by value?

651


What is console in c language?

599


What is the purpose of void in c?

615


What is meant by int main ()?

714