问答题
编写函数fun,其功能是:将所有大于1小于整数m的非素数存入xx所指数组中,非素数的个数通过k返回。
例如,若输入17,则应输出:4 6 8 9 1012 14 15 16。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。
试题程序:
#include<stdlib.h>
#include<conio.h>
#include<sfdio.h>
void fun(int m,int*k,int xx[])
void main()
(
int m,n,zz[100];
system("CLS");
printf("\nPlease enter an integer number between 10 and 100:");
scanf("%d",&n);
fun(n,&m,zz);
printf("\n\nThere are%d non-prime numbers less than%d:",m,n);
for(n=O;n<m;n++)
printf("\n%4d",zz[n]);
【参考答案】
void fun(inf m,int*k,int xx[])
{
inf i,j,n=O;
(↓↓↓ 点击下方‘点击查看答案’看完整答案、解析 ↓↓↓)
点击查看答案&解析
<上一题
目录
下一题>
热门
试题
问答题
下列给定程序中,函数fun的功能是:将tt所指字符串中的小写字母全部改为对应的大写字母,其他字符不变。 例如,若输入“Ab,CD”,则输出“AB,CD”。 请改正程序中的错误,使它能得出正确的结果。 注意:不要改动main函数,不得增行或删行,也不得更改程序的结构! 试题程序: #lnclude<conio.h> #include<stdio.h> #include<string.h> char*fun(char tt[]) ( int i; for(i=O;tt[1];i++) ******found****** if((tt[i]>=’a’)||(tt[i]<=’z’)) ******found******** tt[i]+=32; return(tt); main() char tt[81]; printf( nPlease enter a string: ); gets(tt); printf( nThe result string is n%s fun(tt));
点击查看答案&解析
问答题
下列给定程序中,函数fun的功能是:求ss所指字符串数组中长度最短的字符串所在的行下标,作为函数值返回,并把其串长放在形参n所指的变量中。ss所指字符串数组中共有M个字符串,且串长小于N。 请在下划线处填入正确的内容并将下划线删除,使程序得出正确的结果。 注意:部分源程序给出如下。 不得增行或删行,也不得更改程序的结构! 试题程序: #include<scdio.h> #include<string.h> #define M 5 #define N 20 int funIchar(*ss)[N].int*n) int i.k=0,len=N; ********found******** for(i=0;i小于 (1) ;i++] len=strlen(ss[i]); if(i==O)*n=len; ********found******** if(len (2) *n) *n=len; k=i; ********fOund******** return( (3) ); main() char ss[M][N]=[ shanghai , guangzhou , beijing , tianjin , chongqing ); int n,k,i; printff nThe original strings are: n ); for(i=0;i<M;i++)puts(ss[i]); k=fun(ss,&n); printf( nThe length of shortest string is:%d n ,n); printf( nThe shortest string is:%s n ,ss[k]);
点击查看答案&解析
相关试题
下列给定程序中,函数fun的功能是:将tt所...
下列给定程序中,函数fun的功能是:求ss所...