更多"请编写函数fun( ),该函数的功能是:统计各年龄段的人数。N个年龄通"的相关试题:
[简答题]请编写函数fun( ),该函数的功能是:统计各年龄段的人数。N个年龄通过调用随机函数获得,并放在主函数的age数组中。要求函数把0至9岁年龄段的人数在d[0]中,把10至19岁年龄段的人数放在d[1]中,把20至29岁年龄段的人数放在 d[2]中,依次类推,把100岁(含100)以上年龄的人数都放在d[10]中。结果在主函数中输出。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
试题程序:
#include <stdio. h>
# define N 50
# define M 11
void fun(int *a, int *b)
double rnd( )
static t=29, c=217,m=1024, r=0;
r= (r*t+c)%m;
return ((double) r/m);
main ( )
int age[N], i,d[M];
for(i=0; i<N; i++)
age [i]= (int) (i15*rnd ( ));
/*产生一个随机的年龄数组*/
printf ("The original data : /n");
for(i=0; i<N; i++)
printf((i+l)%10= =07 "%4d/n":"%4d",
age[i]); /*每行输出10个数* /
printf ("/n/n");
fun (age, d);
for(i=0; i<l0; i++)
printf("%4d---%4d :%4d/n", i*l0,
i*10+9, d[i] );
printf("Over 100 : %4dkn",d[10]).;
[简答题]请编写函数fun( ),该函数的功能是判断字符串是否为回文,若是则函数返回1,主函数中输出YES:否则返回0,主函数中输出NO。回文是指顺读和倒读都一样的字符串。
例如:字符串LEVEL是回文,而字符串123312就不是回文。
注意;部分源程序已存在文件test26_.cpp中。
请勿修改主函数main和其他函数中的任何内容,仅在函数fun的花括号中填写若干语句。
文件test26_2.cpp的内容如下:
#include<iostream.h>
#include<stdio.h>
#define N 80
int fun(char*str)
void main( )
char s[N];
cout<<"Enter a string:"<<endl;
getss);
cout<<"/n/n";
puts(s);
if(fun(s))
cout<<"YES/n";
else
cout<<"NO/n";
[简答题]简单应用题 请编写函数fun( ),该函数的功能是判断字符串是否为回文,若是则函数返回1,主函数中输出YES;否则返回0,主函数中输出NO。回文是指顺读和倒读都一样的字符串。 例如:字符串LEVEL是回文,而字符串123312就不是回文。 注意:部分源程序已存在文件kt11_2.cpp中。 请勿修改主函数main和其他函数中的任何内容,仅在函数fun的花括号中填写若干语句。 文件kt11_2.cpp的内容如下: #include #include #defineN80 intfun(char*str) { } voidmain( ) { chars[N]; cout<<"Enterastring:"<
[简答题]请编写函数fun,该函数的功能是:判断字符串是否为回文,若是,函数返回1,主函数中输出Yes,否则返回0,主函数中输出No。回文是指顺读和倒读都一样的字符串。
例如:字符串"LEVEL"是回文,而字符串"123312"就不是回文。
注意:部分源程序在文件PROG1.C中。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。
文件PROG1.C内容如下:
#include<stdio.h>
#define N 80
int fun(char *str)
void main( )
char s[N];
printf("Enter a string:");
gets(s);
printf("/n/n");
puts(s);
if(fun(s)) printf(" YES/n");
else printf(" NO/n");
[简答题]请编写函数fun( ),函数的功能是求出二维数组周边元素之和,作为函数值返回。二维数组中的值在主函数中赋予。
例如:若二维数组中的值为
1 3 5 7 9
2 9 9 9 4
6 9 9 9 8
1 3 5 7 0
则函数值为61。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
试题程序:
#include<conio.h>
#include<stdio.h>
#define M 4
#define N 5
int fun( int a [M][N])
{
}
main( )
{
int aa[M][N]={{1,3,5,7,9},{2,9,9,9,4},
{6,9,9,9,8},{1,3,5,7,0}};
int i, j, y;
clrscr( );
printf ("The original data is :/n ");
for(i=0; i<N;i++)
{for (j=0; j<N;j++)
printf("%6d ",aa[i][j]);
printf("/n ");
}
y=fun(aa);
printf("/nThe sun:%d/n ",y);
printf("/n");
}
[简答题]请编写函数fun( ),该函数的功能是:计算n门课程的平均分,计算结果作为函数值返回。
例如x有5门课程的成绩是90.5,72,80,61.5,55,则函数的值为71.80。
注意:部分源程序给出如下.
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
试题程序:
#include <stdio.h>
float fun (float *a, int n)
{
}
main ( )
{
float score[30]=(90.5,72,80,61.5,55},
aver;
aver=fun(score, 5);
printf("/nAverage score is: %5.2f
/n",aver);
}
[简答题]请编写函数fun( ),该函数的功能是:计算n门课程的平均分,计算结果作为函数值返回。
例如x有5门课程的成绩是90.5,72,80,61.5,55,则函数的值为71.80。
注意:部分源程序给出如下.
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
试题程序:
#include <stdio.h>
float fun (float *a, int n)
main ( )
float score[30]=(90.5,72,80,61.5,55,
aver;
aver=fun(score, 5);
printf("/nAverage score is: %5.2f
/n",aver);
[简答题]请编写一个函数char *fun(char *s),其中s代表一个字符串。函数fun( )的功能是将字符串s的元素倒置。例如,输入为“teacher”,则应输出“rehcaet”。
注意:部分源程序已存在文件PROC10.cpp中。
请勿修改主函数和其他函数中的任何内容,仅在函数fun( )的花括号中填写若干语句。
文件PROC10.cpp的内容如下:
//PROC10. cpp
#include <iostream>
#include <string>
using namespace std;
char *fun(char *s);
int main ( )
{
char str[81];
cout<<"Please enter a string:/n";
cin>>str;
cout<<"The result is:"<<fun(str));
cout<<end1;
return 0;
}
char*fun(char*s)
{
//* * * * * * * * *
}
[简答题]请编写一个函数char *fun(char *s,int n)。函数fun( )的功能是将字符串s中的字符“循环左移”n位。例如,输入“ABCDE”,则循环左移2位应输出“CDEAB”,输入“1234567”,循环左移3位应输出“4567123”。
注意:部分源程序已存在文件PROC13.cpp中。
请勿修改主函数和其他函数中的任何内容,仅在函数fun( )的花括号中填写若干语句。
文件PROC13.cpp的内容如下:
//PROC13.cpp
#include <iostream>
#include <string>
using namespace std;
char *fun(char *s,int n);
int main( )
{
char str[81];
int n;
cout<<"Enter a string(less than 80 char)/n”;
cin>>str;
cout<<"/n Enter n:";
cin>>n;
if(n>strlen(str))
{
cout<<"/n Data overflow";
return 0;
}
cout<<"The result is: "<<fun(str,n)<<end1;
return 0;
}
char *fun(char*s,int n)
{
//* * * * * *
}
[简答题]请编写一个函数int fun(int n),其中n为自然数。函数fun( )的功能是求出自然数n(包括n)以内所有素数的和,并返回其值。
注意;部分源程序已存在文件PROC11.cpp中。
请勿修改主函数和其他函数中的任何内容,仅在函数fun( )的花括号中填写若干语句。
文件PROC11.cpp的内容如下:
//PROC11.cpp
#include<iostream>
using namespace std;
int fun(int n);
int main( )
int number;
cout<<"Enter the number which you want to caculate: /n";
cin>>number;
cout<<"The result is:"<<fun(number)<<end1;
return 0;
int fun(int n)
//* * * * * * * * *