TRIANGULAR NUMBER OR NOT

Consider the following I/O samples.



SAMPLE INPUT: 10

SAMPLE OUTPUT:  TRIANGULAR NUMBER


The TRIANGULAR NUMBER sequence is the representation of the numbers in the
 form of equilateral triangle arranged in a series or sequence. These numbers are in a 
 sequence of 1, 3, 6, 10, 15, 21, 28, 36, 45, and so on.



                 



C PROGRAM:

#include <stdio.h>

int main()

{

    int num,i,flag=0;

    scanf("%d",&num);

    for(i=1;i<=num/2+1;i++)

    {

        if((i*(i+1))/2 == num)
        
        {
            
            flag=1;
            
            break;
            
        }

    }

    if(flag == 1)

        printf("TRIANGULAR NUMBER");

    else

        printf("NOT A TRIANGULAR NUMBER");
        
    return 0;

    
}




OUTPUT:


                 




The given source code in C program "FOR TRIANGULAR NUMBER OR NOT" is short and simple to understand. The source code is well tested in DEV-C++ and is completely error free. 
If you have any feedback about this article and want to improve this, please comment in the comment section.


Comments

Popular posts from this blog

INVERTED PYRAMID STAR PATTERN

C PROGRAM TO PRINT ALL LEAP YEARS IN A GIVEN RANGE

C PROGRAM TO PRINT THE REMAINING DAYS AND COMPLETED DAYS FROM A GIVEN DATE