留念 C语言第一课简单的计算器制作
学C语言这么久了。 /* 留念 C语言第一课简单的计算器制作 */
#include<stdio.h> #include<stdlib.h>
#include<conio.h>void displayMenu(); /*赵存档做*/ void add(); void sub(); void multiply(); void divide(); void yushu(); void jiecheng(); void leijia(); void jiechengleijia(); int main(int n) {do {system("color 2e"); system("cls"); displayMenu(); system("pause");} while(n);} int n; void displayMenu() { printf("***welcome to use simple calculator*** "); printf("the author is xiaobo "); printf("No.1 add "); printf("No.2 sub "); printf("No.3 multiply "); printf("No.4 divide "); printf("No.5 yushu "); printf("No.6 jiecheng "); printf("No.7 liejia "); printf("No.8 jiechengleijia "); printf("No.0 exit "); scanf("%d",&n); switch(n) { case 1:add(); break; case 2:sub(); break; case 3:multiply(); break; case 4:divide(); break; case 5:yushu(); break; case 6:jiecheng(); break; case 7:leijia(); break; case 8:jiechengleijia();break; case 0:exit(0);return;} } void add() { double num1,num2; double sum; printf("Please Input 2 numbers to add "); scanf("%lg%lg",&num1,&num2); sum =num1+num2; printf("sum is %lg ",sum);} void sub() { double num1,num2; double sum; printf("Please Input 2 numbers to sub "); scanf("%lg%lg",&num1,&num2); sum =num1-num2; printf("the result is %lg ",sum);} void multiply() { double num1,num2; double sum; printf("Please Input 2 numbers to multiply "); scanf("%lg%lg",&num1,&num2); sum =num1*num2; printf("the result is %lg ",sum);} void divide() { double num1,num2; double sum; printf("Please Input 2 numbers to divide "); scanf("%lg%lg",&num1,&num2); sum =num1/num2; printf("the result is %lg ",sum);} //http://www.cnblogs.com/xiaobo-Linux/ QQ463431476 void yushu() {int num1,num2; int sum; printf("please Input 2 numbers for yushu "); scanf("%ld",&num1,&num2); sum =num1%num2; printf("yushu is %ld ",sum); } void jiecheng() {double i,j=1; double sum=1; printf("Please Input a integer number for jiecheng "); scanf("%lg",&i); for(;j<i;j++) {sum *=j;} sum *=i; printf("the result is %lg ",sum);} void leijia() {double n; double sum=0; printf("please input any number more than 0, with less than 0 number to end "); for(n=0;n>=0;) {sum +=n; scanf("%lg",&n);} printf("the result is %lg ",sum); } void jiechengleijia() { int i,a[5]; long j,k=1,sum=0; printf("please input any 5 integer numbers "); for(i=0;i<5;i++) {scanf("%d",&a[i]); for(j=a[i];j>=1;j--) {k =k*j;} sum +=k; k=1;} printf(" the sum is %ld ",sum); } /* 2014 /12. 25赵存档 QQ463431476 做 */ |