编程札记

C

C闰年计划示例

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

C实例 找正数或负数

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

C实例 找奇数或偶数程序

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

C实例 比较三个整数

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

C实例 比较两个整数

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

C实例 除法操作

C实例 除法操作 #include <stdio.h> int main() { int op1, op2, div; // variable declaration op1 = 6; // variable definition op2 = 3; div = 6 / 3; // division operation printf("Output of %d divide by %d is %d", op1, op2, div); }

阅读全文 ↗
C

C实例 乘法操作

C实例 乘法操作 #include <stdio.h> int main() { int op1, op2, mul; // variable declaration op1 = 5; // variable definition op2 = 3; mul = op1 * op2; // multiplication operation printf("Output of %d multiplied by %d is %d", op1, op2, mul); }

阅读全文 ↗
C

C实例 减法操作

C实例 减法操作 #include <stdio.h> int main() { int op1, op2, sub; // variable declaration op1 = 5; // variable definition op2 = 3; sub = op1 - op2; // subtraction operation printf("Output of %d − %d is %d", op1, op2, sub); }

阅读全文 ↗
C

C实例 加法操作

C实例 加法操作 #include <stdio.h> int main() { int op1, op2, sum; // variable declaration op1 = 5; // variable definition op2 = 3; sum = op1 + op2; // addition operation printf("sum of %d and %d is %d", op1, op2, sum); }

阅读全文 ↗
C

C实例 双精度变量

C实例 双精度变量 #include <stdio.h> int main() { double d; // double precision variable declaration d = 12.001234; // defining double precision variable printf("value of d is %e", d); return 0; }

阅读全文 ↗
C

C实例 浮点变量

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

C实例 数字变量

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; }

阅读全文 ↗