C Program to Check Whether a Number is Triangular or Not

#include<stdio.h>
#include<conio.h>

int main()
{
	 int number, i, sum=0;
	 clrscr();
	 printf("Enter number: ");
	 scanf("%d", &number);
	
	 for(i=0;i < number; i++)
	 {
	  sum = sum+i;
	
	  if(sum == number)
	  {
	   printf("%d is TRIANGULAR NUMBER.", number);
	   break;
	  }
	 }
	
	 if(number == i)
	 {
	  printf("%d is NOT TRIANGULAR NUMBER.", number);
	 }
	 getch();
	 return(0);
}

Output 

Run 1:
------------
Enter number: 15 ↲
15 is TRIANGULAR NUMBER.

Run 2:
------------
Enter number: 155 ↲
155 is NOT TRIANGULAR NUMBER.

Run 3:
------------
Enter number: 153 ↲
153 is TRIANGULAR NUMBER.

Run 4:
------------
Enter number: 276 ↲
276 is TRIANGULAR NUMBER.

Leave a Reply

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

https://atozonlinesolutions.com/wp-content/uploads/2017/03/logo_white.png
https://atozonlinesolutions.com/wp-content/uploads/2017/03/logo_white.png
About
Products
Subscribe

If you wish to receive our latest news in your email box, just subscribe to our newsletter. We won’t spam you, we promise!

    Applauz

    As the pioneer of the lean startup movement, APPLAUZ has dedicated it’s time to sharing effective business strategies that help new businesses and enterpreneurs put their money to work in the right way.

    Subscribe

    If you wish to receive our latest news in your email box, just subscribe to our newsletter. We won’t spam you, we promise!

      Applauz

      As the pioneer of the lean startup movement, APPLAUZ has dedicated it’s time to sharing effective business strategies that help new businesses and enterpreneurs put their money to work in the right way.

      Copyright by BOLD THEMES. All rights reserved.