(C language) Write a function isprime, the function is to determine if a number is a prime number, if it returns 1, otherwise returns 0. In the main function, the function implemented by the main function is to output all the numbers between 100-300, and 6 data is displayed per line.

tags: C language questions  c++

Write a function isprime,
function is to determine if a number is a prime number, if it returns 1, otherwise returns 0.
Call in the main function, the function of the main function implementation is:
Outputs all the numbers between 100-300, and 6 data is displayed per line.

#include<stdio.h>
#include<math.h>

int IsPrime(int x)  // Function, determine if a number is the number of prime, if it is returned 1, otherwise returns 0
{
	int i,k; 
	k=sqrt(x);
	for(i=2; i<=k; i++)
		if(x%i==0)  return 0;
	return 1;	   // Notice to write into Else Return 1; it is wrong! ! Error !!
}

int main()
{
	int y, j=0;
	for(y=101; y<=300; y+=2)
		if( IsPrime(y))   //	if( IsPrime(y)==1)
		{
			printf("%d ", y);
			j++;
			if(j%6==0) printf("\n");
		}

	return 0;
}

Intelligent Recommendation

c program: write a function for judging prime numbers, enter ten integers in the main function, and output prime number information!

c program: write a function for judging prime numbers, enter ten integers in the main function, and output prime number information! //Idea: Write a program, in which a custom function is used to dete...

[C language] Write a function to judge prime numbers, input an integer in the main function, and output a message about whether it is a prime number.

[C language] Write a function to judge prime numbers, input an integer in the main function, and output a message about whether it is a prime number....

Write a function to determine whether a number is prime. Enter an integer in the main function, and output whether it is a prime number (safer writing)

In addition to the special case of n<=1, the variable m is also used in the program. On the one hand, it avoids repetitive calculations of sqrt(a) each time. On the other hand, it also avoids float...

More Recommendation

isPrime function to determine prime numbers

What does int isPrime(int n) mean in c language isPrimeIt is a custom function that passes in an integer n to determine whether it is a prime number. If it returns 1, otherwise it returns 0. #include&...

Write a FUN function that is the number of words in a string in a string, and returns as a function value. The string is entered in the main function, which specifies that all words consists of lowercase letters, and there are several spaces between words, and there is no space in the beginning of the line!

Title: / * Count the number of words in a line of strings, And return as a function value. The string is entered in the main function. Statify all words consisting of lowercase letters, Several spaces...

Write a function to distinguish prime numbers, input an integer in the main function, and output information about whether it is a prime number.

Write a function to distinguish prime numbers, input an integer in the main function, and output information about whether it is a prime number. #include <stdio.h> int sushu(int m) { int i,n=0; ...

Copyright  DMCA © 2018-2026 - All Rights Reserved - www.programmersought.com  User Notice

Top