更多"请补充main函数,该函数的功能是:把1~100间的所有素数保存在数组"的相关试题:
[填空题]请补充main( )函数,该函数的功能是:把1~100的所有素数保存在数组arr中,然后输出这些素数并计算它们的和。
注意:部分源程序给出如下。
请勿改动main( )函数和其他函数中的任何内容,仅在main( )函数的横线上填入所编写的若干表达式或语句。
试题程序:
#include<stdlib.h>
#include<stdio.h>
void main( )
{
int i,j,k,flag,sum;
int arr[50];
sum=0;
k=0;
system("CLS");
for(i=2;i<100;i++)
{
______;
for(j=2;j<i&&flag;j++)
if(i%j==0)
{
______;
}
if(flag)
{
sum+=i;
______;
}
}
printf("/n***prime nHmber***/n");
for(i=0;i<k;i++)
{
if(i%10==0)
printf("/n");
printf("%4d",arr[i]);
}
printf("/nsum=%d",sum);
}
[简答题]请补充函数fun( ),该函数的功能是:寻找两个整数之间的的所有素数(包括这两个整数),把结果保存在数组bb中,函数返回素数的个数。
例如,输入6和21,则输出为:7 11 13 17 19 21。
注意:部分源程序给出如下。
请勿改动主函数main 和其他函数中的任何内容,仅在函数fun( )的横线上填入所编写的若干表达式或语句。
试题程序:
#include<conio. h>
#include<stdio. h>
#define N 1000
int fun (int n, int m, int bb [N])
int i, j, k=0, flag;
for (j=n; j<=m; j++)
【1】 ;
for (i=2; i<j; i++)
if( 【2】 )
flag=0;
break;
if( 【3】 )
bb [k++] =j
return k;
main ( )
int n=0,m=0, i, k;
int bb[N];
clrscr ( );
printf ("Input n/n");
scanf ("%d", &n);
printf ("Input m/n");
scanf ("%d", &m);
for (i=0; i<m-n; i++)
bb[i]=0;
k=fun (n, m, bb);
for (i=0; i<k; i++)
printf ("%4d",bb [i]);
[填空题]请补充main函数。该函数的功能是:求1~100(不包括100)以内所有素数的平均值。
程序运行后的结果为42.40。
注意:部分源程序给出如下.
请勿改动主函数main和其他函数中的任何内容,仅在 main函数的横线上填入所编写的若干表达式或语句。
试题程序:
#include<stdio.h>
main( )
{
int i, j, n=0,flag;
float aver=0;
clrscr( );
for(j=2;j<100;i++)
{
flag=1;
for(i=2;i<j;i++)
if( 【1】 )
{
flag=0;
break;
}
if( 【2】 )
{
n++;
aver+=j;
}
}
printf("/n/n average=%4.2f", 【3】 );
}
[填空题]请补充main函数。该函数的功能是:求1~100(不包括100)以内所有素数的平均值。
程序运行后的结果为42.40。
注意:部分源程序给出如下.
请勿改动主函数main和其他函数中的任何内容,仅在 main函数的横线上填入所编写的若干表达式或语句。
试题程序:
#include<stdio.h>
main( )
int i, j, n=0,flag;
float aver=0;
clrscr( );
for(j=2;j<100;i++)
flag=1;
for(i=2;i<j;i++)
if( 【1】 )
flag=0;
break;
if( 【2】 )
n++;
aver+=j;
printf("/n/n average=%4.2f", 【3】 );
[填空题]请补充函数fun( ),该函数的功能是:把字符下标为非素数的字符从字符串sb中删除,把字符下标为素数的字符重新保存在字符串e口中。字符串sb从键盘输入,其长度作为参数传入函数fun( )。
例如,输入“abcdefghijkl”,输出“cdfhl”。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的横线上填入所编写的若干表达式或语句。
试题程序:
#include <stdio.h>
#define N 80
void fun(char s[],int n)
int i, j, k, flag;
【1】 ;
for(i=0; i<n; i++)
if (i>1)
s [k++] =s [i];
flag=I;
for( 【2】 ; j<i&&flag; j++)
if (i%j==0)
flag=0;
【3】
s [k]=’/0’;
main( )
int i=0, strlen=0;
char str[N];
clrscr ( );
printf("/n Input a string:/n");
gets (str);
while (str [i] !=’/0’)
strlen++;
i++;
fun (str, strlen);
printf("/n*** display string ***/n");
puts (str);
[填空题]请补充main函数,该函数的功能是:从字符串str中取出所有数字字符,并分别计数,然后把结果保存在数组b中并输出,把其他字符保存在N[10]中。
例如:当str1=“ab123456789cde090”时,结果为:
0: 2 1: 1 2: 1 3: 1 4: 1 5: 1 6: 1 7: 1 8: 1 9:2 other charactor:5
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun( )的横线上填入所编写的若干表达式或语句。
试题程序:
#include <stdio.h>
#include <conio.h>
main( )
int i,b[11];
char *str="abl23456789cde090";
char *p=str;
clrscr( );
printf("***the origial data ***/n");
puts(str);
for(i=0;i<11;i++)
b[i]=0;
while(*p)
switch( 【1】 )
case ’0’:b[0]++;break;
case ’1’:b[1]++;break;
case ’2’:b[2]++;break;
case ’3’:b[3]++;break;
case ’4’:b[4]++;break;
case ’5’:b[5]++;break;
case ’6’:b[6]++;break;
case ’7’:b[7]++;break;
case ’8’:b[8]++;break;
case ’9’:b[9]++;break;
[填空题]请补充函数fun( ),该函数的功能是:把ASCII码为奇数的字符从字符串str中删除,结果仍然保存在字符串str中。字符串str从键盘输入,其长度作为参数传入函数fun( )。
例如,输入“abcdef”,输出“bdf”。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun( )的横线上填入所编写的若干表达式或语句。
试题程序:
#include <stdio.h>
#define N 80
void fun(char s[],int n)
{
int i, j;
j=0;
for(i=0; 【1】 ;i++)
{
if( 【2】 )
s [j++]-s [i];
}
【3】 ;
}
main ( )
{
int i=0, strlen=0;
char str [N];
clrscr ( );
printf ("/nInput a string: /n");
gets (str);
while (str [i] !=’/0’)
{
strlen++;
i++;
}
fun(str, strlen);
printf("/n*** display string ***/n");
puts (str);
}
[简答题]填空题
请补充函数fun( ),该函数的功能是:把一个整数转换成字符串,并倒序保存在字符数组str中。例如:当n=13572468时,str=“86427531”。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的横线上填入所编写的若干表达式或语句。
试题程序:
#include
#include
#define N 80
char str[N];
void fun(long int n)
{
int i=0;
while(【1】)
{
str[i]=【2】;
n/=10;
i++;
}
【3】;
}
main( )
{
long int n=13572468;
clrscr( );
printf("*** the origial data ***/n");
printf("n=%ld",n);
fun(n);
printf("/n%s",str);
}
[填空题]请补充函数proc( ),该函数的功能是:把一个整数转换成字符串,并倒序保存在字符数组str中。例如,当n=12345时,str="54021"。
注意:部分源程序给出如下。
请勿改动main( )函数和其他函数中的任何内容,仅在函数proc( )的横线上填入所编写的若干表达式或语句。
试题程序:
#include<stdlib.h>
#include<stdio.h>
#include<conio.h>
#define M 100
char str[M];
void proc(long int n)
{
int i=0;
while(______)
{
str[i]=______;
n/=10;
i++;
}
______;
}
void main( )
{
long int n=12345;
system("CLS");
printf("***the origial data***/n");
printf("n=%1d",n);
proc(n);
printf("/n%s",str);
}
[填空题]请补充函数fun( ),该函数的功能是:把ASCⅡ码为偶数的字符从字符串s打中删除,结果仍然保存在字符串srt中,字符串str从键盘输入,其长度作为参数传入函数fun( )。
例如,输入“abcdef”,输出“ace”。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun( )的横线上填入所编写的若干表达式或语句。
试题程序:
#inc lude< stdio, h>
#define N 80
【1】
{
int i, j;
【2】
for (i=0;i<n;i++)
{
if (s [i] %2!=0)
s [j++]=s [i];
}
【3】 ;
}
main ( )
{
int i=0, strlen=0;
char str[N];
clrscr ( );
printf ("/nInput a string:/n");
gets (str);
while (str [i] !=’ /0’ )
{
strlen++;
i++;
}
fun (str, strlen);
printf("/n*** display string ***/n");
puts (str);
}
[简答题]请补充函数fun( ),该函数的功能是:只保留字符串中的大写字母,删除其他字符,结果仍保存在原来的字符串中,由全局变量m对删除后字符串的长度进行保存。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun( )的横线上填入所编写的若干表达式或语句。
试题程序:
#include<stdio.h>
#include<conio.h>
int m;
void fun(char*s)
{
int i=0,j=0;
char *p=s;
while(*(p+i))
{
if(*(p+i)>=’A’&&*(p+i)<=’Z’)
{
(1) ;
}
(2) ;
}
s[j]=’/0’;
(3) ;
}
main( )
{
char str[80];
clrscr( );
printf("/nEnter a string:");
gets(str);
printf("/n/nThe string is:/%s/n",str);
fun(str);
printf("/n/nThe string of changing is: /%s/n",str);
printf("/n/nThe length of changed strtng is:/%d/n",m);
}
[填空题]请补充函数fun( ),该函数的功能是;交换数组aa中最大和最小两个元素的位置,结果依然保存在原数组中,其它元素位置不变。注意数组aa中没有相同元素。
例如,输入“33,67,42,58,25,76,85,16,41, 56”,则输出“33,67,42,58,25,76,16,85,41,56”。
注意;部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun( )的横线上填入所编写的若干表达式或语句。
试题程序:
#include <stdio. h>
#define N 10
void fun(int aa[])
int i, j, t;
int max=0, min=0;
for(i=0; i<N; i++)
if( 【1】 )
max=i;
if( 【2】 )
min=i;
t=aa [max];
【3】 ;
aa [min] =t;
main( )
int i;
int aa [N] =33, 67, 42,58,25, 76, 85,16, 41, 56;
clrscr ( );
printf("/n*** original list ***/n");
for(i=0; i<N; i++)
printf ("%4d", aa [i] );
fun (aa);
printf ("/n*** new list ***/n");
for(i=0; i<N; i++)
printf ("%4d", aa [i]);