How to skip a step in a C++ FOR loop?
968428
I wouldn't worry about an extra if eating up any extra CPU's.  Believe me, the difference would be negligible...\n\nIf you really want to speed up your code, do this:\nint x = 0;\nfor ( ; x < 6; x++ ) {\ndoWork();\n}\n\nx++;\nfor ( ; x < 10; x++ ) {\ndoWork();\n}\n\nthat's about as fast as it gets.  It's more code bloat, but it does prevent the extra if().
674903
good answers, but there can also be multiple answers instead of just yes and no.\n\nfor instance, what day is today?\n\nif (day == monday)\n   cout<<"monday";\nelse if (day == tuesday)\n   cout<<"tuesday";\nelse if (day == wedensday)\n   cout<<"wedensday";\n...\nelse \n   cout<<"invalid entry";\n\nof course you could also use a case statement in this example, and would work the same.
830076
you can't really "catch" them per se, as they are really not errors, unlike floating point overflows. \nYou can do some sanity checks like the above answer explained...\nor better, just use larger storage - like unsigned long long - that'll give you more space without overflowing.
301607
C+D cross first 2 mins\nD returns for 1 min\nA+B cross for 10 mins\nC returns for 2 mins\nC+D cross for 2 mins\nTotal 17 minutes
678911
Check out the site at http://www.pscode.com - I don't do C++ but I use that site all the time for Visual BASIC stuff I work on.
751489
I don't see how you could access elements in an array past MAXINT. (Using array syntax.)\n\nSo the practical answer is MAXINT.
585256
its bad to ask the code bcoz this is spoon feeding \nu have to shake ur mind to find the solution \n\ni will just give u the idea which is not so difficult to grab\n\npesudocode:::::::::\nfirst get urself familiar with the synatx of the following\n\nfor loop\n\nprintf\n\nscanf\n\n\ndefine array as  array[10]\napply for loop for 1 to 10 students\nfor(int i=1;i<=10)\nthen using scanf get numbers in array[i]\n\nafter that again use for loop to display data\nprintf array[i]\n\n\nnow that enough open your compiler and write it
697721
First up you are going to need a compiler, you can get a free one here.\nhttp://www.borland.com/downloads/download_turbo.html\n\nInformation about it can be found here.\nhttp://www.turboexplorer.com/\n\nSome tutorials for c++ can be found here.\nhttp://www.cs.wustl.edu/~schmidt/C++/\n\nhttp://www.cplusplus.com/doc/tutorial/\n\nYou do not have to worry about memory allocation in C++, you can deal with it if you want, but you can avaoid it by using the keywords, 'new', 'delete', and 'delete[]'.\n\nRegarding the generation of random word segments, it would be done the same way as the random numbers are generated.\n\nIe, make an enum of these word segments,\nstring[] word_segments[5] = {"a", "an", "her", "ot", "etc"}\n\nWhen you get the random number, have it select a value from this array.\n\nword_segments[random_number];
869459
void main()\n{\nint n,rev=0,ro,n1;\ncout<<"enter the number";\ncin>>n;\nn1=n;\nwhile(n>0)\n{\nro=n%10;\nrev=rev*10+ro\nn=n/10;\n}\nif ( rev== n1)\n cout<<"the number is palindrom";\nelse\ncout<<"the number is not palindrom";\n}
195373
Try this:\n\n#include <stdio.h>\n\nmain()\n{\nint size,array[50],n,m,border,max,buf,step;\nint i, j, temp;\n\nprintf("Input number of elements in array:");\nscanf("%d",&size);\n\nfor(n=0;n<size;n++) {\n  printf("input %d. element of array:",n+1);\n  scanf("%d",&array[n]);\n  }\n\n for (i=(size-1);i>=0; i--)\n  {\n   for(j=1;j<=i;j++)\n    {\n     if(array[j-1]>array[j])\n      {\n       temp=array[j-1];\n       array[j-1]=array[j];\n       array[j]=temp;\n      }\n     }\n   }\n\nfor(n=0;n<size;n++)\n   printf("%d. element: %d&#92;n",n+1,array[n]);\n\n}\n\n\n\nHERE IS MY OUTPUT:\n\nInput number of elements in array:8\ninput 1. element of array:6\ninput 2. element of array:2\ninput 3. element of array:3\ninput 4. element of array:5\ninput 5. element of array:1\ninput 6. element of array:4\ninput 7. element of array:5\ninput 8. element of array:7\n1. element: 1\n2. element: 2\n3. element: 3\n4. element: 4\n5. element: 5\n6. element: 5\n7. element: 6\n8. element: 7
876944
I'm not fully sure of what you're trying to do here, but if you're trying to make sub-menus you can simply put all of the cout and cin statements for each sub-menu in between the cout<<" You selected... etc."; and the break statements. If you want it in another function, you can do:\n\nint main() {\n\n   //Other lines of code...\n\n   switch (choice)\n   {\n      case 1:\n         cout<< " You selected item 1.&#92;n";\n         //Call the first menu\n         menu1();\n         break;\n      }\n   }\n\n   void menu1() {\n      //This is the first menu!\n      int choice;\n      cout<< "This is the first menu...&#92;n";\n      cout<< "Pick something!&#92;n";\n      cin>> choice;\n      //Do other stuff here\n   }\n\n\nSorry if this doesn't help; I don't know C++ very well, and if you could expand on what you want to do I could help more. If this is what you want, then it's all good!
622069
Above answer is ok except for not using the -- operator:\nNeed to start at 10 and to decrement i use the statement:\n\ni--;\n\nThis changes the problem somewhat.  Another problem in the first answer is that fact is not initialized, so it will always equal zero resulting in a division by zero error.
334651
If you use an array, then use the mod operator to choose the first element of the array to access the array once you have passed the last element of the array. \n\ni = 0; \nwhile (1)\n{\n   printf ("%d", a[i%n]); // 'n' is the size of the array\n   i++;\n}
115853
#include <iostream>\n#include <vector>\nusing namespace std;\n#define rep(i, n) for((i) = 0; (i) < (n); (i)++)\n#define rep2(i, k, n) for((i) = k; (i) < (n); (i)++)\nvoid f21();\nint n;\ndouble mat[100][100];\nint main()\n{\nwhile(true)\n{\ncin >> n;\nif(!n) break;\nmemset(mat, 0, sizeof(mat));\nf21();\n}\nreturn 0;\n}\n\nvoid f21()\n{\ncout << "****************************************" << endl;\ncout << "*          INVERSE OF MATRIX           *" << endl;\ncout << "****************************************" << endl;\n\ncout << "ORDER OF THE MATRIX: " << n << endl;\ncout << "ENTER ELEMENT ROW-WISE" << endl;\nint m = 2*n;\nint i, j, k;\nrep(i, n) {\nrep(j, n) {\ncin >> mat[i][j];\ncout <<"&#92;t";\nprintf("%5.3lf", mat[i][j]);\n}\nrep2(j, n, m) {\nif(i == (j-n)){\nmat[i][j] = 1;\ncontinue;\n}\nmat[i][j] = 0;\n}\ncout << endl;\n}\n\ncout << endl << "INVERSE MATRIX: " << endl;\ndouble pivot, comm;\nrep(i, n) {\npivot = mat[i][i];\nif(mat[i][i] == 0){\ncout << "DIVISION BY ZERO." <<endl;\nreturn;\n}\nrep(j, m) mat[i][j] = mat[i][j]/pivot;\nrep(j, n) {\nif(i == j) continue;\ncomm = mat[j][i];\nrep2(k, i, m) {\nmat[j][k] = mat[j][k] - (comm*mat[i][k]);\n}\n}\n}\n\nrep(i, n) {\nrep2(j, n, m) {\ncout <<"&#92;t";\nprintf("%6.4lf", mat[i][j]);\n}\ncout << endl;\n}\ncout << endl;\n}\n\n/*This is writen in C++ this will output the inverse of a Matrix\ninput:\n4\n1 2 3 4\n2 1 4 2\n2 5 7 12\n1 -1 3 11\n\n5\n1.173 -0.634 0 0 0\n-0.539 1.173 -0.634 0 0\n0 -0.539 1.173 -0.634 0\n0 0 -0.539 1.173 -0.634\n0 0 0 -0.539 1.173\n\n0\n*/
635623
I don't know C++. But You can do it by sending  the text in to prn folder. Same thig you can do it in DOS type a.txt >prn
139131
Something like this would work (syntax may not be exactly correct here...):\n\npublic class FibonacciNumbers {\n    public int getNthNumber(int n)  {\n        if (n <= 1) {\n            return 1;\n        }\n        int curFib = 1;\n        int lastFib = 0;\n        int temp;\n        for (int i = 2; i < n; i++) {\n            temp = curFib;\n            curFib = curFib + lastFib;\n            lastFib = temp;\n        }\n        return curFib;\n    }\n};\n\n\nYou can also write it recursively (i.e. call getNthNumber() inside the function), but this way is a bit faster due to overhead from function calls.
784164
sure you can use that syntax and it's correct this way:\nwrite(arraylist[x]);\nusualy this is used with a for clause\nfor i:=0 to n do\n write(arraylist[i]);\nbut if you put a pice of code when ur using this i can help you fix your errors.