用C语言解答下题
来源:百度知道 编辑:UC知道 时间:2024/05/30 22:40:53
1.有a=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx;b=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx;其中x为任意数字,求a*b的值;
2.有如下一组数据:
code value
0001 100
0002 20
0003 30
0001 100
0001 20
0001 4
0002 5
....... ...
等求每一组code的value值的合计值,最大值,最小值,平均值.
3.有任意一段话:要求单词的个数:
"my hert is.ni hao hehe,zan men yao yi;qi nu li.xing:zhe yang ting hao de.xiao qing shuo:"qing shu chu dan ci ge shu."da gai jiu zhe yang."
================
谢谢!
2.有如下一组数据:
code value
0001 100
0002 20
0003 30
0001 100
0001 20
0001 4
0002 5
....... ...
等求每一组code的value值的合计值,最大值,最小值,平均值.
3.有任意一段话:要求单词的个数:
"my hert is.ni hao hehe,zan men yao yi;qi nu li.xing:zhe yang ting hao de.xiao qing shuo:"qing shu chu dan ci ge shu."da gai jiu zhe yang."
================
谢谢!
第二题:
main()
{int max,a,i;
scanf("%d",&a);
max=a;
for(i=1;i<=9;i++)
{scanf("%d",&a);
if(max<a)max=a;
}
printf("%d",max);
}
这个是求的最大,最小也类似
第三题:
要考虑到单词个数为0的情况,
还要考虑到第一个单词前面有空格的情况
比如
skfdh wgf sdfg
使用cin>>s输入也是错误的,
这个不能提取空格后面的。
#include <iostream>
#include <cstdlib>
using namespace std;
int main(int argc, char *argv[])
{
char s[100];
int Words=0;
cin.getline(s, 100);
if(s[0]!=' ') ++Words;
for(int i=1; s[i]; ++i)
if(s[i]!=' ' && s[i-1]==' ')
++Words;
cout<<endl<<"Total words number is "<<Words;
system("PAUSE&