C Unit 5 Answer
C Unit 5 Answer
Problem stattement
Input format :
The first line contains an integer n, representing the size of the array.
Output format :
Code constraints :
In this scenario, the test cases fall under the following constraints:
1<= n <=100
1<=elements <=20
Problem Statement
Sharon wants to create a program that declares and initializes
pointers of various types (void, integer, character, and float) and
prints their sizes using the sizeof operator.
Input format :
No console input.
Output format :
The first line of output displays "Void Pointer = " followed by the size
of the void pointer.
The second line displays "Integer Pointer = " followed by the size of
the integer pointer.
The third line displays "Character Pointer = " followed by the size of
the character pointer.
The fourth line displays "Float Pointer = " followed by the size of the
float pointer.
Problem Statement
Input format :
The first line of input consists of an integer N, representing the array
size.
Output format :
Code constraints :
In this scenario, the test cases fall under the following constraints:
1 ≤ N ≤ 10
1 ≤ array elements ≤ 20
#include <stdio.h>
int main(){
float avg=0;
int sum=0;
int count=0;
int n;
scanf("%d",&n);
int arr[n];
for(int i=0;i<n;i++){
scanf("%d",&arr[i]);
}
if (count > 0) {
avg =(float)sum / count;
printf("%.1f\n", avg);
} else {
printf("0.0\n");
}
return 0;
}
Problem Statement
Note:
The number of students in School A is three times the number of
students in School B.
The number of students in School C is 120 more than the combined
number of students in School A and School B.
Create a program using pointers to help Simba that takes the number
of students in School B as input and calculates the total number of
students in each school and overall students in the town.
Input format :
Output format :
The first line of output prints "Total Students in School A: ", followed
by the total number of students in School A.
The second line prints "Total Students in School B: ", followed by the
total number of students in School B.
The third line prints "Total Students in School C: " followed by the
total number of students in School C.
The fourth line prints "Overall Student Count: " followed by the total
number of students in all three schools.
Code constraints :
In this scenario, the test cases fall under the following constraints:
20 ≤ N ≤ 250
Problem Statement
Input format :
Output format :
The output prints "Result of the expression: ", followed by the result.
Code constraints :
In this scenario, the test cases fall under the following constraints:
1 ≤ m, n ≤ 10
Input 2 :
34
Output 2 :
Result of the expression: 36
Note :
The program will be evaluated only after the “Submit Code” is
clicked.
Extra spaces and new line characters in the program output will
result in the failure of the test case.
Problem Statement
Jai is creating a program to find the maximum number from the given
two integers using pointers.
Input format :
Output format :
Code constraints :
In this scenario, the test cases fall under the following constraints:
Problem Statement
Sarah and Tom love pizza! They decided to share a pizza, but they
were curious about how many pizza slices they had eaten. Help them
by creating a program using pointers that calculate the fraction of the
pizza slices they have eaten.
Input format :
Output format :
The output prints "Sarah and Tom, together ate X/Y of the pizza."
where X is the number of slices Sarah and Tom ate and Y is the total
slices.
Code constraints :
1 ≤ N ≤ 100
Problem Statement
Alex has a credit card debt of a certain amount with a specified
annual interest rate. He makes regular monthly payments to pay off
the debt.
Write a program to determine how many months it will take for Alex
to pay off the debt, given the debt amount, annual interest rate, and
monthly payment. Utilize pointers to calculate the result.
Input format :
The output prints the number of months it will take for Alex to pay
off the debt.
Code constraints :
In this scenario, the test cases fall under the following constraints:
Output 1 :
27 months
Input 2 :
10000.00
8.5
300.00
Output 2 :
39 months
Note :
The program will be evaluated only after the “Submit Code” is
clicked.
Extra spaces and new line characters in the program output will
result in the failure of the test case.
#include <stdio.h>
int main() {
float debt, interest_rate, monthly;
int months = 0;
scanf("%f", &debt);
scanf("%f", &interest_rate);
scanf("%f", &monthly);
return 0;
}