Example: In the following given program, fun computes and prints the sum of the largest 10 primes up to Max. High passes from the main function to fun.

For example, if Max has a value of 50, the function has a value of 300. Do not change anything in main or the other functions. Only fill in the necessary expressions or statements along the lines of fun.

The code is as follows:

#include<conio.h>
#include<stdio.h>
#include<math.h>
int fun(int max)
{
	int sum=0,n=0,j,flag;
	while((max>=2)&&(n<10))
	{
		flag=1;
		for(j=2; j<=max/2; j++)if(max%j==0)
			{
				flag=0;
				break;
			}
		if(flag)
		{
			sum+=max;
			n++;
		}
		max--;
	}
	return sum;
}
main()
{
	printf("%d\n",fun(50));
}
Copy the code

The output running window is as follows:

Other exercises this week

C programming column

① Please add fun function, this function is to determine whether a number is prime. When the number is prime, the function returns the string “yes!” Otherwise the function returns the string “No!” And output it in the main function.

(fun) (string s) (STR) (string S) (fun) (string S) (STR) (string S) (string S) (fun) (STR) (string S) (string S) (string S) (string S)

③ The function of the given program is to segment the scores of m individuals, test scores in the score array, the number of segments stored in the a array:

In the following given program, the function of fun is: given n real numbers, output average, and count the number of real numbers above average (including average).

Find the element whose value is a in s, return the number of elements whose value is a, and store the subscripts of these elements in sequence in array STR.

Use recursive algorithm to calculate the value of the NTH term in the Fibonacci series. From the first term, the Fibonacci series is 1, 1, 2, 3, 5, 8…

Fun moves all non-numeric characters in the string referred to by S after all numeric characters, and preserves the original sequence of numeric and non-numeric strings.

Fun computes and outputs the sum of the 10 largest primes up to Max. High passes from the main function to fun.

The harder you work, the luckier you get! Come on, Aoli!!