Watson95 - 1 year ago 80

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);

}

Recommended for you: Get network issues from **WhatsUp Gold**. **Not end users.**

Recommended from our users: **Dynamic Network Monitoring from WhatsUp Gold from IPSwitch**. ** Free Download**