知識(shí)點(diǎn):素?cái)?shù)求和運(yùn)算
以下程序的功能是計(jì)算并輸出high以內(nèi)的10個(gè)素?cái)?shù)之和,high由主函數(shù)傳給fun函數(shù),例如:high的值為100,則函數(shù)的值為732。
#include
#include
#include
int fun( int high )
{ int sum = 0, n=0, j, yes;
while (high >= 2 && n < 10)
{ yes = 1;
for (j=2; j<=high/2; j++ )
if [ (10) ]
{yes=0; [ (11) ];}
if (yes)
{ sum +=high; n++; }
high--;
}
[ (12) ];
}
main ( )
{ clrscr( );
printf("%d\n", fun (100));
}
以下程序的功能是計(jì)算并輸出high以內(nèi)的10個(gè)素?cái)?shù)之和,high由主函數(shù)傳給fun函數(shù),例如:high的值為100,則函數(shù)的值為732。
#include
#include
#include
int fun( int high )
{ int sum = 0, n=0, j, yes;
while (high >= 2 && n < 10)
{ yes = 1;
for (j=2; j<=high/2; j++ )
if [ (10) ]
{yes=0; [ (11) ];}
if (yes)
{ sum +=high; n++; }
high--;
}
[ (12) ];
}
main ( )
{ clrscr( );
printf("%d\n", fun (100));
}