0% found this document useful (0 votes)
3 views

Code Debugging RAW

The document outlines a coding challenge divided into three rounds focusing on fixing syntax errors, logical errors in loops, and memory/runtime errors across C, C++, and Python languages. Each round provides code snippets with specific errors that need to be identified and corrected. The challenges aim to test and improve debugging skills in various programming languages.

Uploaded by

muttatakkail
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Code Debugging RAW

The document outlines a coding challenge divided into three rounds focusing on fixing syntax errors, logical errors in loops, and memory/runtime errors across C, C++, and Python languages. Each round provides code snippets with specific errors that need to be identified and corrected. The challenges aim to test and improve debugging skills in various programming languages.

Uploaded by

muttatakkail
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Code Debugging

Round 1: Fix the Syntax Error

Challenge Description

In this round, you need to identify and fix syntax errors in code snippets
across three programming languages.

C Language

#include <stdio.h>

int main() {
int a = 5, b = 10;
printf("Sum of two numbers: " + a + b);
return 0;
}

C++ Language

#include <iostream>
using namespace std;

int main() {
int x = 8, y = 12;
cout << "The sum is: " << x + y << endl
return 0;
}
Python Language

def calculate_average(numbers):
total = sum(numbers)
average = total/len(numbers)
return average

my_list = [4, 7, 9, 2, 8]
result = calculate_average
print(f"The average is: {result}")

Round 2: Logical Error in Loop

Challenge Description

In this round, you need to identify and fix logical errors in loop constructs
across three programming languages.

C Language

#include <stdio.h>

int main() {
int i = 1;
while (i < 5);
{
printf("%d ", i);
i++;
}
return 0;
}
C++ Language

#include <iostream>
#include <vector>
using namespace std;

int main() {
vector<int> values = {10, 20, 30, 40, 50};
int sum = 0;

for (int i = 0; i < values.size(); i += 2) {


sum += values[i+1];
}

cout << "Sum of odd-indexed elements: " << sum << endl;
return 0;
}

Python Language

i = 1
while i <= 5:
print(i)
i = i - 1

Round 3: Fix Memory/Runtime Error

Challenge Description

In this round, you need to identify and fix memory/runtime errors in code
snippets across three programming languages.
C Language

#include <stdio.h>
#include <stdlib.h>

struct Node {
int data;
struct Node* next;
};

void printList(struct Node* head) {


struct Node* current = head;
while (current != NULL) {
printf("%d -> ", current->data);
current = current->next;
}
printf("NULL\n");
}

int main() {
struct Node* head = (struct Node*)malloc(sizeof(struct Node));
struct Node* second = (struct Node*)malloc(sizeof(struct Node));
struct Node* third = (struct Node*)malloc(sizeof(struct Node));

head->data = 1;
head->next = second;

second->data = 2;
second->next = third;

third->data = 3;
third->next = NULL;

printList(head);

free(head);
free(third);
return 0;
}

C++ Language

#include <iostream>
using namespace std;

int main() {
int n = 5;
int *arr = new int[n]{4, 2, 7, 1, 8};
int max_val = arr[0];
for (int i = 0; i <= n; i++) {
if (arr[i] > max_val)
max_val = arr[i];
}
delete arr;
cout << "Maximum: " << max_val << endl;
return 0;
}

Python Language

arr = [4, 8, 1, 6]
max_val = arr[0]
for i in range(5):
if arr[i] > max_val:
max_val = arr[i]
print("Max:", max_val)

You might also like