0

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 :)

2
Contributors
1
Reply
3
Views
7 Years
Discussion Span
Last Post by prvnkmr449
0

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.

Edited by prvnkmr449: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.