范文无忧网范文学习范文大全

C语言程序设计计算器

05月19日 编辑 fanwen51.com

[用C语言编写一个计算薪水的程序]/*工资计算程序*/ #include main() { float originWage; /*应发工资*/ float realWage; /*实发工资*/ float tax; /*所缴税款*/ int i,hour,amount,money; printf("请选择工资种...+阅读

C语言程序设计计算器

#include#include#include#define NULL 0 #define LEN sizeof(struct student) struct student {long num; char name[20]; float s[4]; struct student *next; }; int n; struct student *readin(void) {struct student *head; struct student *p1,*p2; float x,y,z; n=0; p1=(struct student *)malloc(LEN); p2=p1; scanf("%ld%s%f%f%f",&p1->num,p1->name,&x,&y,&z); p1->s[0]=x; p1->s[1]=y; p1->s[2]=z; p1->s[3]=((x+y+z)/3); while(p1->num!=NULL) {n=n+1; if(n==1)head=p1; else {p2->next=p1; p2=p1; } p1=(struct student *)malloc(LEN); scanf("%ld%s%f%f%f",&p1->num,p1->name,&x,&y,&z); p1->s[0]=x; p1->s[1]=y; p1->s[2]=z; p1->s[3]=((x+y+z)/3); } p2->next=NULL; return(head); } struct student *taxis(struct student *x) {struct student *p3,*p4,*p5,*q; int i; p3=x->next; p4=x; for(i=0;inum!=0) {if(p4->s[3]s[3]) {if(p4==x) {q=p3; p4->next=p3->next; p3->next=p4; p3=p4->next; x=q; p5=q; } else {p5->next=p3; p4->next=p3->next; p3->next=p4; p5=p3; p3=p4->next; } } else {if(p4==x) {p5=x; p4=p3; p3=p3->next; q=x; } else {p5=p4; p4=p3; p3=p3->next; } } } p3=x->next; p4=x; } return(q); } struct student *insert(struct student *o) {struct student *pl,*p6,*p7,*p8,*head; float a,b,c; int w=0; printf("input a student data!\n"); pl=(struct student *)malloc(LEN); scanf("%ld%s%f%f%f",&pl->num,pl->name,&a,&b,&c); pl->s[0]=a; pl->s[1]=b; pl->s[2]=c; pl->s[3]=((a+b+c)/3); p6=o; p7=o; p8=o->next; while(p6->num!=0&w!=1) {if(p6->s[3]>pl->s[3]) {if(p6==o) {if(p8->num!=0) {head=p6; p6=o->next; p8=p8->next; } else {head=p6; p6->next=pl; pl->next=0; w=1; } } else {if(p8->num==0) {p6->next=pl; pl->next=0; w=1; } else {p6=p6->next; p7=p7->next; p8=p8->next; } } } else {if(p6==o) {head=pl; pl->next=o; w=1; } else {p7->next=pl; pl->next=p6; w=1; } } } return(head); } void search(struct student *pn) {struct student *p4,*p5; char na[20]; int u=1; p4=pn; p5=pn; printf("please input the name:\n"); scanf("%s",&na); while(strcmp((p4->name),na)!=0&u!=0) {p5=p5->next; p4=p5; if(p5->num==0)u=0; } if(p4->num!=0) printf("%-12ld%s%8.1f%8.1f%8.1f%8.1f\n",p4->num,p4->name,p4->s[0],p4->s[1],p4->s[2],p4->s[3]); else {printf("Please input the right name!\n"); search(pn); } } void save(struct student *ps) {FILE *fp; int i; struct student *p11,*p12; p11=ps; p12=ps; if((fp=fopen("D:\\score.txt","w"))==NULL) {printf("cannot open file\n"); return; } while(p12->num!=0) {fwrite(p11,sizeof(struct student),1,fp); p12=p12->next; p11=p12; } fclose(fp); printf("save in D:\\score.txt!\n"); } extern void show(struct student *x) {struct student *p5; p5=x; if(x!=NULL) do {printf("%-12ld%s%8.1f%8.1f%8.1f%8.1f",p5->num,p5->name,p5->s[0],p5->s[1],p5->s[2],p5->s[3]); p5=p5->next; printf("\n"); } while(p5->num!=0); } #define ONE "input 1 to insert a student data, input 2 to search a student data,\ninput 3 to save all students data, input 4 to printf all, input 0 to exit!\n" void main() {struct student *p,*k,*f; int t; printf("input students'number(Tab)name(Tab)score1(Tab)score2(Tab)score(Enter)\n"); printf("and input 0 0 0 0 0 to end input!\n"); p=readin(); if(n!=1) k=taxis(p); f=k; printf(ONE); scanf("%d",&t); while(t!=0) {if(t==1||t==2||t==3||t==4) {if(t==1)f=insert(f); if(t==2)search(f); if(t==3)save(f); if(t==4)show(f); } else printf("error!\n"); scanf("%d",&t); } getch(); exit(0); } 使用说明: 注意:使用TURBO C++3.0进行编译时候,需要在File\Change Directory 选项将ex保存的路径(ex文件直接放在TC的的下一层,即与Project同层)输入Directory Name 再进行编译.使用File\Open打开文件. 使用WIN-TC可以直接打开就可以编译了.

怎样用C语言设计计算器??

#include int main(void) { double number1 = 0.0; /* First operand value a decimal number */ double number2 = 0.0; /* Second operand value a decimal number */ char operation = 0; /* Operation - must be +, -, *, /, or % */ loop: printf("\nEnter the calculation\n"); scanf("%lf %c %lf", &number1, &operation, &number2); /* Code to check the input goes here */ switch(operation) { case '+': /* No checks necessary for add */ printf("= %lf\n",number1 + number2); break; case '-': /* No checks necessary for subtract */ printf("= %lf\n",number1 - number2); break; case '*': /* No checks necessary for multiply */ printf("=%lf\n",number1 * number2); break; case '/': if(number2 == 0) /* check second operand for zero */ printf("\n\n\aDivision by zero error!\n"); else printf("=%lf\n",number1 / number2); break; case '%': /* Check second operand for zero */ if((long)number2 == 0) printf("\n\n\aDivision by zero error!\n"); else printf("=%ld\n",(long)number1 % (long)number2); break; default: printf("\n\n\aIllegal operation!\n"); break; } goto loop; return 0; }

怎样用VB设计简单计算器

Dim x As String Private Sub Command1_Click() Text1.Text = Text1.Text & "1" End Sub Private Sub Command10_Click() Text1.Text = Text1.Text & "6" End Sub Private Sub Command11_Click() Text1.Text = Text1.Text & "9" End Sub Private Sub Command12_Click() If Label1.Caption = "+" Then Text1.Text = Trim(Str(Val(x) + Val(Text1.Text))) End If If Label1.Caption = "-" Then Text1.Text = Trim(Str(Val(x) - Val(Text1.Text))) End If If Label1.Caption = "*" Then Text1.Text = Trim(Str(Val(x) * Val(Text1.Text))) End If If Label1.Caption = "/" Then If Val(Text1.Text) = 0 Then Text1.Text = "除数不能为零" Else If -1

c程序设计一个简单计算器

#include #include void main(); void jia() { int a,b; printf("print a and b:\ "); scanf("%D%D",&a,&b); printf("a+b=%d\ \ ",a+b); main(); } void jian() { int a,b; printf("print a and b:\ "); scanf("%D%D",&a,&b); printf("a-b=%d\ \ ",a-b); main(); } void cheng() { int a,b; printf("print a and b:"); scanf("%D%D",&a,&b); printf("a*b=%d\ \ ",a*b); main(); } void chu() { double a,b; printf("print a and b:"); scanf("%lf%lf",&a,&b); if (!b){printf("ensure your number!\ ");chu();}; printf("a/b=%5.5f\ \ ",a/b); main(); } void choose() { printf("ensure your number!\ "); main(); } void main() { int i; printf("0(EXIT)\ 1(+);\ 2(-);\ 3(*);\ 4(/);\ choose:"); scanf("%D",&i); switch(i) { case 0:break; case 1:jia();break; case 2:jian();break; case 3:cheng();break; case 4:chu();break; default :choose();break; } }

延伸阅读:

c语言程序设计职工工资你要的是命令行还是图形界面?如果是命令行可以考虑下如果是图形界面的话200分少了点,看看吧.--------------------------------------------既然不是图形界面,代码就简单.不过...

C语言程序设计工资管理救急!找迋鬵嘫,他曾回答过这个问题。他的答复如下: /*Microsoft Visual C++ .NET编译通过by 做他07.12.29*/#include "stdafx.h"#include "iostream"#include "string"#include "list"#incl...

c语言程序设计大赛试题我写了个程序,不知道能达到你的要求不? 主要的算法思路是若输入的数不能被11整除,就先用一个数组将输入数的每一位存起来,然后通过交换数组元素的位置达到重新排列数的目的,每次...

C语言计算机基础与程序设计编程题目36题的,37题稍等 #include <stdio.h> int main() { int a[10]; int i; int sum; printf("请输入10个整数:"); for(i=0;i<10;i++) { scanf("%d",&1a[i]); } for(i=0;i<10;++i) { if(a[...

C语言程序设计题目#include char *strcpy(char *d,char *s) { char *p=d; while(*p++=*s++); return d; } char *strcat(char *d,char *s) { char *p=d; for(;*p;p++); strcpy(p,s); return d...

C语言程序设计试题结果 1 1 2 3 5 8 13 21 就是 第一次循环 屏幕上输出 1 1 1 + 1 = 2 1 + 2 = 3 第二次 屏幕上输出 2 3 2 + 3 = 5 3 + 5 = 8 第三次 屏幕上输出 5 8 5 + 8 = 13 13 + 8 = 21...

C语言程序设计C语言程序设计题,C程序设计题目:void main() { float num1,num2; /س定义两个实型运算数س/ char op;/س定义运算符,可以是+,-,س,/中的任何一个س/ printf("input expression: num1+...

c语言程序设计c语言程序设计,C程序设计:方法1: 启动VC时不要用图形界面,通过在命令提示符下输入:Msdev /useenv运行(注意啦/前面有个空格).它会强制使系统环境变量全高设置成正确值.而且,只需要使...

c语言程序设计入门c语言程序设计入门,C语言程序设计怎么学:自学c语言的话,建议你买本谭浩强的《C程序设计》(第四版)出版超过1100万册,成为最畅销的计算机科普书籍。还有配套的《c程序设计学习辅导...

推荐阅读
图文推荐
栏目列表