I am trying to create a statement that will loop and change statesusing numbers
ID: 3610873 • Letter: I
Question
I am trying to create a statement that will loop and change statesusing numbers starting at 1 and ending with 5 where I have 100numbers(all ones) using if statements or the modulus operator. Ifyou dont understand what im talking about, see the followingexample:state 1: 1111111111... //all items are 1
state 2: 1212121212... //every other number changed
state 3: 1222131222... //every third number changed
state 4: 1223131322... //every fourth number changed
state 5: 1223231323... //every fifth number changed
state 1: 1223241323... //every sixth number changed
...and so on until the 100th item is the only one changed
what I have so far is this which only outputs 1s
{
int k;
for(int i=1;i<6;i=i+1)
for(k=1;k<6;k++)
{
if((k%i) == 0)
{
state =1;
returnstate;
state++;
}
else if((k%i) == 1)
{
state =2;
returnstate;
state++;
}
else if((k%i) == 2)
{
state =3;
returnstate;
state++;
}
else if((k%i) ==3)
{
state =4;
returnstate;
state++;
}
else if((k%i) ==4)
{
state =5;
returnstate;
state++;
}
else
break;
}
Explanation / Answer
//Hope this will help you.. #include #include using namespace std; int main(){ int num[100]; int i,state; for(i=0;iRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.