Monday, July 31, 2017

Find triangular no. in C

#include<stdio.h>
void main()
{
    int n1,n2,i,t;
    printf("Enter two numbers : ");
    scanf("%d%d",&n1,&n2);
    for(i=1;i<=n2;i++)
    {
        t = i*(i+1)/2;
        if(t>=n1 && t<=n2)
        {
            printf("%d ",t);
        }
    }
    getch();
}

0 comments:

Post a Comment