1. ## Help finding bugs

Hello, I'm completely new to programming and I'm really struggling to find the bugs in the following pieces of code. Please help me out.

Code 1:
Code:
```/* BUG ZONE!!!Example: integer arithmetic */

#include <stdio.h>

main()
{
int r1 = 22000;
int r2 = 10000;
int r3 = 15000;
int r;

puts("Three resistors in parallel");
printf("%i || %i || %i\n\n", r1, r2, r3);

puts("Method 1: r = (r1 * r2 * r3)/(r1*r2 + r2*r3 + r3*r1)\n");
r = (r1 * r2 * r3)/(r1*r2 + r2*r3 + r3*r1);  /* BUG */
printf("Total resistance = %i\n\n", r);

puts("Method 2: r = 1/(1/r1 + 1/r2 + 1/r3)\n");
r = 1/(1/r1 + 1/r2 + 1/r3);  /* BUG */
printf("Total resistance = %i\n", r);
}```

Code 2:
Code:
```/* BUG ZONE!!!
Example: integer arithmetic */

#include <stdio.h>

main()
{
int StudentsInClass = 116;
int MaxGroupSize = 5;
int NumberOfGroups;
int passes;
int GirlsWithBrownEyes;

NumberOfGroups = StudentsInClass/MaxGroupSize; /* BUG */

printf("%i students at %i max. per group means %i groups\n\n",
StudentsInClass, MaxGroupSize, NumberOfGroups);

/* Three-quarters of the class pass the exam: */

passes = 3/4 * StudentsInClass;  /* BUG */
printf("%i students passed the exam!\n\n", passes);

/* Half the students are female, and
half of these have brown eyes */

GirlsWithBrownEyes = StudentsInClass / 2*2;  /* BUG */

printf("There are %i brown-eyed girls in the class\n",
GirlsWithBrownEyes);
}``` 2. Consider things like
- integer overflow
- division by zero
- integer division truncates (no fractions). 3. Thanks for replying. So do I just need to replace the ints with floats? 4. Have you tried doing that and seeing the results? It takes literally seconds to compile and run a program of this size, so doing some experimentation would help you test your ideas.

Code:
`3/4`
This is an example of what Salem was talking about. 3 and 4 are both integers, and integer division yields an integer result (i.e. any fractional part is discarded).

`3.0 / 4.0` Popular pages Recent additions bug, bugs, code, int, students 