Skip to content

Commit 46889f5

Browse files
committed
introduce bugs in programs
1 parent a69a9d7 commit 46889f5

21 files changed

+227
-68
lines changed

armstrong.c

+12-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,21 @@
1+
/*********
2+
3+
Author1 Name:
4+
Author2 Name:
5+
6+
FIXED THE BUGS FOR GIT-WORKSHOP
7+
8+
**********/
9+
110
#include <stdio.h>
211
int main()
312
{
413
int number, originalNumber, remainder, result = 0;
514

615
printf("Enter a three digit integer: ");
7-
scanf("%d", &number);
16+
17+
// HERE IS THE BUG, PUT A '&' IN FRONT OF number.
18+
scanf("%d", number);
819

920
originalNumber = number;
1021

arraySearch.c

+11-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
/*********
2+
3+
Author1 Name:
4+
Author2 Name:
5+
6+
FIXED THE BUGS FOR GIT-WORKSHOP
7+
8+
**********/
19
#include<stdio.h>
210

311
int main() {
@@ -15,8 +23,9 @@ int main() {
1523
printf("\nEnter the elements to be searched :");
1624
scanf("%d", &ele);
1725

18-
//Search starts from the zeroth location
19-
i = 0;
26+
27+
// HERE IS THE BUG, WE MISSED THE FIRST ELEMENT OF THE ARRAY. CHANGE i=1 to i=0
28+
i = 1;
2029
while (i < num && ele != a[i]) {
2130
i++;
2231
}

average.c

+11-8
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,30 @@
1+
/*********
2+
3+
Author1 Name:
4+
Author2 Name:
5+
6+
FIXED THE BUGS FOR GIT-WORKSHOP
7+
8+
**********/
19
#include <stdio.h>
210

311
int main()
412
{
513
int n, i;
6-
float num[100], sum = 0.0, average;
14+
float num[100], sum = 0.0;
715

816
printf("Enter the numbers of elements: ");
917
scanf("%d", &n);
1018

11-
while (n > 100 || n <= 0)
12-
{
13-
printf("Error! number should in range of (1 to 100).\n");
14-
printf("Enter the number again: ");
15-
scanf("%d", &n);
16-
}
17-
1819
for(i = 0; i < n; ++i)
1920
{
2021
printf("%d. Enter number: ", i+1);
2122
scanf("%f", &num[i]);
2223
sum += num[i];
2324
}
2425

26+
// HERE IS THE BUG, average is declared as int, that will give wrong output. CHANGE int average TO float average.
27+
int average;
2528
average = sum / n;
2629
printf("Average = %.2f", average);
2730

binarySearch.c

+11-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
/*********
2+
3+
Author1 Name:
4+
Author2 Name:
5+
6+
FIXED THE BUGS FOR GIT-WORKSHOP
7+
8+
**********/
19
#include<stdio.h>
210
int main(){
311

@@ -15,7 +23,9 @@ int main(){
1523
scanf("%d",&m);
1624

1725
l=0,u=n-1;
18-
while(l<=u){
26+
27+
// HERE IS THE BUG, THE CONDITION SHOULD BE (l<=u).
28+
while(l<u){
1929
mid=(l+u)/2;
2030
if(m==a[mid]){
2131
c=1;

bubbleSort.c

+18-16
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,44 @@
1+
/*********
2+
3+
Author1 Name:
4+
Author2 Name:
5+
6+
FIXED THE BUGS FOR GIT-WORKSHOP
7+
8+
**********/
19
#include<stdio.h>
2-
#include<conio.h>
310

411
void bubble_sort(int[], int);
512

613
void main() {
714
int arr[30], num, i;
815

9-
printf("\nEnter no of elements :");
16+
printf("Enter no of elements :");
1017
scanf("%d", &num);
1118

12-
printf("\nEnter array elements :");
19+
printf("Enter array elements :");
1320
for (i = 0; i < num; i++)
1421
scanf("%d", &arr[i]);
1522

1623
bubble_sort(arr, num);
17-
getch();
24+
printf("\n");
1825
}
1926

27+
28+
// HERE IS THE BUG, IN THE INNER LOOP, CHANGE j < num to j < num-1
2029
void bubble_sort(int iarr[], int num) {
2130
int i, j, k, temp;
22-
23-
printf("\nUnsorted Data:");
24-
for (k = 0; k < num; k++) {
25-
printf("%5d", iarr[k]);
26-
}
27-
2831
for (i = 1; i < num; i++) {
29-
for (j = 0; j < num - 1; j++) {
32+
for (j = 0; j < num; j++) {
3033
if (iarr[j] > iarr[j + 1]) {
3134
temp = iarr[j];
3235
iarr[j] = iarr[j + 1];
3336
iarr[j + 1] = temp;
3437
}
3538
}
36-
37-
printf("\nAfter pass %d : ", i);
38-
for (k = 0; k < num; k++) {
39-
printf("%5d", iarr[k]);
40-
}
4139
}
40+
41+
for (k = 0; k < num; k++) {
42+
printf("%5d", iarr[k]);
43+
}
4244
}

evenorodd.c

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
/*********
2+
3+
Author1 Name:
4+
Author2 Name:
5+
6+
FIXED THE BUGS FOR GIT-WORKSHOP
7+
8+
**********/
19
#include<stdio.h>
210

311
int main(){
@@ -7,7 +15,8 @@ int main(){
715
printf("Enter any integer: ");
816
scanf("%d",&number);
917

10-
if(number % 2 ==0)
18+
// HERE IS THE BUG, number % 2 == 0 means even
19+
if(number % 2 != 0)
1120
printf("%d is even number.",number);
1221
else
1322
printf("%d is odd number.",number);

factorial.c

+11-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
/*********
2+
3+
Author1 Name:
4+
Author2 Name:
5+
6+
FIXED THE BUGS FOR GIT-WORKSHOP
7+
8+
**********/
19
#include <stdio.h>
210
int main()
311
{
@@ -7,15 +15,15 @@ int main()
715
printf("Enter an integer: ");
816
scanf("%d",&n);
917

10-
// show error if the user enters a negative integer
1118
if (n < 0)
1219
printf("Error! Factorial of a negative number doesn't exist.");
1320

1421
else
1522
{
16-
for(i=1; i<=n; ++i)
23+
// HERE IS THE BUG, CHANGE i<n to i<=n
24+
for(i=1; i<n; ++i)
1725
{
18-
factorial *= i; // factorial = factorial*i;
26+
factorial *= i;
1927
}
2028
printf("Factorial of %d = %llu", n, factorial);
2129
}

fibonacci.c

+10
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
/*********
2+
3+
Author1 Name:
4+
Author2 Name:
5+
6+
FIXED THE BUGS FOR GIT-WORKSHOP
7+
8+
**********/
9+
10+
// NO BUGS IN THIS PROGRAM
111
#include <stdio.h>
212

313
main()

gcd.c

+11-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,20 @@
1+
/*********
2+
3+
Author1 Name:
4+
Author2 Name:
5+
6+
FIXED THE BUGS FOR GIT-WORKSHOP
7+
8+
**********/
19
#include <stdio.h>
210
int main()
311
{
412
int n1, n2, i, gcd;
513

614
printf("Enter two integers: ");
7-
scanf("%d %d", &n1, &n2);
15+
16+
// HERE IS THE BUG, ADD '&' in front of n1
17+
scanf("%d %d", n1, &n2);
818

919
for(i=1; i <= n1 && i <= n2; ++i)
1020
{

greatestof3.c

+13-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
/*********
2+
3+
Author1 Name:
4+
Author2 Name:
5+
6+
FIXED THE BUGS FOR GIT-WORKSHOP
7+
8+
**********/
9+
10+
// NO BUGS IN THIS PROGRAM
111
#include<stdio.h>
212

313
int main() {
@@ -7,13 +17,13 @@ int main() {
717
scanf("%d %d %d", &a, &b, &c);
818

919
if ((a > b) && (a > c))
10-
printf("\na is greatest");
20+
printf("\a is greatest");
1121

1222
if ((b > c) && (b > a))
13-
printf("\nb is greatest");
23+
printf("\b is greatest");
1424

1525
if ((c > a) && (c > b))
16-
printf("\nc is greatest");
26+
printf("\c is greatest");
1727

1828
return(0);
1929
}

largest.c

+11-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
/*********
2+
3+
Author1 Name:
4+
Author2 Name:
5+
6+
FIXED THE BUGS FOR GIT-WORKSHOP
7+
8+
**********/
19
#include <stdio.h>
210

311
int main()
@@ -13,7 +21,9 @@ int main()
1321
for(i = 0; i < n; ++i)
1422
{
1523
printf("Enter Number %d: ", i+1);
16-
scanf("%f", &arr[i]);
24+
25+
// HERE IS THE BUG, PUT '&' IN FRONT OF arr[i]
26+
scanf("%f", arr[i]);
1727
}
1828

1929
// Loop to store largest number to arr[0]

leap.c

+10-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
/*********
2+
3+
Author1 Name:
4+
Author2 Name:
5+
6+
FIXED THE BUGS FOR GIT-WORKSHOP
7+
8+
**********/
19
#include <stdio.h>
210

311
int main()
@@ -11,8 +19,8 @@ int main()
1119
{
1220
if( year%100 == 0)
1321
{
14-
// year is divisible by 400, hence the year is a leap year
15-
if ( year%400 == 0)
22+
// HERE IS THE BUG, WHEN YEAR%400 == 0, THEN IT IS LEAP YEAR!!
23+
if ( year%400 != 0)
1624
printf("%d is a leap year.", year);
1725
else
1826
printf("%d is not a leap year.", year);

lenString.c

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
/*********
2+
3+
Author1 Name:
4+
Author2 Name:
5+
6+
FIXED THE BUGS FOR GIT-WORKSHOP
7+
8+
**********/
19
#include <stdio.h>
210
int main()
311
{
@@ -8,6 +16,7 @@ int main()
816

917
for(i = 0; s[i] != '\0'; ++i);
1018

11-
printf("Length of string: %d", i);
19+
// HERE IS THE BUG, LENGTH OF THE STRING WILL BE EQUAL TO i, not (i-1)
20+
printf("Length of string: %d", i-1);
1221
return 0;
1322
}

lowertoupper.c

+13-4
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,23 @@
1+
/*********
2+
3+
Author1 Name:
4+
Author2 Name:
5+
6+
FIXED THE BUGS FOR GIT-WORKSHOP
7+
8+
**********/
19
#include<stdio.h>
210
int main(){
311
char str[20];
412
int i;
513
printf("Enter any string->");
614
scanf("%s",str);
7-
printf("The string is->%s",str);
15+
printf("The string is = %s",str);
816
for(i=0;i<=strlen(str);i++){
9-
if(str[i]>=97&&str[i]<=122)
10-
str[i]=str[i]-32;
17+
// HERE IS THE BUG, THE RANGE OF SMALL CASE LETTERS IS 97 TO 122.
18+
if(str[i]>=98&&str[i]<=121)
19+
str[i]=str[i]-32;
1120
}
12-
printf("\nThe string in lowercase is->%s",str);
21+
printf("\nThe string in lowercase is = %s",str);
1322
return 0;
1423
}

0 commit comments

Comments
 (0)