1.用C语言写的高c高计算器源代码
2.用c语言程序设计一个简单计算器,求其源代码
3.有一个进行数学乘方的C源代码,但运行结果不对,精度计算精度计算求教各位大侠,源码源码急用。高c高skyglue源码下载
4.50个c/c++源代码网站
用C语言写的计算器源代码
#include<stdio.h>
#include<iostream.h>
#include<stdlib.h>
#include<string.h>
#include<ctype.h>
typedef float DataType;
typedef struct
{
DataType *data;
int max;
int top;
}Stack;
void SetStack(Stack *S,int n)
{
S->data=(DataType*)malloc(n*sizeof(DataType));
if(S->data==NULL)
{
printf("overflow");
exit(1);
}
S->max=n;
S->top=-1;
}
void FreeStack(Stack *S)
{
free(S->data);
}
int StackEmpty(Stack *S)
{
if(S->top==-1)
return(1);
return(0);
}
DataType Peek(Stack *S)
{
if(S->top==S->max-1)
{
printf("Stack is empty!\n");
exit(1);
}
return(S->data[S->top]);
}
void Push(Stack *S,DataType item)
{
if(S->top==S->max-1)
{
printf("Stack is full!\n");
exit(1);
}
S->top++;
S->data[S->top]=item;
}
DataType Pop(Stack *S)
{
if(S->top==-1)
{
printf("Pop an empty stack!\n");
exit(1);
}
S->top--;
return(S->data[S->top+1]);
}
typedef struct
{
char op;
int inputprecedence;
int stackprecedence;
}DataType1;
typedef struct
{
DataType1 *data;
int max;
int top;
}Stack1;
void SetStack1(Stack1 *S,int n)
{
S->data=(DataType1*)malloc(n*sizeof(DataType1));
if(S->data==NULL)
{
printf("overflow");
exit(1);
}
S->max=n;
S->top=-1;
}
void FreeStack1(Stack1 *S)
{
free(S->data);
}
int StackEmpty1(Stack1 *S)
{
if(S->top==-1)
return(1);
return(0);
}
DataType1 Peek1(Stack1 *S)
{
if(S->top==S->max-1)
{
printf("Stack1 is empty!\n");
exit(1);
}
return(S->data[S->top]);
}
void Push1(Stack1 *S,DataType1 item)
{
if(S->top==S->max-1)
{
printf("Stack is full!\n");
exit(1);
}
S->top++;
S->data[S->top]=item;
}
DataType1 Pop1(Stack1 *S)
{
if(S->top==-1)
{
printf("Pop an empty stack!\n");
exit(1);
}
S->top--;
return(S->data[S->top+1]);
}
DataType1 MathOptr(char ch)
{
DataType1 optr;
optr.op=ch;
switch(optr.op)
{
case'+':
case'-':
optr.inputprecedence=1;
optr.stackprecedence=1;
break;
case'*':
case'/':
optr.inputprecedence=2;
optr.stackprecedence=2;
break;
case'(':
optr.inputprecedence=3;
optr.stackprecedence=-1;
break;
case')':
optr.inputprecedence=0;
optr.stackprecedence=0;
break;
}
return(optr);
}
void Evaluate(Stack *OpndStack,DataType1 optr)
{
DataType opnd1,opnd2;
opnd1=Pop(OpndStack);
opnd2=Pop(OpndStack);
switch(optr.op)
{
case'+':
Push(OpndStack,opnd2+opnd1);
break;
case'-':
Push(OpndStack,opnd2-opnd1);
break;
case'*':
Push(OpndStack,opnd2*opnd1);
break;
case'/':
Push(OpndStack,opnd2/opnd1);
break;
}
}
int isoptr(char ch)
{
if(ch=='+'||ch=='-'||ch=='*'||ch=='/'||ch=='(')
return(1);
return(0);
}
void Infix(char *str)
{
int i,k,n=strlen(str);
char ch,numstr[];
DataType opnd;
DataType1 optr;
Stack OpndStack;
Stack1 OptrStack;
SetStack(&OpndStack,n);
SetStack1(&OptrStack,n);
k=0;
ch=str[k];
while(ch!='=')
if(isdigit(ch)||ch=='.')
{
for(i=0;isdigit(ch)||ch=='.';i++)
{
numstr[i]=ch;
k++;
ch=str[k];
}
numstr[i]='\0';
opnd= atof(numstr);
Push(&OpndStack,opnd);
}
else
if(isoptr(ch))
{
optr=MathOptr(ch);
while(Peek1(&OptrStack).stackprecedence>=optr.inputprecedence)
Evaluate(&OpndStack,Pop1(&OptrStack));
Push1(&OptrStack,optr);
k++;
ch=str[k];
}
else if(ch==')')
{
optr=MathOptr(ch);
while(Peek1(&OptrStack).stackprecedence>=optr.inputprecedence)
Evaluate(&OpndStack,Pop1(&OptrStack));
Pop1(&OptrStack);
k++;
ch=str[k];
}
while(!StackEmpty1(&OptrStack))
Evaluate(&OpndStack,Pop1(&OptrStack));
opnd=Pop(&OpndStack);
cout<<"你输入表达式的计算结果为"<<endl;
printf("%-6.2f\n",opnd);
FreeStack(&OpndStack);
FreeStack1(&OptrStack);
}
void main()
{
cout<<"请输入你要计算的表达式,并以“=”号结束。"<<endl;
char str[];
gets(str);
Infix(str);
=================================================================
哈哈!源码源码给分吧!高c高
用c语言程序设计一个简单计算器,精度计算精度计算求其源代码
#include
#include
#include
#include
#include
#include
#include
#include
#include
/* Define constants for the calculator */
#define UP 0x
#define DOWN 0x
#define LEFT 0x4B
#define RIGHT 0x4D
#define ENTER 0x0D
/* Global variables */
double num1 = 0, num2 = 0, result = 0;
char str1[] = ".+-*/知消扒Qc=^%";
char cnum[5], str2[] = "", c;
int x, y, x0, y0, i, j, v, m, n, act, flag = 1;
/* Function prototypes */
void drawboder(void);
void initialize(void);
void computer(void);
void changetextstyle(int font, int direction, int charsize);
void mwindow(char *header);
int specialkey(void);
int arrow();
/* Main function */
int main() {
initialize();
computer();
closegraph();
return 0;
}
/* Initialize the graphics system */
void initialize(void) {
int xasp, yasp;
GraphDriver = DETECT;
initgraph( &GraphDriver, &GraphMode, "" );
ErrorCode = graphresult();
if (ErrorCode != grOk) {
printf("Graphics System Error: %s\n", grapherrormsg(ErrorCode));
exit(1);
}
getpalette( &palette );
MaxColors = getmaxcolor() + 1;
MaxX = getmaxx();
MaxY = getmaxy();
getaspectratio( &xasp, &yasp );
AspectRatio = (double)xasp / (double)yasp;
}
/* Main calculator function */
void computer(void) {
struct viewporttype vp;
int color, height, width;
mwindow("Calculator");
color = 7;
getviewsettings( &vp );
width = (vp.right + 1) / ;
height = (vp.bottom - ) / ;
x = width / 2;
y = height / 2;
setfillstyle(SOLID_FILL, color + 3);
bar( x + width * 2, y, x + 7 * width, y + height );
setcolor( color + 3 );
rectangle( x + width * 2, y, x + 7 * width, y + height );
setcolor(RED);
outtextxy(x + 3 * width, y + height / 2, "0.");
x = 2 * width - width / 2;
y = 2 * height + height / 2;
for (j = 0; j < 4; ++j) {
for (i = 0; i < 5; ++i) {
setfillstyle(SOLID_FILL, color);
setcolor(RED);
bar( x, y, x + width, y + height );
rectangle( x, y, x + width, y + height );
sprintf(str2, "%c", str1[j * 5 + i]);
outtextxy( x + (width / 2), y + height / 2, str2);
x += width + (width / 2);
}
y += (height / 2) * 3;
x = 2 * width - width / 2;
}
x0 = 2 * width;
y0 = 3 * height;
x = x0;
y = y0;
gotoxy(x, y);
arrow();
m = 0;
n = 0;
strcpy(str2, "");
while ((v = specialkey()) != ) {
while ((v = specialkey()) != ENTER) {
putimage(x, y, rar, XOR_PUT);
if (v == RIGHT) {
if (x >= x0 + 6 * width)
x = x0;
else
x += width + width / 2;
m++;
}
if (v == LEFT) {
if (x <= x0)
x = x0 + 6 * width;
else
x -= width - width / 2;
m--;
}
if (v == UP) {
if (y <= y0)
y = y0 + 4 * height + height / 2;
else
y -= height - height / 2;
n--;
}
if (v == DOWN) {
if (y >= 7 * height)
y = y0;
else
y += height + height / 2;
n++;
}
putimage(x, y, rar, XOR_PUT);
}
c = str1[n * 5 + m];
if (isdigit(c) || c == '.') {
if (flag == -1) {
strcpy(str2, "-");
flag = 1;
}
sprintf(temp, "%c", c);
strcat(str2, temp);
setfillstyle(SOLID_FILL, color + 3);
bar(2 * width + width / 2, height / 2, * width / 2, 3 * height / 2);
outtextxy(5 * width, height, str2);
}
if (c == '+') {
num1 = atof(str2);
strcpy(str2, "");
act = 1;
setfillstyle(SOLID_FILL, color + 3);
bar(2 * width + width / 2, height / 2, * width / 2, 3 * height / 2);
outtextxy(5 * width, height, "0.");
}
if (c == '-') {
if (strcmp(str2, "") == 0)
flag = -1;
else {
num1 = atof(str2);
strcpy(str2, "");
act = 2;
setfillstyle(SOLID_FILL, color + 3);
bar(2 * width + width / 2, height / 2, * width / 2, 3 * height / 2);
outtextxy(5 * width, height, "0.");
}
}
if (c == '*') {
num1 = atof(str2);
strcpy(str2, "");
act = 3;
setfillstyle(SOLID_FILL, color + 3);
bar(2 * width + width / 2, height / 2, * width / 2, 3 * height / 2);
outtextxy(5 * width, height, "0.");
}
if (c == '/') {
num1 = atof(str2);
strcpy(str2, "");
act = 4;
setfillstyle(SOLID_FILL, color + 3);
bar(2 * width + width / 2, height / 2, * width / 2, 3 * height / 2);
outtextxy(5 * width, height, "0.");
}
if (c == '^') {
num1 = atof(str2);
strcpy(str2, "");
act = 5;
setfillstyle(SOLID_FILL, color + 3);
bar(2 * width + width / 2, height / 2, * width / 2, 3 * height / 2);
outtextxy(5 * width, height, "0.");
有一个进行数学乘方的C源代码,但运行结果不对,源码源码求教各位大侠,高c高急用。精度计算精度计算python购物系统源码
直接使用pow函数不就可以了吗?
或:
将
for(i=1;i<=exponent;i++)
{
initial=base;
base*=base;
value=base*initial;
}
改为:
value=base;
for(i=1;i<exponent;i++)
{
value=value*base;
}
个c/c++源代码网站
在编程的源码源码世界里,C/C++无疑是高c高璀璨的明珠,它以其强大的精度计算精度计算功能和广泛的应用吸引着无数开发者。今天,源码源码我们将带你探索五十个精心挑选的tcpudp源码安卓网站,它们犹如知识的宝库,存储着数以千计至数万行的源代码,涵盖了实用的代码片段、创新的脚本、精妙的内核协议栈源码程序、令人惊叹的项目,乃至复杂的数据结构和算法,甚至是那些让你眼前一亮的游戏源码。让我们一起开启这段代码之旅吧!
首先,steam授权工具源码让我们从<a href="/topics/core-c/" title="C/C++ IT工具</" target="_blank">C/C++ IT工具</,专为IT专业人士设计,提供了核心C/C++技术和工具的集合。最后,来到第站,<a href="http://www.le.ac.uk/cc/tutorials/c/ccccdbas.html" title="le.ac.uk</" target="_blank">le.ac.uk</的C示例程序库,让你领略C语言的经典与创新。
每一个站点都是一个知识的节点,连接起C/C++编程的广阔世界。无论你是追求技术提升,还是寻求灵感启发,这里总能找到适合你的宝藏。现在,就让我们一起探索这个C/C++源代码网站,开启你的编程之旅吧!
如果你在探索过程中遇到任何问题或需要进一步的指导,随时欢迎提问,我们将竭诚为你解答。祝你在代码的海洋中畅游无阻,收获满满!