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);
}