#include <stdio.h> #include <stdlib.h> int main(){ int f,x,s,y,t,l,year,sum; f=year/1000; x=year%1000; s=x/100; y=x%100; t=y/10; l=y%10; sum=f+s+t+l; printf("Enter a Year:"); scanf("%d",&year); if (year%4==0){ printf("Leap,%d",sum); } else if (year%400==0){ printf("Leap,%d",sum); } else if (year%100==0){ printf("Regular,%d",sum); } else {printf("Regular,%d",sum);} return 0; } Obejective: Input a 4 digit year using stdin (scanf). Display whether it is a leap year or not. If it is a leap year, display - Leap,sum of digits of year. If not a leap year, display - Regular,sum of digits of year.
Its giving correct output for leap year but not the sum of the digits
main()and evaluates one statement after the other. (Simply speaking, startup routine, signals, interrupts, multithreading, stack unwinding .... ignored). Ignoring the return value ofscanf()is a programming error.