Example: Write fun, which stores all non-prime numbers greater than 1 and less than the integer n into the array referred to by A. The number of non-prime numbers is returned by M.

For example, if you type 11, you should print 4, 6, 8, 9, 10. Do not change anything in the main function or the other functions, but just put the statements you wrote in curly braces for fun.

The code is as follows:

#include<conio.h>
#include<stdio.h>
void fun(int n,int*m,int a[])
{
	int i,j;
	int t=0;
	for(i=2; i<n; i++) { j=2;
		while(j<i)
		{
			if(i%j==0)
			{
				a[t]=i;
				t++;
				break;
			}
			j++;
		}
		*m=t;
	}
}
main()
{
	int k,h,c[100];
	FILE*out;
	printf("\nPlease enter an nteger number between 10 and 100:");
	scanf("%d",&h);
	fun(h,&k,c);
	printf("\n\nThere are %d nonprime numbers less than %d:",k,h);
	for(h=0; h<k; h++)printf("%4d\t",c[h]);
	out=fopen("outfile.dat"."w");
	fun(10,&k,c);
	fprintf(out,"%d\n",k);
	for(h=0; h<k; h++)fprintf(out,"%d\n",c[h]);
	fclose(out);
}
Copy the code

The output running window is as follows:



Other exercises this week

C programming column

① Write the function fun, its function is: all non-prime numbers greater than 1 and less than the integer n into the array referred to by A, the number of non-prime numbers returned by m.

If the input string contains only letters and “#”, write fun (fun) to delete all “#” at the end of the string.

Count the number of odd digits in a string from “0” to “9”. The result is saved in the array num. Note: You cannot use string library functions.

The results of M students have been put into a linked list structure of the head node in the main function, a points to the head node of the linked list. Write fun, which finds the average score and returns the value.

Please write the function fun, whose function is to combine two two-digit positive integer x, y into an integer in z. The combination works by placing the tens and units places of x in the ones and hundreds places of Z, and the tens and units places of y in the tens and thousands places of Z.

C programming > week 14 ⑥ Please write the function fun, its function is: two two-digit positive integer a, B into an integer put in C. The combination works by placing the tens and units of A in the hundreds and units of C, and the tens and units of B in the thousands and tens places of C.

Calculate the average score of n courses and return the result as a function value.

Stu = stu, stu = stu, stu = stu, stu = stu, stu = stu, stu = stu The number of students with less than or equal to the average score is returned by parameter n, and the average score is returned by the function value.

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