#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語言形式寫的,可能有些小小的不兼容。如果有就找我。