更多"请编写函数fun( ),该函数的功能是:实现B=A+A’,即把矩阵A加"的相关试题:
[简答题]请编写函数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( ),它的功能是:实现两个字符串的连接(不使用库函数strcat( )),即把p2所指的字符串连接到p1所指的字符串后。
例如,分别输入下面两个字符串:
FirstString--
SecondString
则程序输出:
FirstString--SecondString
[注意] 部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
[试题源程序]
#include<stdio.h>
#include<conio.h>
void fun(char p1[], char p2[])
main( )
char s1[80], s2[40];
clrscr( );
printf("Enter s1 and s2:/n");
scanf("%s%s", s1, s2);
printf("s1=%s/n", s1);
printf("s2=%s/n", s2);
printf("Invoke fun(s1, s2):/n");
fun(s1, s2);
printf("After invoking:/n");
printf("%s/n", s1);
[简答题]请编写函数fun,其功能是求出数组的最大元素在数组中的下标并存放在k所指的存储单元中。
例如,输入如下整数:
876 675 896 101 301 401 980 431 451 777
则输出结果为:
6,980
注意:部分源程序在文件PROG1.C中,请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。
文件PROG1.C内容如下:
#include<stdio.h>
void fun(int *s,int t,int *k)
void main( )
int a[10]=876,675,896,101,301,401,980,431,451,777,k;
fun(a,10,&k);
printf("The resuh:%d,%d/n",k,a[k]);
[简答题]请编写函数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");
[简答题]m个人的成绩存放在score数组中,请编写函数fun( ),它的功能是将高于平均分的人数作为函数值返回,将高于平均分的分数放在叩所指的数组中。
例如,当score数组中的数据为24,35,88,76,90,54, 59,66,96时,函数返回的人数应该是5,up中的数据应为88, 76, 90, 66, 96。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
试题程序:
#include <conio.h>
#include <stdio.h>
#include <string.h>
int fun(int score[],int m,int up[])
main( )
int i,n,up[9];
int score[9]=24,35,88,76,90,54,
59,66,96;
clrscr( );
n=fun(score,9,up);
printf("/nup to the average score are:");
for(i=0;i<n;i++)
printf("%d",up[i]);
[简答题]请编写函数fun,该函数的功能是:将M行N列的二维数组中的数据,按列的顺序依次存放到一维数组中。函数fun中给出的语句仅供参考。
例如,二维数组中的数据为:
33 33 33 33
44 44 44 44
55 55 55 55
则一维数组中的内容应是:
33 44 55 33 44 55 33 44 55 33 44 55
注意:部分源程序在文件PROG1.C中。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。
文件PROG1.C内容如下:
#include<stdio.h>
void fun(int(*s)[10],int *b,int *n,int mm,int nn)
/*以下代码仅供参考*/
int i,j,np=0; /*np用作b数组的下标*/
void main( )
int w[10][10]=33,33,33,33,44,44,44,44,55,55,55,55,i,j;
int a[100]=0,n=0;
printf("The matrix: /n");
for(i=0;i<3;i++)
for(j=0;j<4;j++)printf("%3d",w[i][j]);
printf("/n");
fun(w,a,&n,3,4);
printf("The A array: /n");
for(i=0;i<n;i++)printf("%3d",a[i]);
printf("/n/n");
[简答题]m个人的成绩存放在score数组中,请编写函数fun( ),它的功能是:将低于平均分的人数作为函数值返回,将低于平均分的分数放在below所指的数组中。
例如,当score数组中的数据为10,20,30,40,50,60, 70,80,90时,函数返回的人数应该是4,below中的数据应为10,20,30,40。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
试题程序:
#include <conio.h>
#include <stdio.h>
#include <string.h>
int fun(int score[],int m, int below[])
{
}
main( )
{
iht i, n, below[9];
int score[9]={10,20,30,40,50,60,70,
80,90};
clrscr( );
n=fun(score, 9, below);
printf("/nBelow the average score are: ");
for(i=0;i<n;i++)
printf("%d",below[i]);
}
[简答题]请编写函数fun,该函数的功能是:移动字符串中的内容,移动的规则如下:把第1~m个字符平移到字符串的最后,把第m+1到最后的字符移到字符串的前部。
例如:字符串中原有的内容为ABCDEFGHIJK,m的值为3,则移动后字符串中的内容应该是DEFGHIJKABC。
注意:部分源程序在文件PROG1.C中,请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。
文件PROG1.C内容如下:
#include<stdio.h>
#include<string.h>
#define N 80
void fun(char *w,int m)
void main( )
char a[N]="ABCDEFGHIJK":
int m;
printf("The original string:/n");
puts(a);
printf("/nEnter m:/n");
scanf("%d",&m);
fun(a,m);
printf(:/n The string after moving: /n");
puts(a);
printf("/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( ),该函数的功能是判断字符串是否为回文,若是则函数返回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,它的功能是:删除字符串中所有的*号。在编写函数时,不得使用C语言提供的字符串函数。
例如,字符串中的内容为:****A*BC*DEF*G********,删除后,字符串中的内容应当是:ABCDEFG。
注意:部分源程序在文件PROG1.C中。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。
文件PROG1.C内容如下:
#include<stdio.h>
void fun(char *a)
void main( )
char s[81];
printf("Enter a string: /n");gets(s);
fun(s);
printf("The string after deleted:/n");pats(s);
[简答题]请编写一个函数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)
{
//* * * * * * * * *
}