//you must konw the differences between BASIC and C++ //in c++ ,= do not mean equal!while == has the meaning ! #include \#include
bool flag=true;
int main(int argc, char* argv[]) { cout<<\请输入一个整数: \ cin>>n; for(int i=2;i!=n;++i){ if(n%i==0){cout<<\这是一个非质数\ } if(flag==true) cout<<\你输入了一个质数\ return 0; }
88***************************************************************************** /*这个习题考察的是对初始值的理解;在定义func这个函数的时候 对C,D规定 了初始值,但是如果在调用的时候对于CD有了重新的定义,。那么输出的值 就不熟3和4了;这里的理解有误*/ #include \#include
void func(int a,int b,int c=4,int d=5) { cout<
int main(int argc, char* argv[]) { func(10,25,35,40); func(10,11,12); func(113,13); return 0; }
//简单的四舍五入程序,自己的想法,很不错~ #include \#include
if(n-n1>=0.5) return n1+1; }
int main(int argc, char* argv[]) { double x; cin>>x; cout< ********************************************************************** #include \# include int main(int argc, char* argv[]) { srand((unsigned)time(NULL)); int ran1,ran2; ran1=rand()0+1; ran2=rand()0+1; cout< if(re==ran1+ran2) cout<<\真棒,答对了\ else{ cout<<\再算一次吧~ \ cin>>re; if(re==ran1+ran2)cout<<\真棒,答对了\ else cout<<\真遗憾,答错了\ } return 0; } // 习题3点11.cpp : Defines the entry point for the console application. // 判断这个函数的的结果 // when you do such kind of exercise ,pay attention to the progress //make sure that you konw the progress well,if not ,calm down~ #include \#include int main(int argc, char* argv[]) { } int a[10]={77,83,72,54,92,65,75,81,43,96}; int b[5]={60,70,80,90,100}; int c[5]={0}; for(int i=0;i<10;i++) { int j=0; while(a[i]>=b[j])j++; c[j]++; } for(i=0;i<5;i++)cout< // 测试复制构造函数.cpp : Defines the entry point for the console application. // // 对象与类的测试.cpp : Defines the entry point for the console application. //this code is an example of the destructor and the copy consturctor;pay attention to the result and understand the execute progress; // take notice of of mark 1 and mark2;mark1 is about the definition of the destructor; #include \#include float rect::peri() { float z; z=2*x+2*y; return z; } float rect::area() { float z; z=x*y; return z; } void main() { rect obj(78.5,52),obj2,obj3(obj); cout<<\ cout<<\ cout<<\ cout<<\ obj.set(12,34); obj2.set(34,78); cout<<\ cout<<\ cout<<\} ***************************************************************************8 // 对象与类的测试.cpp : Defines the entry point for the console application. // #include \#include float rect::peri() { float z; z=2*x+2*y; return z; } float rect::area() { float z; z=x*y; return z; } void main() { rect obj(78.5,52),obj2; cout<<\ cout<<\ cout<<\ obj.set(12,34); obj2.set(34,78); cout<<\ cout<<\ cout<<\} #include \#include int white,black,sum,ran1,ran2; int main(int argc, char* argv[]) { srand((unsigned)time(NULL)); cout<<\请输入白球的个数:\ cin>>white; cout<<\请输入黑球的个数: \ cin>>black; sum=black+white; while(black+white!=1){ ran1=rand()%sum+1; ran2=rand()%sum+1; if(ran1,ran2<=white ){ white--; sum--; } if(ran1,ran2>white ){ white--; sum--; } if(ran1 百度搜索“77cn”或“免费范文网”即可找到本站免费阅读全部范文。收藏本站方便下次阅读,免费范文网,提供经典小说综合文库为C++初学者准备的一些简单例子在线全文阅读。
相关推荐: