Let’s start from the beginning, the addition of integers. I think you surely made this program already but you did’t done this in your program. If you do so, So Congrats!! you are going by the right way. Look at the program below and make out what you forgot to include in your program. And clear that bug. ►►
printf(“Enter the value of A and B\n”);
printf(“Sum = %ld”,a+b);
In the above program. I did not use an extra variable for showing the sum because I don;t need it further in the program so why to store it, I printed it out directly in the printf statement.One more thing make sure to use %ld format specifier for the output. Because the range of the integers is -32768 to 32767 but in many operations our output may cross the limit and it will result in unpredictable negative result.
As the output of 20,000 + 20,000 will equal to 40,000. %ld is a format specifier for long integers. So when your output cross the limit of integer, it will show by the long integer range.
In programming there is a rule that make minimum number of variables as to keep program size less and avoid extra lines of code(try to do in short). Also make ensure that by doing so you don’t loose the program completeness.
Truly saying it’s not a rule :D, it’s a convention but it is good to keep it as a rule for becoming a good programmer.