#include<stdio.h>intmain(){int a, b, c, d, res;printf("Input a/b, c/d:");scanf("%d/%d,%d/%d",&a,&b,&c,&d);
res = a * d - b * c;if(res >0)printf("%d/%d>%d/%d\n", a, b, c, d);elseif(res <0)printf("%d/%d<%d/%d\n", a, b, c, d);elseprintf("%d/%d=%d/%d\n", a, b, c, d);return0;}
#include<stdio.h>#include<math.h>intmain(){float A, B, compete, standard;printf("Input percent of A and B:");scanf("%f%f",&A,&B);
compete = A *10+ B *6;
standard = A *8+ B *10;printf("compete = %.4f\nstandard = %.4f\n", compete, standard);if(compete > standard)printf("The Best Response is compete!");elseprintf("The Best Response is standard!");return0;}
1 检测用户错误输入
#include<stdio.h>#include<math.h>intmain(){int a, b, t;if(scanf("%d %d",&a,&b)==2)printf("a = %d, b = %d\n", a, b);elseprintf("Input error!");return0;}
2 闰年判断
#include<stdio.h>intmain(){int year;scanf("%d",&year);if(year >=1){if(year %4==0&& year %100!=0|| year %400==0)printf("Yes\n");elseprintf("No\n");}elseprintf("Input error!\n");return0;}
#include<stdio.h>intmain(){char ch;printf("Input simple:\n");scanf("%c",&ch);if((ch >='a'&& ch <='z')||(ch >='A'&& ch <='Z'))printf("It is an English character.\n");elseif(ch >='0'&& ch <='9')printf("It is a digit character.\n");elseprintf("It is other character.\n");return0;}
#include<stdio.h>intmain(){int n, a, b;printf("Please input n:\n");scanf("%d",&n);
a = n /100;
b = n %100;printf("%d,%d\n", a, b);printf("sum=%d,sub=%d,multi=%d\n", a + b, a - b, a * b);if(b !=0)printf("dev=%.2f,mod=%d\n",(float)a / b, a % b);elseprintf("The second operator is zero!\n");return0;}
#include<stdio.h>intmain(){int n;printf("Please enter the number:\n");scanf("%d",&n);if(n <=0|| n >=10000)printf("error!\n");elseif(n >=1000)printf("%d: 1000-9999\n", n);elseif(n >=100)printf("%d: 100-999\n", n);elseif(n >=10)printf("%d: 10-99\n", n);elseprintf("%d: 0-9\n", n);return0;}
9 计算一元二次方程的根v2.0
#include<stdio.h>#include<math.h>#define EPS 1e-6main(){float a, b, c, disc, p, q;printf("Please enter the coefficients a,b,c:\n");scanf("%f,%f,%f",&a,&b,&c);if(fabs(a)<= EPS){printf("error!\n");exit(0);}
disc = b * b -4* a * c;if(disc <-EPS){printf("error!\n");}else{
p =- b /(2* a);
q =sqrt(fabs(disc))/(2* a);printf("x1=%7.4f, x2=%7.4f\n", p + q, p - q);}return0;}