Watson95 - 10 months ago 55

C Question

Write isTriangular function, which takes a positive integer and returns 1 if the given number is a triangular number; returns 0, otherwise.

The main function is okay, but there is some errors in "isTriangular" function which i can not see, please help me.Triangular numbers are shown below:

`#include<stdio.h>`

int isTriangular(int N)

{

int sum = 0, n = 0;

for (n; sum <= N; n++)

sum += n;

if (sum == N)

return 1;

else

return 0;

}

int main()

{

int x;

do

{

scanf("%d", &x);

if (x > 0)

{

if (isTriangular(x))

printf("%d is a triangular number\n", x);

else

printf("%d is NOT a triangular number\n", x);

}

}

while (x > 0);

}