C++编程实例-分支结构

实验1 分支结构

【实验目的】

通过本实验,了解C语言的分支结构程序设计的方法及语法规则的正确使用。

【实验内容】

利用随机函数出个位数加/减法算术题

#include

#include

#include

using namespace std;

int main(){

    int a,b,c,s,x,t;

    char fh;

    srand((unsigned)time(NULL));

    a=(int)rand()%10;

    b=(int)rand()%10;

    c=(int)rand()%10;

    switch(c%2){

        case 0:fh='+'; s=a+b; break;

        case 1:fh='-'; if(a

    }

    cout<>x;

    if(s==x) cout<<"/nOK!"<

    else cout<<"/nNO!"<

    return 0;

}

你可能感兴趣的:(C++编程实例)