帮我分析下程序,把输出结果写一下谢谢!!

来源:百度知道 编辑:UC知道 时间:2024/05/18 02:11:46
1.#include<iostream.h>
void main()
{int x=4;
switch(2*x-1)
{case 3:cout<<x<<"";break;
case5:cout<<2*x+1<<"";
case7:cout<<3*x-1<<"";
default:cout<<"default";}
cout<<"Switch end.\n";}

2. #include<iostream.h>
#include<math.h>
void main()
{int m,k,i;
for(m=1;m<=10;m+=2)
{k=m/3;
for(i=2;i<=k;i++)
if(m%i)cout<<m<<" ";} }

3. #include<iostream.h>
void main()
{int a=0
for(int i=1;i<=3;i++)
{switch(i)
{case 1:a=i; break;
case 2:a+=i;break;
case 3:a*=i; }
cout<<"a="<<a<<endl;}}

4. #include<iostream.h>

1 11defaultSwitch end.
你应该在每个case后加一个break,要不然就会接着运行后面的case,此处就把default显示出来了

2 7 9

3 a = 1
a = 3
a = 9
int a=0 后面少了分号

4 13579
cout<<i<<""' 少了分号

5 1 3 5 7 9
此处空格代表制表符;
也少了分号

6 s = 64
还是少分号

这是在机子上运行的结果

晕,上机试一下不就有答案拉..
!@!
打开VC或者其他C++开发工具
复制代码->在标题栏上右键>粘贴->运行->输出结果了把

自己试下把

1.
defaultSwitch end.

2.
7 9

3.
a=1
a=3
a=9

4.
13579

5.
1 3 5 7 9
说明:上面的每个数字后都有一个制表符

6.
s=64

1."case7"中应有空格(此时输出:11 defaultSwitch end.),否则,输出default句(defaultSwitch end.).
2.输出:7 9
3.输出:a=1
a=3
a=9
4.输出:1 3 5 7 9

5.输出:1 3 5 7 9
这题和上题不同的是每个制表位输出一个数.
另外,int i=1后少了一个分号.
6.输出:s=64
while(s<