小宝的第三章2
#include<stdio.h> int main(void) { double valuel,value2; char op; printf("Type in an expression:"); scanf("%lf%c%lf",&valuel,&op,&value2); if(op=='+') printf("=%.2f\n",valuel+value2); else if(op=='-') printf("=%.2f\n",valuel-value2); else if(op=='*') printf("=%.2f\n",valuel*value2); else if(op=='/') if(value2!=0) printf("=%.2f\n",valuel/value2); else printf("Divisor can not be 0!\n"); else printf("Unknown operator!\n"); return 0; }
#include<stdio.h> int main(void) { int blank,digit,other; char ch; int i; blank=digit=other=0; printf("Enter 10 characters:"); for(i=1;i<=10;i++){ ch=getchar(); switch(ch){ case' ': case'\n': blank++; break; case'0':case'1':case'2':case'3':case'4': case'5':case'6':case'7':case'8':case'9': digit++; break; default: other++; break; } } printf("blank=%d,digit=%d,other=%d\n",blank,digit,other); return 0; }
#include<stdio.h> int main(void) { double valuel,value2; char op; printf("Type in an expression:"); scanf("%lf%c%lf",&valuel,&op,&value2); switch(op){ case'+': printf("=%.2f\n",valuel+value2); break; case'-': printf("=%.2f\n",valuel-value2); break; case'*': printf("=%.2f\n",valuel*value2); break; case '/': printf("=%.2f\n",valuel/value2); break; default: printf("Unknown operator\n"); break; } return 0; }