C闰年计划示例 #include <stdio.h> int main() { int year; year = 2016; if (((year % 4 == 0) && (year % 100!= 0)) || (year%400 == 0)) printf("%d is a leap year", year); else printf("%d is not a leap year", year); return 0; }
C实例 找正数或负数 #include <stdio.h> int main() { int number = -2; if (number >= 0) printf("%d is positive\n", number); else printf("%d is negative\n", number); return 0; }
C实例 找奇数或偶数程序 #include <stdio.h> int main() { int even = 24; int odd = 31; if (even % 2 == 0) printf("%d is even\n", even); if (odd % 2 != 0 ) printf("%d is odd\n", odd); return 0; }
C实例 比较三个整数 #include <stdio.h> int main() { int a, b, c; a = 11; b = 22; c = 33; if ( a > b && a > c ) printf("%d is the largest.", a); else if ( b > a && b > c ) printf("%d is the largest.", b); else if ( c > a && c > b ) printf("%d is the largest.", c); else printf("Values are not unique"); return 0; }
C实例 比较两个整数 #include <stdio.h> int main() { int a, b; a = 11; b = 99; // to take values from user input uncomment the below lines − // printf("Enter value for A :"); // scanf("%d", &a); // printf("Enter value for B :"); // scanf("%d", &b); if(a > b) printf("a is greater than b"); else printf("a is not greater than b"); return 0; }
C实例 浮点变量 #include <stdio.h> int main() { float f; // floating point variable declaration f = 12.001234; // defining float variable printf("value of f is %f", f); return 0; }
C实例 数字变量 #include <stdio.h> int main() { int i; // integer variable declaration i = 123; // defining integer variable printf("value of i is %d", i); return 0; }