0
#include <stdio.h>
#include <stdlib.h>

int main(void) {
    int num;
    printf("Enter a Number");`scanf`
    scanf("%d",&num);
    if(num<0){
        printf("Number is negative");
    }else{
        printf("Number is Positive");
    }
    return EXIT_SUCCESS;
}

This was my code.

But when I run this the first printf "Enter a number " is not showing. Even without showing that, I entered a number. then I press the enter key. Then it is showing "Enter a NumberNumber is Positive" both the printf.

Anyone can help me?? please!!!!

kaylum
  • 11,347
  • 2
  • 20
  • 29
  • Does this answer your question? [Why does printf not flush after the call unless a newline is in the format string?](https://stackoverflow.com/questions/1716296/why-does-printf-not-flush-after-the-call-unless-a-newline-is-in-the-format-strin) – kaylum Jan 01 '21 at 05:04
  • `stdout` is line buffered by default. That means `printf` will not actually output until there is a newline in the string or an explicit `fflush` is called. – kaylum Jan 01 '21 at 05:05
  • Why is there a chunk of scanf immediately after `printf("Enter a Number");`? – KaiserKatze Jan 01 '21 at 06:06
  • Why do you use scanf 2 times to read the number ? – MED LDN Jan 01 '21 at 09:25

0 Answers0