Ex.No:3e Triangle Of Numbers

AIM:

        To write a c program to print triangle of numbers.

ALGORITHM:

Step 1: Start the program.

Step 2: Declare the variables i,j,k,l and n as “int” datatype.

Step 3: Read  N numbers of lines in a triangle.

Step 4: Initialize l=1.

Step 5: for i=1,j=n-i to less than or equal to n.

Step 5.1: for k=1, to less than or equal to j print “ ”.

Step 5.2: for k=1, to less than or equal to 1 print “i ”.

Step 5.3: l is incremented by 2.

Step 6: Stop the program.

PROGRAM CODE:
#include<stdio.h>
void main()
{
    int i,j,k,l,n;
    clrscr();
    printf("n  type n-no of lines in triangle:");
    scanf("%d",&n);
    l=1;
    for(i=1,j=n-i;i<=n;i++,j--)
    {
        for(k=1;k<=j;k++)
        printf("   ");
        for(k=1;k<=l;k++)
        printf("  %d",i);
        printf("n");
        l+=2;
    }
    getch();
}
OUTPUT:

print

RESULT:

                    Thus the c program to print triangle of numbers is written and executed successfully.

Leave a Reply

Your email address will not be published. Required fields are marked *