题目:计算并输出high以内最大的10个素数之和,high由主函数传
给fun函数,若high的值为100,则函数的值为732。
#include "stdio.h"
int fun( int high )
{
int sum = 0, n=0, j, yes;
/***********SPACE***********/
while ((high >= 2) && (【?】))
{
yes = 1;
for (j=2; j<=high/2; j++ )
/***********SPACE***********/
if (【?】)
{
yes=0;
break;
}
if (yes)
{
sum +=high;
n++;
}
high--;
}
/***********SPACE***********/
【?】;
}
main
{
printf("%d
", fun (100));
}
给fun函数,若high的值为100,则函数的值为732。
#include "stdio.h"
int fun( int high )
{
int sum = 0, n=0, j, yes;
/***********SPACE***********/
while ((high >= 2) && (【?】))
{
yes = 1;
for (j=2; j<=high/2; j++ )
/***********SPACE***********/
if (【?】)
{
yes=0;
break;
}
if (yes)
{
sum +=high;
n++;
}
high--;
}
/***********SPACE***********/
【?】;
}
main
{
printf("%d
", fun (100));
}
举一反三
- 写输出结果#include "stdio.h"int binary(int x, int a[], int n){ int low=0,high=n-l,mid; while(low<=high) { mid=(low+high)/2; if(x>a[mid]) high=mid-l; else if(x<a[mid]) low=mid+l; else return(mid); } void main(){ static int a[]={4,0,2,3,1}; int i,t,j; for(i=1;i<5;i++) t=a[i]; j=i-l; while(j>=0 && t>a[j]) { a[j+1]=a[j]; j--;} a[j+1]=t; } printf("%d\n",binary(3,a,5)); }
- 若输入52<;CR>;,则下面程序的运行结果是。main(){int a[8]={6,12,18,42,46,52,67,73};int low=0,mid,high=7,x;printf("Input a x:");scanf("%d",&x);while(low<;=high){mid=(low+high)/2;if(x>;a[mid]) low=mid+1;else if(x<;a[mid]) high=mid-1;else break;}if(low<;=high) printf("Search Successful! The index is:%d\n",mid);else printf("Can't search!\n");}
- – Is shopping there expensive? --- Yes, the price runs ______ fifty dollars. A: so high to B: as high to C: so high as D: as high as
- 以下程序的运行结果是_______。int fun(int array[3][3]){ int j;for(j=0;j<;3;j++) array[1][j]++;printf("\n");}main(){ int j,a[3][3]={0,1,2,1,0,4,2,4,5};fun(a);for(j=0;j<;3;j++)printf("%2d",a[1][j]);printf("\n");} A: 2 1 5 B: 1 0 4 C: 0 1 2 D: 1 2 3
- 以下程序运行的输出结果是______。 #include<stdio.h> #define M 100 void fun(int m,int *a,int *n) int i,j=0; for(i=1;j<=m;i++) if(i%7==0 ‖ i%11==0) a[j++]=i; *n=j; main( ) int aa[M],n,k; fun(10,aa,&n); for(k=0;k<n;k++) if((k+1)%20==0)printf("\n"); else printf("%4d",aa[k]); printf("\n");