Single File Programming QuestionProblem StatementAlice is tracking her academic performance. She scored 5 in a quiz (an integer), received a grade of 5.99 in a project (a float value), and was assigned a grade 'D' for her assignment (a character). Create a C program to print these values with appropriate data types in separate lines.Input format :No console input.Output format :The first line displays an integer representing the score of Alice's quiz.The second line displays a float value representing the grade of Alice's project.The third line displays a character representing the grade of Alice's assignment.Refer to the sample output for the formatting specifications.Sample test cases :Input 1 :Output 1 :55.990000D
Question
Single File Programming QuestionProblem StatementAlice is tracking her academic performance. She scored 5 in a quiz (an integer), received a grade of 5.99 in a project (a float value), and was assigned a grade 'D' for her assignment (a character). Create a C program to print these values with appropriate data types in separate lines.Input format :No console input.Output format :The first line displays an integer representing the score of Alice's quiz.The second line displays a float value representing the grade of Alice's project.The third line displays a character representing the grade of Alice's assignment.Refer to the sample output for the formatting specifications.Sample test cases :Input 1 :Output 1 :55.990000D
Solution 1
Here is a simple C program that meets the requirements:
#include <stdio.h>
int main() {
int quiz_score = 5;
float project_grade = 5.99;
char assignment_grade = 'D';
printf("%d\n", quiz_score);
printf("%.6f\n", project_grade);
printf("%c\n", assignment_grade);
return 0;
}
This program first includes the standard input/output library. Then, in the main function, it declares and initializes three variables: quiz_score (an integer), project_grade (a float), and assignment_grade (a character).
It then uses the printf function to print these values. The %d format specifier is used for the integer, %.6f for the float (to ensure it always prints with 6 digits after the decimal point), and %c for the character. Each value is printed on a new line (\n).
The program then returns 0 to indicate successful execution.
Solution 2
Here is a simple C program that meets the requirements of the problem statement:
#include <stdio.h>
int main() {
// Declare and initialize variables
int quizScore = 5;
float projectGrade = 5.99;
char assignmentGrade = 'D';
// Print the values
printf("%d\n", quizScore);
printf("%.6f\n", projectGrade);
printf("%c\n", assignmentGrade);
return 0;
}
This program first includes the stdio.h header file, which allows it to perform input and output operations. It then defines the main function, which is the entry point of the program.
Inside the main function, it declares and initializes three variables: quizScore (an integer), projectGrade (a float), and assignmentGrade (a character). These variables are initialized with the values specified in the problem statement.
Finally, it uses the printf function to print the values of these variables. The %d, %.6f, and %c format specifiers are used to print an integer, a float with six digits after the decimal point, and a character, respectively. Each value is printed on a separate line, as required by the problem statement.
Similar Questions
Single File Programming QuestionProblem StatementA school administrator needs to display the information of a student. The student has an ID (an integer) of 15, an age (an integer) of 23 and achieved a grade (a character) 'B'. Write a C program to print these details using appropriate data types and formatting.Input format :No console input.Output format :The output displays the values in the below format:Student id: 15Student age: 23Student grade: BRefer to the sample output for the formatting specification
Single File Programming QuestionProblem StatementJamie is managing a school and is looking to find out the number of students in the class based on the sum of their scores and the average score.He wants to design a program that takes the average score and sum of scores as input and outputs the calculated number of students in the class using pointers.Input format :The first line of input consists of an integer value n, representing the sum of scores.The second line of input consists of a floating-point value f, representing the average score.Output format :The output displays the calculated number of students in the class.Refer to the sample output for the formatting specifications.Code constraints :In this scenario, the test cases fall under the following constraints:1 ≤ n ≤ 1051.0 ≤ f ≤ 100.0Sample test cases :Input 1 :187575.45Output 1 :24Input 2 :20010.25Output 2 :19Note :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.Marks : 10Negative Marks : 0WhitelistSet 1:*
Single File Programming QuestionProblem StatementJohn is eager to create a simple program for gathering and presenting personal details. Write a program that prompts users to provide the initial letter of their name (a character), age (an integer), and height in meters (a floating-point number).After collecting this information, display it in a well-organized format.Input format :The input consists of three space-separated values, representing the first letter of the name (character), age (integer), and height in meters (floating point value), separated by spaces.Output format :The first line prints the initial of the name in the format "Initial: [initial]"The second line prints the age in the format "Age: [age] years"The third line prints the height of the person, rounded to two decimal places, in the format "Height: [height] meters"Refer to the sample output for formatting specifications.Code constraints :In the given scenario, the test cases will fall under the following constraints:10 ≤ Age ≤ 500.01 ≤ Height ≤ 1.80Sample test cases :Input 1 :A 10 1.35Output 1 :Initial: AAge: 10 yearsHeight: 1.35 metersInput 2 :b 25 1.70Output 2 :Initial: bAge: 25 yearsHeight: 1.70 metersInput 3 :Z 28 1.80Output 3 :Initial: ZAge: 28 yearsHeight: 1.80 metersCode Size : 1024 kbNote :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.Marks : 10Negative Marks : 0
Single File Programming QuestionProblem StatementAman is assigned a program that takes a generic pointer (void *) to handle different data types. You have to guide him in completing the program.The program prompts the user to input a data type identifier ('i' for integer, 'f' for float) and a corresponding value. Using a switch statement, print the entered value with the appropriate data type label. Any other input except ('i' and 'f') is given, print "Invalid type entered!" Input format :The first line of input consists of a character, representing a data type (i for integer or f for float).If the character is i, the second line consists of an integer value.If the character is f, the second line consists of a floating-point value.Output format :If the character is i, print "Integer: " followed by the integer value.If the character is f, print "Float: " followed by the float value, rounded off to two decimal places.If any other character is entered, print "Invalid type entered!"Refer to the sample output for formatting specifications.Code constraints :In this scenario, the test cases fall under the following constraints:1 ≤ integer ≤ 1501.0 ≤ float ≤ 150.0Sample test cases :Input 1 :i4Output 1 :Integer: 4Input 2 :f5.5Output 2 :Float: 5.50Input 3 :p50Output 3 :Invalid type entered!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.
Single File Programming QuestionProblem StatementMark wants to calculate his monthly savings based on his salary and a specified savings percentage.Write a program to help Mark that input the monthly salary and the percentage of the salary to save. Use pointers to calculate the amount to save. Display the calculated amount with two decimal places.Input format :The first line of input consists of a floating-point value, representing the monthly salary.The second line consists of a floating-point value, representing the savings percentage.Output format :The output prints a floating-point value, representing the calculated savings amount, rounded off to two decimal places.Refer to the sample output for formatting specifications.Code constraints :In this scenario, the test cases fall under the following constraints:1.00 ≤ monthly salary ≤ 1,00,000.001.00 ≤ percentage ≤ 100.00Sample test cases :Input 1 :10000.5010.75Output 1 :1075.05Input 2 :80575.2514.50Output 2 :11683.41Note :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.Marks : 10Negative Marks : 0WhitelistSet 1:*
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.