Skip to content

Commit 4270ddc

Browse files
committed
hi
1 parent d8a222e commit 4270ddc

16 files changed

+16
-16
lines changed

arraySearch.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ int main() {
2525

2626

2727
// HERE IS THE BUG, WE MISSED THE FIRST ELEMENT OF THE ARRAY. CHANGE i=1 to i=0
28-
i = 1;
28+
i = 0;
2929
while (i < num && ele != a[i]) {
3030
i++;
3131
}

average.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ int main()
2424
}
2525

2626
// HERE IS THE BUG, average is declared as int, that will give wrong output. CHANGE int average TO float average.
27-
int average;
27+
float average;
2828
average = sum / n;
2929
printf("Average = %.2f", average);
3030

binarySearch.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ int main(){
2525
l=0,u=n-1;
2626

2727
// HERE IS THE BUG, THE CONDITION SHOULD BE (l<=u).
28-
while(l<u){
28+
while(l<=u){
2929
mid=(l+u)/2;
3030
if(m==a[mid]){
3131
c=1;

bubbleSort.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ void main() {
2929
void bubble_sort(int iarr[], int num) {
3030
int i, j, k, temp;
3131
for (i = 1; i < num; i++) {
32-
for (j = 0; j < num; j++) {
32+
for (j = 0; j < num-1; j++) {
3333
if (iarr[j] > iarr[j + 1]) {
3434
temp = iarr[j];
3535
iarr[j] = iarr[j + 1];

evenorodd.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ int main(){
1616
scanf("%d",&number);
1717

1818
// HERE IS THE BUG, number % 2 == 0 means even
19-
if(number % 2 != 0)
19+
if(number % 2 == 0)
2020
printf("%d is even number.",number);
2121
else
2222
printf("%d is odd number.",number);

factorial.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ int main()
2121
else
2222
{
2323
// HERE IS THE BUG, CHANGE i<n to i<=n
24-
for(i=1; i<n; ++i)
24+
for(i=1; i<=n; ++i)
2525
{
2626
factorial *= i;
2727
}

gcd.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ int main()
1414
printf("Enter two integers: ");
1515

1616
// HERE IS THE BUG, ADD '&' in front of n1
17-
scanf("%d %d", n1, &n2);
17+
scanf("%d %d", &n1, &n2);
1818

1919
for(i=1; i <= n1 && i <= n2; ++i)
2020
{

largest.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ int main()
2323
printf("Enter Number %d: ", i+1);
2424

2525
// HERE IS THE BUG, PUT '&' IN FRONT OF arr[i]
26-
scanf("%f", arr[i]);
26+
scanf("%f", &arr[i]);
2727
}
2828

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

leap.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ int main()
2020
if( year%100 == 0)
2121
{
2222
// HERE IS THE BUG, WHEN YEAR%400 == 0, THEN IT IS LEAP YEAR!!
23-
if ( year%400 != 0)
23+
if ( year%400 == 0)
2424
printf("%d is a leap year.", year);
2525
else
2626
printf("%d is not a leap year.", year);

lenString.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@ int main()
1717
for(i = 0; s[i] != '\0'; ++i);
1818

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

lowertoupper.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ int main(){
1515
printf("The string is = %s",str);
1616
for(i=0;i<=strlen(str);i++){
1717
// HERE IS THE BUG, THE RANGE OF SMALL CASE LETTERS IS 97 TO 122.
18-
if(str[i]>=98&&str[i]<=121)
18+
if(str[i]>=97&&str[i]<=121)
1919
str[i]=str[i]-32;
2020
}
2121
printf("\nThe string in lowercase is = %s",str);

palindrome.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ int main()
2323

2424
// HERE IS THE BUG, THE BELOW LINE SHOULD BE UNCOMMENTED FOR THIS PROGRAM TO WORK PROPERLY
2525

26-
// n /= 10;
26+
n /= 10;
2727
}
2828

2929
if (originalInteger == reversedInteger)

prime.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ int main()
2424
}
2525

2626
// HERE IS THE BUG, NUMBER WILL BE PRIME WHEN THE VALUE OF FLAG IS EQUAL TO 0. CHANGE != to ==
27-
if (flag!=0)
27+
if (flag==0)
2828
printf("%d is a prime number.",n);
2929
else
3030
printf("%d is not a prime number.",n);

reverse.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ int main()
2020
reversedNumber = reversedNumber*10 + remainder;
2121

2222
// HERE IS THE BUG, n SHOULD BE DIVIDED BY 10 ON EACH ITERATION, NOT BY 100
23-
n /= 100;
23+
n /= 10;
2424
}
2525

2626
printf("Reversed Number = %d", reversedNumber);

sumofdigits.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ void main()
2121
sum = sum + digit;
2222

2323
// HERE IS THE BUG, n SHOULD BE DIVIDED BY 10 ON EACH ITERATION, NOT BY 100
24-
num /= 100;
24+
num /= 10;
2525
}
2626
printf("Given number = %ld\n", temp);
2727
printf("Sum of the digits %ld = %ld\n", temp, sum);

sumofseries.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ int main(){
2020
printf("Sum of the series: ");
2121

2222
// HERE IS THE BUG, LOOP SHOULD GO UPTO AND INCLUDING n, change < to <=
23-
for(i =1;i <n n;i++){
23+
for(i =1;i <=n n;i++){
2424
if (i!=n)
2525
printf("%d + ",i);
2626
else

0 commit comments

Comments
 (0)