|
悬赏500FM币已解决
#include<iostream >
using namespace std;
int a[8]={1, 2, 3, 4, 5, 6 , 7 , 8};
void main(){
int s0,s1,s2;
s0=s1=s2=0;
for(int i=0; i<8; i++)
{switch(a【i】%3)
{case 0: s0+=a【i】;break;
case 1: s1+=a【i】;break;
case 2: s2+=a【i】;break;
}
}
cout<<s0<<' '<<s1<<' '<<s2<<endl;
}
#include<iostream >
using namespace std;
int count_calls()
{
static int ctr=-1;
return ++ctr;
}
int main()
{
for (int i=0;i!=10;++i)
cout<<count_calls()<<endl;
return 0;
}
#include<iostream >
using namespace std;
void swap(int x, int y)
{
int temp;
temp =x;
x=y;
y=temp;
}
int main()
{
int xval,yval;
cout<<"Enter two integers:"<<endl;
cin >>xval>>yval;
cout<<"Before swapped: "
<<"x="<<xval
<<";y="<<yval<<endl;
swap(xval,yval);
cout<<"After swapped: "
<<"x="<<xval
<<";y="<<yval<<endl;
return 0;
}
上面三题请说出运行结果并简单解释
#include<iostream >
#include<string>
#include<cctype>
using namespace std;
int main(){
string currWord,preWord;
cout<<"Enter some words:"<<endl;
while(cin>>currWord)
{
if(currWord==preWord && isupper(preWord[0]))
break;
else
preWord=currWord;
} //注:下面的empty()成员函数判断单词是否为空
if(currWord==preWord && !currWord.empty())
cout<<"The repeated word:"<<currWord<<endl;
else
cout<<"There is no repeated word."<<endl;
return 0;
}
说出这个代码的作用
还有谁能列出些常用的函数及他们的意义
[ 本帖最后由 meng1987 于 2008-6-25 04:06 PM 编辑 ] |
最佳答案
查看完整内容
第一题有错,无法执行
第二题输出:
0
1
2
3
4
5
6
7
9
第三题
输入两个数,显示交换前与交换后的结果
但实际上两个数并没有交换,因为swap函数的参数是传值的,不影响原来的xval与yval
|