Menu

For loop problem

Sevko
2009-11-26
2012-09-26
  • Sevko

    Sevko - 2009-11-26

    include <stdio.h>

    include <stdlib.h>

    include <math.h>

    include <dos.h>

    int main(){
    float a, b, c, i=0;
    for(a =1;a <= 1000; a=a+0.1){
    for(b=1; b>0; b=b+0.1){
    if(i=1){
    i=0;
    break;
    }
    for(c; c>0; c+=0.1){
    if((cc)==((aa)+(b*b))){
    printf("%f\n", c);
    sleep(2);
    i++;
    break;
    }

    }
    }
    }

    system("PAUSE"); return 0; }

    This is supposed to find the pythagorean triples to the number 1000. But the
    program doesn't outputanything it just runs and ends. What did I do wrong?(And
    now thta i look at the code i could just put a goto start;)

     
  • Sevko

    Sevko - 2009-11-26

    changed dos.h to windows.h and sleep into upper case

     
  • Sevko

    Sevko - 2009-11-26

    and the 2 in Sleep to 2000

     
  • cpns

    cpns - 2009-11-26

    The variable c never gets initialised. Initialise it in the first
    expression of the for statement thus:

    for( c = 0; c > 0; c += 0.1 )

    Note that this code does not depend on math.h.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.