Simple While Cycles

Asked

Viewed 43 times

1

#include <stdio.h>

main(){

    int cont=15;
    while(cont<=200){
        printf("%d\n",&cont);
        cont++;     
    }
}

Supposedly the counter should start with the value 15 and go showing its value by adding 1 at the end of each cycle. But when I run the program shows only 2293324 on all lines... I already tried to add another variable to make the square and it remains the same.

1 answer

2

Remove & of this line printf("%d\n",&cont);:

Code:

#include <stdio.h>

int main(void) {
    int cont=15;
    while(cont<=200){
        printf("%d\n",cont);
        cont++;     
    }
    return 0;
}

Online Example

  • Ok, I get it, & only fits the variables inside the scanf... Thanks for the help.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.