Class 9th CBSE

Q.5 Write a C program to print Floyd’s triangle.

Program-5

Q.5 Write a C program to print triangle.

Solution  :- 

#include<stdio.h>
#include<conio.h>
void main()
{
int i, j, N;
 
    printf(“Enter N: “);
    scanf(“%d”, &N);
 
    for(i=1; i<=N; i++)
    {
        // Logic to print numbers
        for(j=1; j<=i; j++)
        {
            printf(“%d”, j);
        }
 
        printf(“\n”);
    }
 
}
getch();
}

Q.5 Write a C program to print triangle. Flow Chart

Solution  :- 

 

Q.5 Write a C program to print triangle. Algorithm

Solution  :- 

1. Start
2. Initialize two variables, ‘row’ and ‘num’, to 1.
3. While ‘row’ is less than or equal to 5 (the number of rows in the pattern):
a. Initialize ‘num’ to 1.
b. While ‘num’ is less than or equal to ‘row’:
i. Print ‘num’ followed by a space.
ii. Increment ‘num’ by 1.
c. Print a new line.
d. Increment ‘row’ by 1.
4. End

Fun & Easy to follow
Works on all devices
Your own Pace
Super Affordable

Popular Videos

Play Video

UX for Teams

Learn the basics and a bit beyond to improve your backend dev skills.

ava4.png
Chris Matthews

Designer

Play Video

SEO & Instagram

Learn the basics and a bit beyond to improve your backend dev skills.

ava4.png
Chris Matthews

Designer