473,402 Members | 2,061 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,402 software developers and data experts.

Expected declaration specifier in for loop

#include <stdio.h>
#include <math.h>
main()
{
int n;
int k;
int j;

//gets user input for length of string
printf("Enter the value of n:");
scanf("%d", &n);
//stores user input as n

printf("Printing primes less than or equal to %d: \n", n);

for(k = 2; k <= n; k++)
{
if(is_Prime(k) == 1)
{
printf("%d,", k);
}
}


//here is the is_Prime function
int is_Prime (int k)


for(j = 2; j < k; j++)
{
if(k%j != 0)
{
return 1;
}

else(k%j == 0)
{
return 0;
break;
}
}

When I compile my code I get an error saying that I need declaration specifiers in my is_prime subroutine in the for loop. Can anyone explain what this means or how to fix it? Here is the line of code it references.

for(j = 2; j < k; j++)
Mar 1 '15 #1
2 4818
weaknessforcats
9,208 Expert Mod 8TB
You are calling is_prime before you have defined it. The compiler doesn't know whether is_prime is a valid call.

Either move the definition of the function above main() or place a function prototype above main to reasuure the compiler.

BTW: main() is returning default int. main() should return an int.
Mar 1 '15 #2
donbock
2,426 Expert 2GB
You need to declare variable j before you use it.

You have a parenthesized expression in the else statement in is_Prime. But else does not have a condition argument. Perhaps you mean this to be a comment.
Mar 2 '15 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Christian Christmann | last post by:
Hi, I've tree questions on the storage class specifier "extern": 1) Code example: int main( void ) { int b = -2; // my line 3 if ( a ) {
4
by: nospam_timur | last post by:
Let's say I have two files, myfile.h and myfile.c: myfile.h: int myfunction(int x); myfile.c: #include "myfile.h"
8
by: Chad | last post by:
Given the following..... #include <stdlib.h> #include <stdio.h> struct node { int data; struct node *next; };
10
by: preeya | last post by:
Hi, I have written the following program: ------------------------------------------------------------------------------------------------------------- 1 #include <stdio.h> 2 #include...
5
by: dbrother | last post by:
Access 2003 Win XP Pro SP3 Using SQL /ADO Recordsets in a Do Loop Hello, I'm using a random number generator based on an integer input from a user from a form that will get X number of random...
9
by: erictheone | last post by:
Ok so what I'm trying to do is create a trans location cipher. For those among us that don't know alot about cryptography it is a method for jumbling up letters to disguise linguistic...
2
by: Chris Winton | last post by:
I am trying to do some matrix multiplication but i keep getting a expected declaration at the end of input. Any help would be much appreciated. /* Description:To multiply given to matrix using...
1
by: psychocoyote | last post by:
Thanks for reading this in advance Basically I compile my script and I get this return error lab05.cpp: In function ‘int main()’: lab05.cpp:46: error: expected `}' before ‘else’ lab05.cpp:...
2
by: roymunia200 | last post by:
i wrote this program.after compiling it gave this error.for more i'm writing the program..... #include<iostream.h> class student { private: char name; int marks; public: void setinfo(void);
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
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,...
0
Oralloy
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.