Skip to main content
added 3 characters in body
Source Link

i wrote the following code in orde to get familiar with the while loop However , instead of executing the loop when i give a number lower than 1 it does the exact opposite !it executes the loops and prints "you gave a negative number " when i input a number higher than 1. Can someone explain me why is this happening . Below is the code

int main() { int x =0; printf("Enter a postive number : "); scanf("%d" ,&x); printf("%d", &x); while (x < 1); { printf("you gave a negative number please try again: " ); } }

    int main()
{
 int x =0;
        printf("Enter a postive number : ");
        scanf("%d" ,&x);
        printf("%d", &x);
         while (x < 1);
         {
             printf("you gave a negative number please try  again: " );
         }
}

i wrote the following code in orde to get familiar with the while loop However , instead of executing the loop when i give a number lower than 1 it does the exact opposite !it executes the loops and prints "you gave a negative number " when i input a number higher than 1. Can someone explain me why is this happening . Below is the code

int main() { int x =0; printf("Enter a postive number : "); scanf("%d" ,&x); printf("%d", &x); while (x < 1); { printf("you gave a negative number please try again: " ); } }

i wrote the following code in orde to get familiar with the while loop However , instead of executing the loop when i give a number lower than 1 it does the exact opposite !it executes the loops and prints "you gave a negative number " when i input a number higher than 1. Can someone explain me why is this happening . Below is the code

    int main()
{
 int x =0;
        printf("Enter a postive number : ");
        scanf("%d" ,&x);
        printf("%d", &x);
         while (x < 1);
         {
             printf("you gave a negative number please try  again: " );
         }
}
Source Link

my while loop is not working

i wrote the following code in orde to get familiar with the while loop However , instead of executing the loop when i give a number lower than 1 it does the exact opposite !it executes the loops and prints "you gave a negative number " when i input a number higher than 1. Can someone explain me why is this happening . Below is the code

int main() { int x =0; printf("Enter a postive number : "); scanf("%d" ,&x); printf("%d", &x); while (x < 1); { printf("you gave a negative number please try again: " ); } }