You are on page 1of 12

202152336_lab 6

Q.1 - Program to print stars Sequences (right triangular,


Isosceles triangle, etc.).
(A) For RIGHT TRIANGULAR:
Sol. Algorithm:-

Step 1 – START

Step 2 – Declare integer I,j and rows.

Step 3 – Ask the user to input the value of rows.

Step 4 – execute 1st loop , put a condition i<=rows and updating i++.

Step 5 — execute 2nd loop , put a condition j<=i and updating j++.

Step 6—print : * and exit 2nd loop.

Step 7— print new line(\n).

Step 8—STOP.
FLOWCHART:-

START

Declare integer i, j and rows.

Ask the user to input


the value of rows.

execute 1st loop , put a condition


i<=rows and updating i++.

execute 2nd loop , put a


condition j<=i and updating
j++.

print : * and exit 2nd


loop.

print new
line(\n).

STOP.
Source code :--
#include <stdio.h>

void starpattern(int rows)


{
int i,j;
for (i=1; i<=rows; i++)
{
for (j=1; j<=i; j++)
printf("*");
printf("\n");
}
}

int main ()
{
int rows;
printf("how many rows do want in this shape \n");
scanf("%d",&rows);
starpattern(rows);

return 0;
}
OUTPUT:-
(B) For ISOSCELES TRIANGLE:
Sol. Algorithm:-

Step 1 – START

Step 2 – Declare integer I,j and rows.

Step 3 – Ask the user to input the value of rows.

Step 4 – execute 1st loop , put a condition i<=rows and updating i++.

Step 5 — execute 2nd loop , put a condition j<=rows and updating j++.

Step 6—print : blank space ( ) and exit 2 nd loop.

Step 7— execute 3rd loop, put condition j<=((2*i)-1) and updating ++j.

Step 8— print : * and exit 3rd loop .

Step 9— print new line(\n) and exit 1st loop.

Step 10—STOP.

FLOWCHART:-
START
Declare integer i, j and rows.

Ask the user to input


the value of rows.

execute 1st loop , put a condition


i<=rows and updating i++.

execute 2nd loop , put a


condition j<=rows and
updating j++.

print : blank space ( )


and exit 2nd loop.

execute 3rd loop, put


condition j<=((2*i)-1)

print : * and exit 3rd loop


.

print new line(\n)


and exit 1st loop.

Source code :-- STOP.

#include <stdio.h>
void starpattern(int rows)
{
int i,j;
for (i=1; i<=rows; i++)
{
for (j=i; j<=rows; ++j)
{
printf(" ");
}

for (j=1; j <=((2*i)-1); ++j)


{
printf("*");
}
printf("\n");
}
}
int main()
{
int rows;
printf("how many do you want rows in this shape\n");
scanf("%d",&rows);
starpattern(rows);
return 0;
}
OUTPUT:-
Q.2 -Program to print Fibonacci series up to 100.

Sol. Algorithm:-

Step 1 – START

Step 2 – Declare integer x=0,y=1,I and z.

Step 3 – Now Print the Fibonacci series up to 100.

Step 4 – execute 1st loop, i=1 and put condition i<=12, updating i++.

Step 5 –print value of x , z=x+y, x=y and y=z.

Step 6 –Exit loop.

Step 7—STOP.
START
FLOWCHART:-

Declare integer x=0,y=1,I and


z.

Now Print the


Fibonacci series up to

execute 1st loop, i=1 and put


condition i<=12, updating i++.

print value of x , z=x+y, x=y


and y=z.

Exit loop.

STOP.
Source code :--
#include <stdio.h>

int main()
{
int x=0,y=1,i,z;

printf("x=%d\ty=%d\n",x,y);
printf("Print Fibonacci series up to 100:-\n");
for(i=1;i<=12;i++)
{
printf("%d\n",x);
z=x+y;
x=y;
y=z;
}

return 0;
}
OUTPUT:-

You might also like