I'm using gcc to compile the code listed below when I get the following error
error: expected '=', ',', ';', 'asm' or '__attribute__' before ' is_prime_number -
/*
-
* What is the largest prime factor of the number 317584931803?
-
*/
-
-
#include <stdio.h>
-
#include <stdlib.h>
-
-
bool is_prime_number(unsigned long number){
-
if(number < 2){
-
return false;
-
}
-
-
bool is_a_prime = true;
-
unsigned long i;
-
unsigned long factor = number/2;
-
-
for(i=factor;i>1;i--){
-
if(number%i == 0){
-
is_a_prime = false;
-
break;
-
}
-
}
-
-
return is_a_prime;
-
}
-
-
int main(int argc, char* argv[]){
-
if(argc != 2){
-
fprintf(stderr, "Usage: ./euler_3 <number>\n");
-
exit(1);
-
}
-
-
unsigned long max_val, biggest, result, i;
-
max_val = strtoul(argv[1], NULL, 10);
-
biggest = max_val/2;
-
-
//check in the reverse direction if the number is a factor of max_val
-
for(i=biggest; i>1; i--){
-
if(max_val%i == 0){
-
//check if the number is a prime number
-
if(is_prime_number(i)){
-
result = i;
-
break;
-
}
-
}
-
}
-
-
printf("Largest prime factor: %d", result);
-
exit(0);
-
}
-
Any pointers will be greatly appreciated. Thanks in advance.
2 1652
I'm using gcc to compile the code listed below when I get the following error
error: expected '=', ',', ';', 'asm' or '__attribute__' before ' is_prime_number
compiling with g++ -o file file.c works just fine. strange!
thanks
Not strange at all.
bool does not exist in C.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Carmine Cairo |
last post by:
Hi,
I'm working on a project and today I've note a little problem during the
compile fase.
Here a little piece of code:
// 1st version
welldone = 0;
size = p->getSize();
backbone = new rightType;
|
by: Brice Prunier |
last post by:
Here under 4 schemas i'm working with ( it may be long: sorry...)
The context is the following :
Resident.xsd imports Person.xsd and includes Common.xsd ( anonimous schema:
no TargetNamespace )
Person.xsd includes Common-Naming.xsd ( anonimous schemas )
Common-Naming.xsd includes common.xsd ( both are anonimous schemas )
Compilation of Resident.xsd raise the following exception:
"System.Xml.Schema.XmlSchemaException: The attribute 'oid'...
|
by: Glen |
last post by:
I'm working on a custom assembly and I'm trying to figure out the best
approach to handling known constraints within the assembly, once
compiled, to alert the developer at compile time of a potential issue.
For example, in the assembly I would like to add a constraint that
states a particular property member of the class can not be equal to one
other property. In standard coding I can throw an exception during
run-time, but I would rather...
|
by: Adam Blair |
last post by:
Is it possible to bind a switch statement to an Enum such that a compile-time
error is raised if not all values within the Enum are handled in the switch
statement? I realise you can use default: to catch unhandled cases, but of
course this is only at run-time.
Example:
public enum MyEnum
{
one, two, three, four
}
|
by: ufnuceda |
last post by:
Hello everyone,
I was wondering if any of you have some experience with the boost
library. I am having trouble compiling code with it. Since boost is
being used a lot these days I thought some of you might have an answer.
I would greatly appreciate help with this, as I tried to search for an
answer for quite some time in vain.
I am getting error messages when I try to compile as soon as I put an
include to the boost library in the...
| |
by: Urs Thuermann |
last post by:
What is the most elegant way to check certain conditions at compile
time? I.e. I want a compile time error to be generated if for example
the size of a struct is not a multiple of 4 or if one struct is larger
than another struct, etc.
I think of something like
#define CHECK(expr) static int dummy
CHECK(sizeof(struct foo) % 4 == 0);
|
by: electrixnow |
last post by:
Help!,
I need to compile this code with static libs so it run on another XP
machine that does'nt have
MS Studio installed. When I compile now I get an ERROR:
1>------ Rebuild All started: Project: drawing_control, Configuration:
Release Win32 ------
1>Deleting intermediate and output files for project 'drawing_control',
configuration 'Release|Win32'
|
by: steve yee |
last post by:
i want to detect if the compile is 32 bits or 64 bits in the source
code itself. so different code are compiled respectively. how to do
this?
|
by: ThunderMusic |
last post by:
Hi,
I'd like to create a compile time error in my class... maybe there's a way
already built in in the framework so I can achieve what I want... I have 2
constructors in my class. One of them has mandatory parameters, I mean, they
should not be null nor empty (for strings). So I'd make the validation in
the constructor and generate a compile-time error if the validation does not
match...
Is there a way to achieve this or to specify...
|
by: Ioannis Vranos |
last post by:
Perhaps a mechanism can be introduced in the C++0x/1x standard,
something simple like defining a function as:
void somefunc(void) throw()
{
// ...
}
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |