You are on page 1of 4

1a.

i)Statement:
Writing a C programme to draw the following pattarn using while loop-
*
*
*
*
*
ii)Code:
#include<stdio.h>
int main()
{
int n,i=0;
printf("enter a number:");
scanf("%d",&n);
while(i<n){
printf("*\n");
i++;
}
return 0;

iii)Output:

iv)Discussion:
From the statement it is clear that, n numbers of stars(*) will be printed and each star
will print in new line.To creat this pattern we used a print statement in a while loop.
1b.
i)Statement:
Write a C programme to draw the following pattern-
*
**
***
****
ii)Code:

#include<stdio.h>
int main()
{
int n,i=0,j;
printf("enter a number:");
scanf("%d",&n);
while(i<n){
j=0;
while(j<=i){
printf("*");
j++;
}
i++;
printf("\n");
}
return 0;

iv)Output:

v)Discussion:
From the triangular pattern we can see that, the input number indicates the the total line to be
printed and another thing is in each line the number of stars is equals to the line number as the 3rd line
has 3 stars and 4th line has 4 stars.
To draw theis pattern I used two while loop.The 1st while loop creats a new line after printing
the stars and the 2nd while loop is used for printing the stars in a line.
1c.
i)Statement:
Drawing the following pattern using C program -
*
***
*****
*******
ii)Code:

#include<stdio.h>
int main()
{
int n,i=0,j,a,b=1;
printf("enter a number:");
scanf("%d",&n);
a=n;
while(i<n){
j=1;
while(j<a){
printf(" ");
j++;
}
j=0;
while(j<b){
printf("*");
j++;
}
a--;
b+=2;
i++;
printf("\n");
}
return 0;

iii)Output:
iv)Discussion:
From the pattern we can see two triangular shapes, the first one is made of ‘space’ and the
second one is of ‘*’. The input number indicates the total row or lines in the pattern.It is clear that the
‘space’ decreases by a number in every line and the ‘*’ increases by 2.
To draw this pattern I used 3 while loop . The 1st loop used for creating new line and decreases
the variable of 2nd loop to decrease the number of space again the loop increases the variable of 3rd loop
by two to increase the number of printed stars ‘*’. The 2nd loop print the ‘space’ and decreases by one
after completing every line and it’s initial printing is just one less than the input n.The 3 rd loop was
used for printing the stars’*’ .

You might also like