Technical Hands - Day 5

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

Technical Hands-on

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

calculatesum( int sum)


{
int sum = a + b;
return 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);

void calculate_cost (int n)


{
Printf ("\nCalculating ticket cost for %d people",n);
return n * 150;
}
Expected output:
Enter number of passengers: 5
Calculating ticket cost for 5 people
Ticket cost is: 750

Question: 5

Your task is to debug and fix the given code so that your code executes successfully can
returns expected output mentioned below.

If I input ‘1’ the program should print odd numbers from 0 to 10


If I input ‘0’ the program should print even numbers from 0 to 10

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

You might also like