Hi, so im new to this website. I am trying to write a program that tells you if a number is prime, but i have an error message that keeps popping up saying :

error C2447: '{' : missing function header (old-style formal list?

Here is my code:

#include <stdio.h>
#include "genlib.h"
int main();
{
int n,d;
n= GetInteger();
d=0;
for(int i=1;i<=n;i++)
{
if(n%i==0)d++;
}

if(d==2) printf("The number is prime");
else printf("The number is not prime");
}

Thanks :)

Hi just remove semicolon which you put at the end of

int main()

this and if you use .c extension then declare all the variable before any function call, your code work correctly without any error. I think GetInteger() is function define you so your program look similar to this

#include <stdio.h>

int main()
{
int n,d,i;
n= GetInteger();
d=0;
for(i=1;i<=n;i++)
{
if(n%i==0)d++;
}

if(d==2) printf("The number is prime");
else printf("The number is not prime");
getch();
return 0;
}

int GetInteger()
{
int num;
printf("Enetr Number: ");
scanf("%d",&num);
return num;
}

and it work.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.