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 pointers? What are stacks and queues?
explain what are actual arguments?
What is a pragma?
What is FIFO?
Write a code to achieve inter processor communication (mutual exclusion implementation pseudo code)?
What are data structures in c and how to use them?
Explain what is the stack?
Which is more efficient, a switch statement or an if else chain?
Array is an lvalue or not?
How can I call fortran?
how can I convert a string to a number?
What is the use of function in c?
Are enumerations really portable?
Describe wild pointers in c?
GIVEN A FLOATING POINT NUMBER HOW IS IT ACTUALLY STORED IN MEMORY ? CAN ANYONE EXPLAIN?? THE 32 BIT REPRESENTATION OF A FLOATING POINT NUMBER ALLOTS: 1 BIT-SIGN 8 BITS-EXPONENT 23 BITS-MANTISSA