473,487 Members | 2,616 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

eratosthenos

It is nothing short of embarrassing to feel the need to ask for help on
this. I can't see how I would make the main control for this. What I want
is a for loop and a test condition. And while I know, from things I
pondered 2 decades ago, that a fella can write code without a goto, I'm
stuck.

/* sieve1.c */

#define whatever 20
#define N whatever
#include <stdio.h>

int main(void)
{
int i, A[N+1], m, sum;

/* initialize to 0 */

for (i = 0; i <= N; ++ i) A[i] = 0;

/* output */
printf("Primes less than N are:\n");
for (i = 2; i <= N; ++ i)
{
if (A[i] == 0)
printf("%d
Apr 27 '06 #1
3 1526
On Wed, 26 Apr 2006 19:14:03 -0400, "Joe Smith"
<gr**********@netzero.net> wrote:
It is nothing short of embarrassing to feel the need to ask for help on
this. I can't see how I would make the main control for this. What I want
is a for loop and a test condition. And while I know, from things I
pondered 2 decades ago, that a fella can write code without a goto, I'm
stuck.

/* sieve1.c */

#define whatever 20
#define N whatever
#include <stdio.h>

int main(void)
{
int i, A[N+1], m, sum;
If you change it to A[N+1]=0 you can eliminate the initialization loop
below.

/* initialize to 0 */

for (i = 0; i <= N; ++ i) A[i] = 0;
For each i that is not prime, you want to set A[i] to a non-zero
value. One way is

for (i = 2; i <= N; i++)
if (A[i] == 0)
for (j = i+i; j <= N; j += i)
A[j] = 1;


/* output */
printf("Primes less than N are:\n");
for (i = 2; i <= N; ++ i)
{
if (A[i] == 0)
printf("%d

It looks like the tail end of your program fell into the bit bucket.
Remove del for email
Apr 30 '06 #2
On Sat, 29 Apr 2006 17:07:56 -0700, Barry Schwarz <sc******@doezl.net>
wrote:
On Wed, 26 Apr 2006 19:14:03 -0400, "Joe Smith"
<gr**********@netzero.net> wrote:

int i, A[N+1], m, sum;


If you change it to A[N+1]=0 you can eliminate the initialization loop
below.

Must use braces for an array: ... A[N+1] = {0}
- David.Thompson1 at worldnet.att.net
May 11 '06 #3

"Dave Thompson" <da*************@worldnet.att.net> wrote in message
news:uc********************************@4ax.com...
On Sat, 29 Apr 2006 17:07:56 -0700, Barry Schwarz <sc******@doezl.net>
wrote:
On Wed, 26 Apr 2006 19:14:03 -0400, "Joe Smith"
<gr**********@netzero.net> wrote:

>int i, A[N+1], m, sum;


If you change it to A[N+1]=0 you can eliminate the initialization loop
below.

Must use braces for an array: ... A[N+1] = {0}


Thanks. Down yonder I think I have this algorithm correct using static and
dynamic mem allocation. joe
-------------
character test here ??????
May 15 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

31
3772
by: Twister | last post by:
Hi All, I have a question which might sound very basic. I have a simple structure: struct simple{ void *buffer; }; typedef struct simple Simple;
22
2161
by: Joe Smith | last post by:
It is nothing short of embarrassing to feel the need to ask for help on this. I can't see how I would make the main control for this. What I want is a for loop and a test condition. And while I...
0
7106
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,...
1
6846
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
7349
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
5442
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,...
1
4874
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...
0
4565
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3076
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...
1
600
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
267
bsmnconsultancy
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...

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.