How to handle unsigned int overflow in C?
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.
1108883
The reason you got these results is because in C, when you precede an integer literal with 0 (the way you did), it means that you're using octal base.\n\n12 octal = 1*8 + 2 = 10 decimal\n34 octal = 3*8 + 4 = 28 decimal\n56 octal = 5*8 + 6 = 46 decimal
114514
I have the answer.\n\nYou should change the numbers to be "400.0" instead of "400". This is your primary problem.\n\nThe deeper reason that this is happening is that 400*400/400 is an INTEGER expression. It will be evaluated as an integer, and only assigned to a floating point result.\n\nI believe that your compiler is a 16 bit compiler, this is the only answer that makes sense.\n\nNow let's just see what the compiler is doing. Its first step is to evaluate 400*400. Now if you get out your calculator, you will get the answer 160,000. NOT SO FAST!!!! An integer in your compiler is only 16 bits long, and can only express numbers between -32768 and 32767. The answer that it comes up with is 28,928 (160,000 - 2*65,536). It will next divide 28,928 by 400 to give 72 (again it drops the fractional result because it is integer).\n\nIn both C and C++, the result of an integer expression is an integer. It does not matter if it gets assigned to a float or not. If you want float accuracy, then the numbers in the expression must be floats.
1024904
Thats a recursive program for you.\nAnd I put an arbitrary limit of 9 there. You can change that for yourself.\n\n#include <stdio.h>\n\nvoid triangle(char ch, int count) {\n        int temp=0;\n        if (count==1) {\n                printf("%c&#92;n", ch);\n                return;\n        }\n        triangle(ch, count-1);\n        for(;temp<count;temp++) {\n                printf("%c", ch);\n        }\n        printf("&#92;n");\n}\n\nint main() {\n        char ch='*';\n        int count=0;\n        while((count<=0)||(count>=10)) {\n                printf("Enter the size of triangle (less than 10)&#92;n");\n                scanf("%d", &count);\n        }\n        triangle(ch, count);\n}
782532
there is no built-in at-the-nth-power operator in c++,\n\nsimply use \n#include <math.h>\ndouble z = pow(3,2);
492653
sounds like your either entering a number that is too big or too small for a particular data type. if your using int try to switch to long and see if that works.
618947
#include <iostream> \n#include <cstdlib> \n#include <iomanip> \n\nint make_odd(int h); \nvoid rec_call(char c, int s); \n\n\nint main( void) \n{ \n    cout << "Enter character to use in the diamond.&#92;t"; \n    char draw; \n    cin >> draw; \n    cin.ignore(1000, '&#92;n'); \n    cout << "How many rows in the diamond (make it an odd number)?&#92;t"; \n    int high; \n    cin >> high; \n    cin.ignore(1000, '&#92;n'); \n    high = (high % 2)? (high/2) + 1 : make_odd(high); \n    rec_call(draw, high); \n    cout << "&#92;n&#92;nPress Enter to Continue . . .&#92;t"; \n    cin.get(); \n    return 0; \n\n\n\n} \n\n\nint make_odd(int h) \n{ \n cout << "That is not an odd number&#92;nUsing " << (h + 1); \n return ((h / 2) + 1); \n\n\n} \n\n\nvoid rec_call(char c, int s)  // c = char to print s = rows to print \n{ \n static int i = 0; \n while(i < s) \n { \n      int width = s + i; \n      int len = 1 + (2 * i); \n      char temp[len + 1]; \n      for(int count = 0; count < len; count++) \n              temp[count] = c; \n      temp[len] = '&#92;0'; \n      cout << endl << setw(width) << temp; \n      i++; \n      rec_call(c, s); \n      if(i == s) \n      { \n         i++; \n         return; \n      } \n\n      cout << endl << setw(width) << temp; \n  } \n\n\n\n}
120558
Another answer suggested you could write your own\ncomplex functions, and while strictly possible, puts\na lot more burden on you than you might want.  There's\nvery little reason to reinvent the wheel.\n\nThe good news is that complex numbers are supported\nby both the current C ("C99) and C++ ANSI/ISO standards.\nSo if you have a recent compiler, you will just be\nable to use the complex type.\n\nIn the C++ standard, see chapter 26 (specifically 26.2).\nThe header is <complex>, and all of the expected operators\nare provided.\n\nIn the C standard, see section 7.3.  The header is\n<complex.h>, and it uses the new built-in type "complex"\nto provide all of the functions that used to only\nbe provided for float and double.
524070
This is because you have ENTER character in STDIN when you call scanf second time. Flush SDIN before scanf.:\n\n#include<stdio.h>\nint main()\n{\nint x[10],i;\nchar choice;\ni=-1;\ndo\n{\ni=i+1;\nfflush( stdin );\nprintf("&#92;n Enter a value :");\nscanf("%d",&x[i]);\nfflush( stdin );\nprintf("&#92;n Add more (y/n) :");\nscanf("%c",&choice);\n}while(choice!='n');\nreturn 0;\n}
785470
There are numerous ways to do that. \nHere is, probably the simplest:\n\nchar *s="char *s=%c%s%c;%cmain() {printf(s,34,s,34,10,10);}%c";\nmain() {printf(s,34,s,34,10,10);}\n\nThe program itself is fairly useless.\nThe whole point of an exercise like this is the satisfaction of finding a solution yourself. Too bad, you did not give yourself a chance
551498
I'm no "C" expert, but in Delphi this is a Windows system call, and I'm sure it will be a similar implementation in C; just alter the syntax as necessary...
195727
Here is one way of doing it, using only what we've seen so far: \n\n#include <stdio.h>\n\nextern int getline(char [], int);\nextern int reverse(char [], int);\n\nint main()\n{\nchar line[100];\nint len;\n\nwhile((len = getline(line, 100)) != EOF)\n{\nreverse(line, len);\nprintf("%s&#92;n", line);\n}\n\nreturn 0;\n}\n\nint reverse(char string[], int len)\n{\nint i;\nchar tmp;\nfor(i = 0; i < len / 2; i = i + 1)\n{\ntmp = string[i];\nstring[i] = string[len - i - 1];\nstring[len - i - 1] = tmp;\n}\nreturn 0;\n}\n\nIn practice, it would be a nuisance to have to pass the length of the string to the reverse function. Strings in C are always terminated by the ``zero'' or ``nul'' character, represented by &#92;0. Therefore, reverse (or any piece of code) can always compute the length of a string, either by searching for the &#92;0, or by calling the library function strlen, which computes the length of a string by searching for the &#92;0. Here is how the program might look if the reverse function did not require that the length of the string be passed in: \n#include <stdio.h>\n#include <string.h>\n\nextern int getline(char [], int);\nextern int reverse(char []);\n\nint main()\n{\nchar line[100];\n\nwhile(getline(line, 100) != EOF)\n{\nreverse(line);\nprintf("%s&#92;n", line);\n}\n\nreturn 0;\n}\n\nint reverse(char string[])\n{\nint len = strlen(string);\nint i;\nchar tmp;\nfor(i = 0; i < len / 2; i = i + 1)\n{\ntmp = string[i];\nstring[i] = string[len - i - 1];\nstring[len - i - 1] = tmp;\n}\nreturn 0;\n}
673244
Function overloading doesn't affect a programs execution speed in any way because the overloads are resolved at compile time which is virtually free.\nIt makes your program more understandable. Take an example.\nYou want to convert an integer into its equivalent ascii representation. There are many integral types in every major language (C++, Java, C#, VB.Net). Tell me what would you like to have:\nchar* itoa(int);\nchar* ltoa(long);\nchar* stoa(short);\nchar* lltoa(long long);\n\nor the simplified versions:\n\nchar* itoa(int);\nchar* itoa(long);\nchar* itoa(short);\nchar* itoa(long long);\n\n?
846187
if you are using a "while" or "do while" loop\n\nwhile ((x1 - x0) > 0.001)\n{\n//your code here\n}\n\nor you can do this\n\ndo\n{\n//your code here\n}\nwhile ((x1 - x0) > 0.001);
260093
Here it is:-\n\n/* Convert.cpp */\n/* Display the reverse of the input */\n/* By Senthil */\n\n#include <iostream.h>\n#include <conio.h>\n#include <string.h>\n\nvoid main()\n{\nchar inp[10];\nint cnt = 0, ex = 0;\nclrscr();\n\ncout<<"Enter some characters (max limit 10) : ";\ncin>>inp;\n\ncnt = strlen(inp);\ncnt--;\nfor(ex = 0;ex != cnt;ex++,cnt--)\n{\ninp[ex] = inp[cnt];\n}\ncout<<"The reverse of the string is : "<<inp;\ngetch();\n}
985771
You can generate this in one line of Perl, Unix scripting, or a small C/C++ program.  Simply write one number per line from your program counter.  You may have to get tricky and use two long ints, but it's not hard.\n\n Realize that your document may be very large, and for most purposes, you don't need a document, just use the variable(s) in your final program.
600562
Okay once again..\nStringBuffer b = buf.replace(6,10,"orld");\n\nThis replaces offset 6 to 10 with world... So offset 6 in your case is W so it would be:\nHello orld\n\nNow That is correct.. Now b.delete(0, 1)\nThat deletes the 0 offset which is H! only so it would be\nello\n\nNow the total StringBuffer Contents is:\nello orld\n\n\nSee why? Remember buffers is like a memory location that stores a buffer, so treat it as global scope in that case