//c++语言程序设计第二章习题 //2-4 #include <iostream> using namespace std; int main() { const double PI = 3.1416; double a; a = PI; cout<<"a的值为:"<<a<<endl; return 0; }
1 //c++语言程序设计第二章习题 2 //2-11 3 #include <iostream> 4 using namespace std; 5 int main() 6 { 7 int n =100; 8 for(int n=100;n<=200;n+=2){} 9 do{int n=100;n+=2;}while(n!=200); 10 while(n!=200){n+=2;} 11 return 0; 12 }
1 //c++语言程序设计第二章习题 2 //2-13 3 #include <iostream> 4 using namespace std; 5 int main() 6 { 7 int x; 8 int y; 9 cout<<"请输入x,y的值"<<endl; 10 cin>>x>>y; 11 int temp; 12 if(x>y||x<y) 13 { 14 temp = y; 15 y = x; 16 x = temp; 17 } 18 cout<<"x = "<<x<<endl; 19 cout<<"y = "<<y<<endl; 20 return 0; 21 }
1 //c++语言程序设计第二章习题 2 //2-16 3 #include <iostream> 4 using namespace std; 5 int main() 6 { 7 cout<<"int字节数为:"<<sizeof(int)<<endl; 8 cout<<"char字节数为:"<<sizeof(char)<<endl; 9 cout<<"float字节数为:"<<sizeof(float)<<endl; 10 cout<<"double字节数为:"<<sizeof(double)<<endl; 11 return 0; 12 }
1 //c++语言程序设计第二章习题 2 //2-17 3 #include <iostream> 4 using namespace std; 5 int main() 6 { 7 int num = 0; 8 for(int i=32;i<=127;i++) 9 { 10 cout<<(char)i<<"\t"; 11 num++; 12 if(num == 4) 13 { 14 num = 0; 15 cout<<endl; 16 } 17 } 18 return 0; 19 }
标签:main,12,int,namespace,2023.4,using,习题,include From: https://www.cnblogs.com/muzhaodi/p/17311311.html