Вопрос

So I had to write a program that used the Pythagorean Threes concept where if you entered a number it would give you all the combinations less than that number that would produce a correct a^2 + b^2 = c^2 output.

Not sure if I explained the assignment well, but basically I understand the logic or at least I think I do I was wondering if you guys could help me find out why I am getting this error....

For the last line of my code it gives me, "warning: control reaches end of non-void function [-Wreturn-type]," As the error any idea what I am doing wrong?

#include <stdio.h>

int main(void){

int x = 0, y = 0, z = 0, n;
int count = 0;

printf("Please Enter A Positive Integer: \n");
scanf("%d", &n);

while(z <= n){
        while(y < z){
                while(x < y){
                        if(x * x + y * y == z * z)
                                printf("%d: \t%d %d %d\n", ++count, x, y, z);      
        x += 1;         }
        y += 1; }
        z += 1;
        }
}
Это было полезно?

Решение

int main(void){

Your function header indicates that you're looking to return an int. To fix this, return a number (0 usually indicates a normal termination) at the end of your function.

To break it down a little,

  • int indicates the return type,
  • main is the method name, and
  • void indicates that there are no parameters for this method.

Другие советы

Your main function is declared to return an int, but you don't return anything.

put return 0; before the closing brace of your main.

int main( void )
{
    // ... code ...
    return 0;
}
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top