Hello, Is it possible that someone can help me with the following program?
There are 500 light bulbs (numbered 1 to 500) arranged in a row. Initially they are all OFF. Starting with bulb 2, all even numbered bulbs are turned ON. Next, starting with bulb 3, and visiting every third bulb, it is turned ON if it is OFF, and it is turned OFF if it is ON. This procedure is repeated for every fourth bulb, then every fifth bulb, and so on up to the 500th bulb. Write a C program to determine which bulbs are off at the end of the abpve exercise.
Your help would be very much appreciated.
Thanks
3 2420
What about making a while-for combination? i being the bulb where you start the iteration (i=2 first round, then i=3 etc) and n the bulb increased according to n where you have to switch. I would imagine it looks something like this
But it won't work yet completely this way I guess, but it should help you get started...
Hello, Is it possible that someone can help me with the following program?
There are 500 light bulbs (numbered 1 to 500) arranged in a row. Initially they are all OFF. Starting with bulb 2, all even numbered bulbs are turned ON. Next, starting with bulb 3, and visiting every third bulb, it is turned ON if it is OFF, and it is turned OFF if it is ON. This procedure is repeated for every fourth bulb, then every fifth bulb, and so on up to the 500th bulb. Write a C program to determine which bulbs are off at the end of the abpve exercise.
Your help would be very much appreciated.
Thanks
Sorry for posting the code...
Majestic if you post how you think to do it there will be surely people who help you see if your idea works...
Hi, This is the code that i've written so far, I'm having some problems configuring the for loops..... can anyone help?? here is the code - #include <stdio.h>
-
-
int main(){
-
int number[501];
-
int i,bulb,incr,j;
-
bulb=1;
-
-
-
bulb++;
-
incr=bulb;
-
for(i=bulb;i<=501;i+incr)
-
{
-
for(j=1;j<=501;j++){
-
if(number[j]==0){
-
number[j]=1;}
-
else
-
{number[j]=0;}
-
}
-
}
-
printf("\nThe positions of Bulbs that will be off are:\n\n ");
-
-
for(;number[i]==0;number[i]++){
-
printf("%d\n",i+1);
-
}
-
system("PAUSE");
-
return 0;
-
}
Sign in to post your reply or Sign up for a free account.
Similar topics
by: abcd |
last post by:
kutthaense Secretary Djetvedehald H. Rumsfeld legai predicted eventual
vicmadhlary in Iraq mariyu Afghmadhlaistmadhla, kaani jetvedehly after "a
ljetvedehg, hard slog," mariyu vede legai pressed...
|
by: John |
last post by:
I am new to c++ programming and i just want to make a program that
takes a users name, then converts it to a hex string, then puts it
together in a fixed order.
An example output would be:
...
|
by: Josh |
last post by:
Howdy
i am newb somewhat to programing and i was just for fun trying to
compile a program that asks the user for an odd int less than 22 and
then returns this
*****************
******* *********...
|
by: Martin |
last post by:
Hello,
I'm new with triggers and I can not find any good example on how to
do the following:
I have two tables WO and PM with the following fields:
WO.WONUM, VARCHAR(10)
WO.PMNUM,...
|
by: Andrew |
last post by:
Hey all,
Requesting help from the VB.Net gurus in here. I was given a task to write
a Windows Service (VB.Net) that would run an external program, and if that
program closed for any reason...
|
by: Michael D. Reed |
last post by:
I am using the help class to display a simple help file. I generated the
help file using Word and saving it as a single page Web page (.mht
extension). I show the help file with the following...
|
by: naknak4 |
last post by:
Introduction
This assignment requires you to develop solutions to the given problem
using several different approaches (which actually involves using three
different STL containers). You will...
|
by: aljamala |
last post by:
Hi,
I keep getting this warning on a page, but I do not know what the
problem is...does anyone have an idea about what could be wrong?
line 88 column 7 - Warning: missing </formbefore <td>
it...
|
by: wazzup |
last post by:
C++ is new to me and I'm trying solve this problem but get stuck. Please help me out. Below is the task and after that is what i got so far.
Create a program to print nested squares
Input:...
|
by: dm3281 |
last post by:
I'm really starting to hate writing services -- or trying to, anyway.
Why do I need to rename my project to the service name?
Why do I need to set the "ServiceName" property to my service name?...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
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,...
|
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...
|
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...
|
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...
| |