标签:小代码
#include <iostream> #include <stdlib.h> #include <cmath> using namespace std; void switchyuju() { cout<<"|int x;cin>>x; | "<<endl; cout<<"| switch(x) { |"<<endl; cout<<"| case 1:函数(); |"<<endl; cout<<"| case 2:函数(); break ; |"<<endl; cout<<"| default: cout<<\"error\n;\"} |"<<endl; cout<<"|char x;cin>>x; | "<<endl; cout<<"| switch(x) { |"<<endl; cout<<"| case ‘1‘:函数(); |"<<endl; cout<<"| case ‘2‘:函数(); break ; |"<<endl; cout<<"| default: cout<<\"error\n\";} |"<<endl; } void foryuju() {cout<<"| 输出99乘法表 |"<<endl; int a,b; for(a=1;a<10;a++) { for( b=1;b<=a;b++) {cout<<a<<"*"<<b<<"="<<a*b<<";"<<" ";} cout<<endl; } } void whileyuju() { cout<<"| 阶乘运算展示 |"<<endl; cout<<"| 0!=1; |"<<endl; cout<<"| 1!=1; |"<<endl; cout<<"| 2!=2*1; |"<<endl; cout<<"| 3!=3*2*1=6 |"<<endl; cout<<"| 4!=4*3*2*1=24 |"<<endl; cout<<"| 阶乘运算运用 |"<<endl; cout<<"|想求几的阶乘(输入一个0到50的小正数) |"<<endl; int x,W=1; cin>>x; while(x>0&&x<50) //为了防护限制在0-50 {W=W*x;x--;} cout<<W; //w=120 24?(1 0) } void ifyuju() { int c; double d; d=rand()%101; cout<<"| 输入数来看运气 |"<<endl; cout<<"| 输入(0-100),输出结果是随机的 |"<<endl; cin>>c; if(c<=0){cout<<"再试一次";} if(c<30){c=c*d; if(c<15) {cout<<"明天会更美好";} else {cout<<"明年的今天,别样风采";} } if(c>=30&&c<60) {c=c*d; if(c<30){cout<<"明天会更美好";} else {cout<<"风景依旧在,最美是情怀";} } else {cout<<"学习知识是一场场信息不对称的战争";} } void gotoyuju() { cout<<"| 我的见解 关于goto |"<<endl; cout<<"| 函数好用,但可避免 |"<<endl; cout<<"| goto语言的作用:无条件跳转 |"<<endl; cout<<"| 以下界面展示文档 |"<<endl; cout<<"| { int i=1,sum=0; loop:if(i<=100) |"<<endl; cout<<"|{sum=sum+i; i++; goto loop; }cout<<sum;}|"<<endl; cout<<"| 计算累加 |"<<endl; cout<<"| 输入一个正整数 | "<<endl; int i,sum=0; cin>>i; loop:if(i<=100) { sum=sum+i; i++; goto loop; } cout<<sum; } int main() { int X; cout<<"---------------------------"<<endl; cout<<"| 五大语法 |"<<endl; cout<<"| |"<<endl; cout<<"| 1.switch 2.for |"<<endl; cout<<"| 3.while 4.if |"<<endl; cout<<"| 5.goto |"<<endl; cout<<"---------------------------"<<endl; cout<<"| (1-5)选1可以总预览 |"<<endl; cin>>X; switch(X) { case 1 : switchyuju(); case 2 : foryuju(); case 3 : whileyuju(); case 4 : ifyuju(); case 5 : gotoyuju(); default: cout<<"error\n"; } return(X); }
标签:小代码
原文地址:http://sts609.blog.51cto.com/11227442/1749364