C Program to Input Number by the user between 1-100

How to write a C Program to Input Number by the user between 1-100 ?


  1. #include <stdio.h>
  2.  
  3. int main (void){
  4. int n=53;
  5. int a;
  6. int i;
  7. for (i=0; i<5 && a!=n; i++){
  8.         printf("Enter number between 1-100: ");
  9.         scanf("%d", &a);
  10.         if (a<0 || a>100){
  11.                 printf("Number invalid, please enter a number between 1-100: \n");
  12.         }
  13.         else if (a=n){
  14.                 printf("You guessed the number correctly!\n");
  15.         }
  16.         else if (a<n){
  17.                 printf("Number is too low, try again.\n");
  18.         }
  19.         else if (a>n){
  20.                 printf("Number is too high, try again.\n");
  21.         }
  22.         }
  23.         if (i=5){
  24.                 printf("You're a loser.");
  25.         }
  26. }


Learn More :