×

[C++] Am I using for loops correctly?

 0 1 My solution for CLEANUP goes as follows: #include #include #include #define lo unsigned long long using namespace std; void solve(lo M, lo N,lo a[]){ set s; vector v; vector j; vector k; bool polar = true; //creates list of 1,2..M for (lo x = 1; x<=M;x++){ s.insert(x); } //deletes terms for (lo x = 0; x> T; lo M,N = 0; lo a[N]; for (lo x = 0; x> M >> N; for (lo y = 0; y> a[y]; } solve(M,N,a); } return 0; }  However I seem to be getting wrong answers. I suspect this is because of how I used for loops. I tried to use increments of 2, however I'm not sure if that causes overflow or not(goes past the set limit). Can anyone confirm? Thanks asked 21 Jul '17, 03:44 3★jaycram 1 accept rate: 0%

 1 hey everything is correct but you are doing a small mistake. Initially N is 0 and you are declaring an array a[N] then you can store only one element in the array. Declare array after scaning the value of N then you will get AC.I just changed that got AC.here is the link answered 21 Jul '17, 04:26 1.7k●2●10 accept rate: 14% ty so much, this explains why my last 3 solutions have been wrong lol (21 Jul '17, 20:11) jaycram3★
 0 Another thing I want to add with @hruday, it's always good practice to declare an array globally. There's always chance of stack overflow if you declare an array locally. answered 21 Jul '17, 08:06 4★sudip_95 755●6 accept rate: 10%
 0 The best way to understand loops is to understand the concept behind them. Loops are used in programming when you need to perform a task more than once. While loops and For loops exist to this end. the main difference in the two, besides the code you use to write them, is that while loops check the condition at the end of the loop, and Do My Essays will repeat the loop until the while condition is met. answered 21 Jul '17, 15:47 -1 accept rate: 0%
 toggle preview community wiki:
Preview

By Email:

Markdown Basics

• *italic* or _italic_
• **bold** or __bold__
• image?![alt text](/path/img.jpg "title")
• numbered list: 1. Foo 2. Bar
• to add a line break simply add two spaces to where you would like the new line to be.
• basic HTML tags are also supported
• mathemetical formulas in Latex between \$ symbol

Question tags:

×3,706
×2,698
×1,901
×179

question asked: 21 Jul '17, 03:44

question was seen: 391 times

last updated: 21 Jul '17, 20:11