Professional Documents
Culture Documents
Technical Hands - Day 5
Technical Hands - Day 5
Technical Hands - Day 5
Practice set – 5
Question: 1
Your task is to debug and fix the given code so that your code executes successfully and
returns expected output mentioned below.
Code:
#include <stdio.h>
int main()
{
PrintMax();
}
printMax()
{
int num1, num2;
scanf("%d", &num1);
scanf("%d", &num2);
if (num1 > num2)
printf ("%d", num1);
else
printf ("%d", num2);
}
Expected output:
i/p: 10
5
o/p: 10
Question: 2
Your task is to debug and fix the given code so that your code executes successfully and
returns expected output mentioned below.
Code:
#include <stdio.h>
void CalculateScore (int);
int main()
{
int score;
char grade;
scanf ("%d", &score);
grade = CalculateScore (score);
printf ("%c", grade);
}
void CalculateScore (score)
{
int score;
char grade;
if (score <= 60)
grade = 'D';
else if ((61 <= score) && (score <= 75))
grade = 'C';
if (score <= 90)
grade = 'B';
else
grade = 'A';
return grade;
}
Expected output:
i/p: 90
o/p: Grade A
Question: 3
Your task is to debug and fix the given code so that your code executes successfully and
returns expected output mentioned below.
Code:
#include <stdio.h>
int main()
{
int num1, num2, sum;
scanf ("%d %d", &num1, &num2);
sum = calculatesum (num1, num2);
printf ("\nSum = %d", sum);
}
Expected output:
i/p : 10, 80
o/p: 90
Question: 4
The given program checks whether the input integer is odd or even.
Your task is to debug and fix the given code so that your code executes successfully can
returns expected output mentioned below.
Code:
#include<stdio.h>
int calculate_cost(int);
int main()
{
int n, cost;
printf ("\nEnter number of passengers: ");
scanf ("%d", &n);
calculate_cost(n);
printf ("\nTicket cost is: %d", cost);
Question: 5
Your task is to debug and fix the given code so that your code executes successfully can
returns expected output mentioned below.
Code:
#include <stdio.h>
void PrintOdd(int);
void PrintEven(int);
int main()
{
int num;
printf("Enter 1 or 0 : \n")
scanf ("%d", &num);
if (num == 1)
PrintEven();
else
PrintOdd();
}
void PrintEven ()
{
Printf("Even numbers");
for(int x = 0; x<=10 ; x++)
{
if (x % 2 == 0)
printf("%d \n", x);
}
}
void PrintOdd ()
Expected { output:
Printf("Odd numbers");
i/p: 1 for(int x = 0; x<=10 ; x++)
o/p: {
Even numbersif (x % 2 != 0)
0 2 4 6 8 10printf("%d \n", x);
}
}