Home > database >  Why does this while loop print a number two times at the start?
Why does this while loop print a number two times at the start?

Time:02-13

#include<stdio.h>
int main(long int argc, char const *argv[])
{
    short int a, i;
    scanf("%hd", &a);
    while (a!=5) {
        printf("%hd\n",a);
        a  ;
    }
    return 0;
}

For some reason, it shows the output:

1
1
2
3
4

But why?

CodePudding user response:

I think the first "1" is your input.
I tried to run the same code and that is what I observed the first "1" is the input I gave and then the code prints from 1 to 4.

CodePudding user response:

@Red Sky is right, the first one is your input, Please take a look

  •  Tags:  
  • c
  • Related