why appear random number at the end

+2 votes
asked Oct 17 by E Alkindi (140 points)
int main()
 {  
   int calclus, fyear ;
  do{
      printf (" enter first year\n");
      scanf ("%d" , &fyear);

     
     if (((fyear % 4 == 0) && (fyear % 100!= 0)) || (fyear%400 == 0))
      printf("%d is  a leap year", &fyear);
     else
      printf( "%d is  not a leap year", &fyear);
  }while (fyear < 999 );
 

   return 0;
}

1 Answer

0 votes
answered Oct 21 by LiOS (5,280 points)
In printf, you only reference the variable, not the address of the variable i.e. fyear not &fyear.

#include <stdio.h>

int main(){
    
    int calclus, fyear;
    
    do{
        printf (" enter first year\n");
        scanf ("%d" , &fyear);
        
        if (((fyear % 4 == 0) && (fyear % 100!= 0)) || (fyear%400 == 0))
            printf("%d is  a leap year", fyear);
        else
            printf( "%d is  not a leap year", fyear);
    }
    while(fyear < 999);
    
    return 0;
}
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...