Click here to Skip to main content
15,307,351 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hi guys.Im new to coding .I tried coding a c programm in eclipse that checks if a given number is a prime number.I keep getting error "Error encountered during Build". Where did i go wrong? How could i change the code to make it work ? Thank you in advance :)

Update: I just used the corrections suggested (pritf to printf and ;). It unfortunately still doesnt work.

Launch failed , binary not found
Build Project has encountered a problem.Errors occured during the build

What I have tried:

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

int main()
{
	int x ;
	int i, val1, val2, count=0 ;
	printf("Please enter a number:");
	scanf("%d", &x);

	val1= ceil(sqrt(x));
	val2=x;

	for (i=2; i<=val1; i++)
{
		if(val2% i == 0)
			count=1;
}
if((count == 0 && val2 !=1)||val2 == 2 || val2==3)
	printf("The number is a prime number");
else
	printf("The number is not a prime number");

	return 0;
}
Posted
Updated 14-Dec-21 8:23am
v4
Comments
PIEBALDconsult 14-Dec-21 11:45am
   
https://en.wikipedia.org/wiki/Sieve_of_Eratosthenes
Dave Kreskowiak 14-Dec-21 13:34pm
   
For future reference, when asking questions about your code, the exact error messages you're getting are very important.

C++
pritf("The number is a prime number");

Never heard of pritf.
   
Spelling: pritf is not the same as printf
pritf("The number is a prime number");

Each statement in C must end with a semicolon:
printf("The number is not a prime number")
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900