Home > Back-end >  Why while loop print a number two time in start
Why while loop print a number two time in start

Time:02-12

#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;
}

There is any reason, It shows 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