更多"请编写一个函数fun( ),它的功能是计算并输出给定整数n的所有因子("的相关试题:
[简答题]请编写一个函数fun( ),它的功能是计算并输出给定整数n的所有因子(不包括1与自身)之和(规定n的值不大于1000)。
例如:输入n的值为856,则输出为sum=763。
注意:部分源程序已存在文件test33_2.cpp中。
请勿修改主函数main和其他函数中的任何内容,仅在函数count的花括号中填写若干语句。
文件test33_2.cpp清单如下:
#include<stdio. h>
#include<iostream. h>
int fun(int n)
{
}
void main ( )
{
int n, sum;
cout<<"Input n:"<<end1;
cin>>n;
sum=fun (n);
cout<<" sum= /n"<<sum<<end1;
}
[简答题]请编写一个函数fun( ),它的功能是计算并输出给定整数n的所有因子(不包括1与自身)的平方和(规定n的值不大于100)。
例如:主函数从键盘给输入n的值为56,则输出为 sum=1113。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
试题程序:
#include <stdio.h>
long fun(int n)
main( )
int n;
long sum;
printf("Input n:");
scanf("%d",&n);
sum=fun(n);
printf("sum=%ld/n",sum);
[简答题]请编写函数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( ),该函数的功能是:将M行N列的二维数组中的字符数据,按列的顺序依次放到一个字符串中。
例如,若二维数组中的数据为:
W WWW
S S S S
H H H H
则字符串中的内容应是WSHWSHWSHWSH。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
试题程序:
#include<stdio.h>
#define M 3
#define N 4
void fun(char (*s)[N],char *b)
main( )
char a[100],w[M][N]= ’W’, ’W’, ’W’, ’W’,
’S’, ’S’, ’S’, ’S’,’H’, ’H’, ’H’, ’H’;
int i,j;
printf("The matrix:/n");
for(i=0;i<M;i++)
for(j=0;j<N;j++)
printf("%3c",w[i][j]);
printf("/n");
fun(w,a);
printf("The A string:In");
puts(a);
printf("/n/n");
[简答题]请编写函数fun( ),该函数的功能是:将两个两位数的正整数a,b合并形成一个整数放在c中。合并的方式是:将a数的十位和个位数依次放在c数的十位和千位上,b数的十位和个位数依次放在c数的百位和个位上。
例如,当a=45时,b=12,调用到该函数后,c=5142。
注意:部分源程序给出如下.
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
试题程序:
#include <stdio.h>
#include<conio.h>
void fun(int a ,int b, long *c)
main ( )
int a,b;
long c;
clrscr( );
printf("Input a ,b:");
scanf(,%d%d",&a,&b);
fun(a,b,&c);
printf("The result is :%ld/n",c);
[简答题]请编写函数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( ),该函数的功能是:删去一维数组中所有相同的数,使之只剩一个。数组中的数已按由小到大的顺序排列,函数返回删除后数组中数据的个数。
例如,若一维数组中的数据是:
2 2 2 3 4 4 5 6 6 6 6 7 7 8 9 9 10 10 10
删除后,数组中的内容应该是:
2 3 4 5 6 7 8 9 10。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
试题程序:
#include <stdio. h>
#define N 80
int fun(int a[], int n)
{
}
main ( )
{
int a[N]={ 2,2,2,3,4,4,5,6,6,6,6,7,7,
8,9,9,10,10,10,10}, i, n=20;
printf ("The original data : /n");
for(i=0; i<n; i++)
printf ("%3d", a [i] );
n=fun (a, n);
printf("/n/nThe data after deleted
: /n");
for(i=0; i<n; i++)
printf ("%3d", a [i] );
printf ("/n/n");
}
[简答题]请编写一个函数fun( ),该函数的功能是:返回给定字符串中大写字母字符的个数。
如字符串"Hello World"中,大写字母的个数为2个。
注意:部分源程序已存在文件PROC5.CPP中。
请勿修改主函数和其他函数中的任何内容,仅在函数fun( )的花括号中填写若干语句。
文件PROC5.cpp的内容如下:
//PROC5.cpp
#include<iostream>
#include<string>
using namespace std;
int fun(char *str);
int main( )
{
char str[ ]="Chinese Computer World";
cout<<fun(str)<<end;
return 0;
}
int fun(char *str)
{
//**********
}
[简答题]请编写一个函数fun( ),该函数的功能是:返回给定字符串中大写字母字符的个数。
如字符串"Hello World"中,大写字母的个数为2个。
注意:部分源程序已存在文件PROC5.CPP中。
请勿修改主函数和其他函数中的任何内容,仅在函数fun( )的花括号中填写若干语句。
文件PROC5.cpp的内容如下:
//PROC5.cpp
#include<iostream>
#include<string>
using namespace std;
int fun(char *str);
int main( )
char str[ ]="Chinese Computer World";
cout<<fun(str)<<end;
return 0;
int fun(char *str)
//**********
[简答题]请编写一个函数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)
{
//* * * * * * * * *
}
[简答题]请编写函数fun( ),该函数的功能是:实现B=A+A’,即把矩阵A加上A的转置,存放在矩阵B中。计算结果在main( )函数中输出。
例如,输入下面矩阵:
1 2 3
4 5 6
7 8 9
其转置矩阵为:
1 4 7
2 5 8
3 6 9
则程序输出:
2 6 10
6 10 14
10 14 18
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
试题程序:
#include <stdio.h>
#include<conio.h>
void fun (int a[3][3], int b[3][3])
{
}
main ( )
{
int a[3][3]={{1,2,3}, {4,5,6},{7,8,9}},t[3] [3];
int i, j;
clrscr ( );
fun (a,t);
for(i=0; i<3; i++)
{ for (j=0; j<3; j++)
printf ("%7d",t [i] [j] );
printf ("/n");
}
}
[简答题]请编写函数fun( ),该函数的功能是:移动字符串中的内容,移动的规则是把第1到第m个字符,平移到字符串的最后,把第m+1到最后的字符移到字符串的前部。
例如,字符串中原有的内容为ABCDEFGHIJK,m的值为 3,移动后,字符串中的内容应该是DEFGHIJKABC。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
试题程序:
#include <stdio. h>
#include <string.h>
#define N 80
void fun (char *w, int m)
main ( )
char a[N]= "ABCDEFGHIJK";
int m;
printf ("The origina string : /n");
puts (a);
printf("/n/nEnter m: ");
scanf ("%d", &m);
fun (a, m);
printf (" /nThe string after moving : /n");
puts (a);
printf ("/n/n");
[简答题]请编写函数fun( ),该函数的功能是:移动一维数组中的内容,若数组中有n个整数,要求把下标从p到n-1(p≤n-1)的数组元素平移到数组的前面。
例如,一维数组中的原始内容为1,2,3,4,5,6,7, 8,9,10,11,12,13,14,15,p的值为6。移动后,一维数组中的内容应为7,8,9,10,11,12,13,14,15,1,2,3,4,5,6。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
试题程序:
#include<stdio.h>
#define N 80
void fun(int *w,int p,int n)
main( )
int a[N]=1,2,3,4,5,6,7,8,9,10,11,12,13,14,15;
int i,p,n=15;
printf("The original data:/n");
for(i=0;i<n;i++)
printf("%3d",a[i]);
printf("/n/nEnter p:");
scanf("%d",&p);
fun(a,p,n);
printf("/nThe data after moving:/n");
for(i=0;i<n;i++)
printf("%3d",a[i]);
printf("/n/n");