标签:
留念 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***\n"); printf("the author is xiaobo\n"); printf("No.1 add\n"); printf("No.2 sub\n"); printf("No.3 multiply\n"); printf("No.4 divide\n"); printf("No.5 yushu\n"); printf("No.6 jiecheng\n"); printf("No.7 liejia\n"); printf("No.8 jiechengleijia\n"); printf("No.0 exit\n"); 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\n"); scanf("%lg%lg",&num1,&num2); sum =num1+num2; printf("sum is %lg\n",sum);} void sub() { double num1,num2; double sum; printf("Please Input 2 numbers to sub\n"); scanf("%lg%lg",&num1,&num2); sum =num1-num2; printf("the result is %lg\n",sum);} void multiply() { double num1,num2; double sum; printf("Please Input 2 numbers to multiply\n"); scanf("%lg%lg",&num1,&num2); sum =num1*num2; printf("the result is %lg\n",sum);} void divide() { double num1,num2; double sum; printf("Please Input 2 numbers to divide\n"); scanf("%lg%lg",&num1,&num2); sum =num1/num2; printf("the result is %lg\n",sum);} //http://www.cnblogs.com/xiaobo-Linux/ QQ463431476 void yushu() {int num1,num2; int sum; printf("please Input 2 numbers for yushu\n"); scanf("%ld",&num1,&num2); sum =num1%num2; printf("yushu is %ld\n",sum); } void jiecheng() {double i,j=1; double sum=1; printf("Please Input a integer number for jiecheng\n"); scanf("%lg",&i); for(;j<i;j++) {sum *=j;} sum *=i; printf("the result is %lg\n",sum);} void leijia() {double n; double sum=0; printf("please input any number more than 0, with less than 0 number to end\n"); for(n=0;n>=0;) {sum +=n; scanf("%lg",&n);} printf("the result is %lg\n",sum); } void jiechengleijia() { int i,a[5]; long j,k=1,sum=0; printf("please input any 5 integer numbers\n"); 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("\nthe sum is %ld\n",sum); } /* 2014 /12. 25 做 */ |
标签:
原文地址:http://www.cnblogs.com/xiaobo-Linux/p/5052107.html