#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#define maxsize 50
void trans(char str[],char exp[])/*将算术表达式str转换成后缀表达式exp*/
{
   struct
   { char data[maxsize]; /*存放运算符*/
     int top;            /*栈指针*/
   }opr;                 /*定义运算符栈*/
    char ch;
    int i=0,t=0;         /*t作为exp的下标,i作为str的下标*/
    opr.top=-1;          /*初始化设定top的值为负一*/
    ch=str[i];i++;       /*逐个读取字符串中的字符*/
    while (ch!='\0')     /*str表达式未扫描完时循环*/
    {  switch(ch)        /*判定*/
        {
        case '(':
        opr.top++;opr.data[opr.top]=ch; /*判定为'('号,则将其入栈opr*/
        break;
        case ')':
        while (opr.data[opr.top]!='(')  /*判定为')'号*/
         { exp[t]=opr.data[opr.top];    /*将栈opr中'('以后的字符依次删除并存入数组exp中*/
           opr.top--;
           t++;
         }
         opr.top--;          /*将左括号删除*/
          break;
         case  '+':           /*判定为加号或减号*/
         case  '-':
         while (opr.top!=-1 &&opr.data[opr.top]!='(')
          {      exp[t]=opr.data[opr.top];    /*将当前栈opr中(以前的所有字符依次删除并存入数组exp中*/
                 opr.top--;
                t++;
          }
          opr.top++;opr.data[opr.top]=ch;  /*将ch存入栈opr中*/
          break;
         case '*':
         case '/':
          while (opr.data[opr.top]=='*'||opr.data[opr.top]=='/'||opr.data[opr.top]=='^')
          { exp[t]=opr.data[opr.top];   /*将当前栈opr中连续的'*'或'/'或'^'依次删除并存入数组exp中*/
            opr.top--;
            t++;
          }
           opr.top++;opr.data[opr.top]=ch;  /*将ch存入栈opr中*/
             break;
          case '^':                   /*判定为乘方号*/
          while (opr.data[opr.top]=='^')
          { exp[t]=opr.data[opr.top];   /*将当前栈opr中连续的'^'依次删除并存入数组exp中*/
            opr.top--;
            t++;
          }
           opr.top++;opr.data[opr.top]=ch;  /*将ch存入栈opr中*/
             break;
          case ' ': break;              /*过滤掉空格*/
          default:
           while(ch>='0'&& ch<='9'||ch=='.')  /*判定为数字*/
          { exp[t]=ch;t++;          /*将后续数字依次存入数组中*/
            ch=str[i];i++;
           }
           i--;
           exp[t]='#';t++;          /*用#标示一个数值串结束*/
        }
        ch=str[i];i++;
      }
        while (opr.top!=-1)         /*此时str扫描完毕,栈不空时循环*/
        {  exp[t]=opr.data[opr.top];
             t++;opr.top--;
         }
         exp[t]='\0'; /*给exp表达式添加结束标示*/
    }
 float compvalue(char exp[])    /*计算后缀表达式的值*/
     {
         struct
         {   float data[maxsize];  /*存放数值*/
              int top;             /*栈指针*/
          } st;                    /*定义数值栈*/
       float d,d2;double po;
        char  ch;
       int t=0,flag=1,i,count;                     /*t作为exp的下标*/
        st.top=-1;
         ch=exp[t];t++;
        while (ch!='\0')          /*exp字符串为扫描完时循环*/
       {   switch(ch)
           {
              case '+':st.data[st.top-1]=st.data[st.top-1]+st.data[st.top]; /*执行两次退栈,并将计算结果入栈*/
                   st.top--;break;
              case '-':st.data[st.top-1]=st.data[st.top-1]-st.data[st.top];
                   st.top--;break;
              case '*':st.data[st.top-1]=st.data[st.top-1]*st.data[st.top];
                   st.top--;break;
              case '/':
                  if(st.data[st.top]!=0)
                       st.data[st.top-1]=st.data[st.top-1]/st.data[st.top];
                   else
             {    printf("\n除零错误!\n");
                    exit(0);                    /*除数为零,异常退出*/
             }
             st.top--;break;
               case '^':
                  po=pow(st.data[st.top-1],st.data[st.top]); st.data[st.top-1]=(float)po;/*调用pow子函数进行乘方运算*/
                   st.top--;break;
        default:
              d=0;  flag=1; d2=0;                           /*将数字字符转换成对应的数值存放到d中*/
            while(ch>='0'&&ch<='9'&&flag)          /*判定为数字字符*/
           {  d=10*d+ch-'0';
              ch=exp[t];t++;
              if(ch=='.')
               flag=0;
           }
              if(flag==0)
           {  ch=exp[t];t++;count=0;
               while(ch>='0'&&ch<='9')          /*判定为数字字符*/
              {d2=10*d2+ch-'0';
              ch=exp[t];t++;count++;
              }
           for(i=1;i<=count;i++)
               d2=0.1*d2;
           }
            d+=d2;
            st.top++;
            st.data[st.top]=d;
         }
           ch=exp[t];t++;
    }
     return st.data[st.top];
 }
int main()
 {
      char str[maxsize],exp[maxsize];  /*str存储原算术表达式,exp存储对应的后缀表达式*/
     printf("the arithmetic expression is:\n");
     gets(str);
     trans(str,exp);
    printf("the postfix expression is:%s\n",exp);
    printf("the result is %g\n",compvalue(exp));
}
❷ 帮忙设计个小学生四则运算C语言程序
这个很容易的输入两个数字,然后呢,分别调用四则运算四个函数,再把运算结果赋值给一个结果变量。
❸ C程序课程设计题目:小学生计算机辅助教学系统。 详情如下,望各位高手帮忙给出源代码!
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
void main()
{ 
    int a,b,op,term;
    int x,i=0;
    int counter = 0;               /*初始答对题数为0*/
 char opchar;
srand(time(NULL));              /*为函数rand()设置随机数种子*/
 a= rand()%10+1;
 b= rand()%10+1;
for(i= 0;i < 10;i++)
{
  a= rand()%10+1;
  b= rand()%10+1;
 op=rand()%4+1;
  switch(op)            /*根据运算符号不同进行不同的运算*/
  {
      case1:opchar='+';
    term=a+ b;
   break;
   case2: opchar='-';
   term=a - b;
   break;
 case3: opchar='*';
 term=a*
b;
                            break;
                   case
4:
                            opchar='/';
                            term=a/b;
                            break;
                   default:
                            printf("Wrong
operator!");
                   }
                   printf("%d%c%d=",a,opchar,b);
                   scanf("%d",&x);
                   if(x==term)
                   {
                            printf("Right!\n");
                            counter++;              
                   }
                   else
                            printf("Wrong!\n");
         }
         printf("Total
score is %d\n",counter*10);
         printf("Rate
of correctness is %d%%\n",counter*10);
}
❹ 小学编程题目c语言摘红苹果
程序设计思路:
一、小朋友和苹果都具有多样属性(比如高度、编号、状态等,还可以扩展出姓名,重量等)。所以小朋友和苹果要定义成结构体。
二、人和苹果数量都是手动输入,因此数组大小不确定,要使用动态数组(不使用动态,就得得限制用户输入的大小)。
三、题目要求确保摘到的总数最多,从最矮的小朋友开始摘,因此小朋友的数组要进行排序。
四、递归函数实现摘苹果逻辑,每人在自己够到的范围中随机摘两个(不够就拿1个)。(递归函数每次发现一个可摘取的苹果,有50%概率看中,都没看中,默认摘取最后一个看中的苹果)。
下面是代码(控制台刷新函数中cls仅限window系统运行,其它操作系统,删除或修改):

#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#include<malloc.h>
#define AFR 7//苹果图像的行数
#define AFC 6//苹果图像的行数
#define CFR 5//小朋友图像的行数
#define CFC 6//小朋友图像的行数
typedef struct apple//表示苹果数据的结构体
{
int aid;//苹果编号
int height;//苹果的高度
int status;//0:表示未被摘取。1:表示已被摘取
char aframe[AFR][AFC];//表示苹果的图像
}APPE;
typedef struct childern//表示小孩子的编号
{
int cid;//小孩子的编号
int height;//小孩子的身高
int n;//小孩摘取的苹果数量
char cframe[CFR][CFC];//表示小朋友的图像
APPE **appes;//小孩摘取的苹果结构指针数组
}CHN;
int n,m;//苹果和小朋友的个数,设为全局变量
APPE *setApps();//设置苹果。成功返回结构数组,失败返回NULL
CHN *setChns();//设置小盆友。同上。
int orderChnByHeight(CHN *chns);//对小朋友数组按照身高升序排列
int getApple(APPE *appes,CHN *chns,char (*strInfo)[100]);//递归,模拟小朋友依次选苹果。异常返回-1
int showFrame(APPE *appes,CHN *chns,char (*strInfo)[100]);
int main()
{
int i;
char (*strInfo)[100]=NULL;//用于显示操作流水
APPE *appes=NULL;
CHN *chns=NULL;
appes=setApps();
chns=setChns();
if(orderChnByHeight(chns)==-1)return 1;
srand(time(NULL));
strInfo=(char (*)[100])malloc(sizeof(char *)*m*100);
for(i=0;i<m;i++)strInfo[i][0]=0;
if(!strInfo) return 1;
showFrame(appes,chns,strInfo);
return 0;
}
int showFrame(APPE *appes,CHN *chns,char (*strInfo)[100])
{
static int k=1;
int i,j;
system("cls");
printf(" =============每组图像靠上的数值为高度,靠下的数值为编号============ ");
printf(" =============为确保能拿到最多的苹果,小朋友们按升序排列============ ");
for(i=0;i<AFR;printf(" "),i++)
for(j=0;j<n;j++)
printf("%s ",appes[j].aframe[i]);
printf(" ");
for(i=0;i<CFR;printf(" "),i++)
for(j=0;j<m;j++)
printf("%s ",chns[j].cframe[i]);
printf(" ==================================================================== ");
printf("操作流水: ");
for(i=0;i<m;i++)
printf("%s ",strInfo[i]);
fflush(stdin);
printf("按下任意键进行下一步。。。。。。 ");
getchar();
if(getApple(appes,chns,strInfo)==-1)return -1;
if(k)showFrame(appes,chns,strInfo),k--;
return 1;
}
int getApple(APPE *appes,CHN *chns,char (*strInfo)[100])
{
static int i=0,aflag,cflag;
int j,indexSave;
if(appes==NULL||chns==NULL) return -1;
if(chns[i].n==2)i++;//当前小朋友拿够2个,换下一个小朋友
if(i==m)return 1;//所有人均拿过,结束递归
aflag=0;
for(j=0;j<n;j++)
if(appes[j].status==0) {aflag=1;break;}
if(aflag==0) return 1;//所有苹果均拿完,结束递归
indexSave=-1;
cflag=0;
for(j=0;j<n;j++)
{
if(appes[j].status==0 && appes[j].height<=chns[i].height)
{
cflag=1;
indexSave=j;
if(rand()%2)//每次发现,有50%概率拿取,如所有可拿苹果都没选中,选最后发现的目标
break;
}
}
if(cflag)//小朋友拿起一个苹果的过程
{
appes[indexSave].status=1;
//改变苹果初始图像
sprintf(appes[indexSave].aframe[6]," ");
chns[i].appes[chns[i].n]=&appes[indexSave];
chns[i].n++;
if(chns[i].n==1)
{
//改变小朋友初始图像
sprintf(chns[i].cframe[0]," %c%c/ ",3,1);
sprintf(strInfo[i],"编号%d的小朋友拿取了1个苹果(编号%d) ",chns[i].cid,chns[i].appes[0]->aid);
}
if(chns[i].n==2)
{
//改变小朋友初始图像
sprintf(chns[i].cframe[0]," %c%c%c ",3,1,3);
sprintf(strInfo[i],"编号%d的小朋友拿取了2个苹果(编号%d和编号%d) ",chns[i].cid,chns[i].appes[0]->aid,chns[i].appes[1]->aid);
}
}
if(cflag==0 && chns[i].n==0) sprintf(strInfo[i],"编号%d的小朋友没有能拿到的苹果,非常沮丧! ",chns[i].cid),i++;
if(cflag==0 && chns[i].n==1) i++;
return getApple(appes,chns,strInfo);
}
int orderChnByHeight(CHN *chns)
{
CHN chnTemp;
int i,j;
chnTemp.appes=(APPE **)malloc(sizeof(APPE*)*2);
if(!chnTemp.appes) return -1;
else
{
chnTemp.appes[0]=chnTemp.appes[1]=NULL;
if(chns)
for(i=0;i<m-1;i++)
for(j=i+1;j<m;j++)
if(chns[i].height>chns[j].height)
chnTemp=chns[i],chns[i]=chns[j],chns[j]=chnTemp;
}
free(chnTemp.appes);
return 1;
}
CHN *setChns()
{
int i;
CHN *chns=NULL;
printf("请输入小朋友的个数:");
scanf("%d",&m);
chns=(CHN *)malloc(sizeof(CHN)*m);
if(!chns) return NULL;
printf("请输入%d个小朋友身高(不超过3位整数): ",m);
for(i=0;i<m;i++)
{
chns[i].cid=i+1;
scanf("%d",&chns[i].height);
chns[i].height=chns[i].height%1000;//超出3位截取
chns[i].n=0;
chns[i].appes=(APPE **)malloc(sizeof(APPE*)*2);
if(!chns[i].appes) return NULL;
chns[i].appes[0]=chns[i].appes[1]=NULL;
//设置小朋友初始图像
sprintf(chns[i].cframe[0]," \%c/ ",1);
sprintf(chns[i].cframe[1]," / \ ");
sprintf(chns[i].cframe[2],"-----");
sprintf(chns[i].cframe[3],"高%3d",chns[i].height);
sprintf(chns[i].cframe[4],"ID%3d",chns[i].cid);
}
return chns;
}
APPE *setApps()
{
int i;
APPE *appes=NULL;
printf("请输入苹果的个数:");
scanf("%d",&n);
appes=(APPE *)malloc(sizeof(APPE)*n);
if(!appes) return NULL;
printf("请输入%d个苹果的高度(不超过3位整数): ",n);
for(i=0;i<n;i++)
{
appes[i].aid=i+1;
scanf("%d",&appes[i].height);
appes[i].height=appes[i].height%1000;//超出3位截取
appes[i].status=0;
//设置苹果初始图像
sprintf(appes[i].aframe[0],"高%3d",appes[i].height);
sprintf(appes[i].aframe[1],"ID%3d",appes[i].aid);
sprintf(appes[i].aframe[2],"-----");
sprintf(appes[i].aframe[3]," %c ",'|');
sprintf(appes[i].aframe[4]," %c ",'|');
sprintf(appes[i].aframe[5]," %c ",'|');
sprintf(appes[i].aframe[6]," %c ",3);
}
return appes;
}
❺ 什么是C语言程序设计
c语言是一种高级编程语言,用来编写程序,编程可以用不同的语言来写高手都用c语言
❻ C语言程序设计:问题描述:面向小学1~2年级学生,随机选择两个整数的加减法形成算式要求学生解答.1
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
int Is50(int a,int b)
{
int s;
if(a+b<50&&a-b>0)
s=1;
else
s=0;
return(s);
}
int Right(int a, int b,int Time)
{
int R;
int Ans1,Ans2;
printf("Input Your Answer:\n");
scanf("%d,%d",&Ans1,&Ans2);
if(Ans1==a+b&&Ans2==a-b)
{
switch(Time)
{
case 1:  R=10; break;
case 2:  R=7; break;
case 3:  R=5; break;	
} 
}
else
{
if(Time!=3)
{       
printf("You Are Wrong, Try Again!\n"); 
Time++;
Right(a,b,Time);		
}
else
{
printf("You Are Wrong,The Answer is %d,%d\n",&a+b,&a-b);
R=0;
}	
}
return(R);
}
int main()
{
int a,b;
int i;
int score=0;
static int t;
srand(time(NULL));
for(i=0;i<10;i++)
{
a=rand()%51;
b=rand()%51;
while(!Is50(a,b))
{
a=rand()%51;
b=rand()%51;
}
t=1;
printf("Input the result of %d+%d and %d-%d:\n",a,b,a,b);
score=score+Right(a,b,t);
}
printf("The Total score is %d\n",score);
if(score>=90) printf("SMART\n");
else if(score>=80) printf("GOOD\n");
else if(score>=70) printf("OK\n");
else if(score>=60) printf("PASS\n");
else printf("TRY AGAIN\n");
}
❼ C语言小学数学测验程序设计
#include<stdio.h>
#include<time.h>
#include<stdlib.h>
#include<math.h>
int i=0,s=0,a,b,f=0,c,stdans,userans,boolean;
/*i控制当前题号,s是分数,
a,b是当前参与运算的数字,
f是一道题中已经用掉的机会,
c是运算符号,stdans是标准答案,
userans是用户答案,
boolean保存该题是否已经答对 
*/ 
int array[3]={10,7,5};//保存3个每道题可能累加上的分数(非0) 
int main()
{
    srand(time(0));//初始化随机数发生器 
    while(i<10){
        a=rand()%51;//产生随机数a(0<=a<=50) 
        b=rand()%51;//产生随机数b(0<=b<=50) 
        if(a+b>50 || a-b<0)continue;//保证题目不超出低年级水平所及范围 
        c=rand()%2;
        if(c==0){printf("%d、%d+%d=",i+1,a,b);stdans=a+b;}
        else {printf("%d、%d-%d=",i+1,a,b);stdans=a-b;}
        //决定运算符并输出题号及算式 
        while(f<=2){
            scanf("%d",&userans);//输入答案 
            if(f==2)break; 
            if(userans==stdans){//若答案正确  
                printf("正确!\n");
                boolean=1;
                s+=array[f]; 
                break;//则输出信息、更改变量状态、累加分数、结束循环 
                }//当机会没用完时继续循环 
            else{
                printf("错误!你还有%d次机会:",2-f);
                f++;
                boolean=0;
                }//否则再来 
            }
        if(boolean==0)printf("你没有机会了!正确答案是:%d\n",stdans);//三次没答对时 
        f=0;//初始化f
        i++;//题号增加 
        }
    printf("答题结束!你的成绩是:");
    if(s>=90)printf("SMART\n");
    else if(s>=80)printf("GOOD\n");
    else if(s>=70)printf("OK\n");
    else if(s>=60)printf("PASS\n");
    else printf("TRY AGAIN\n");//输出成绩 
    system("pause");//可删,只是相当于cmd.exe(系统自带命令解释程序)中的pause命令 
    return 0;
}
 
//我是用C++编译但刻意以C语言形式写的,可能有些小小的不兼容。如果有就找我。