Problem 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
Problem 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
Here is a simple C program that meets the requirements of the problem statement:
#include <stdio.h>
int main() {
// Declare variables with appropriate data types
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/output operations. The main function is then defined, which is the entry point of the program.
Inside the main function, three variables are declared to store Alice's scores: quizScore (an integer), projectGrade (a float), and assignmentGrade (a character). These variables are initialized with the values specified in the problem statement.
The printf function is then used to print these values to the console. The %d format specifier is used for the integer, the %.6f format specifier is used for the float (to ensure that it is printed with six digits after the decimal point), and the %c format specifier is used for the character. Each value is printed on a separate line, as specified in the problem statement.
Finally, the main function returns 0 to indicate that the program has finished successfully.
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:*
Problem StatementA computer science teacher assigned the students a programming task that calculates and displays grades based on test marks. The teacher wants the program to take a student's test mark as input and determine their grade using the following criteria:If the mark is between 90 and 100 (inclusive), assign grade A.If the mark is between 80 and 89 (inclusive), assign grade B.If the mark is between 70 and 79 (inclusive), assign grade C.If the mark is between 60 and 69 (inclusive), assign grade D.If the mark is between 45 and 59 (inclusive), assign grade E.For marks below 45 assign grade F.If the mark is greater than 100 or a negative number, it displays "Invalid input". Help the students to accomplish the given task.Note: This question helps in clearing AMCAT exam.Input format :The input consists of a single integer, representing the student's mark.Output format :The output displays "Grade: " followed by the grade for the given mark based on the given criteria.If the mark is greater than 100 or a negative number, the output displays "Invalid input".Refer to the sample output for the formatting specifications.Code constraints :In the given scenario, the test cases fall under the following constraints:0 ≤ student's mark ≤ 100Sample test cases :Input 1 :100Output 1 :Grade: AInput 2 :85Output 2 :Grade: BInput 3 :79Output 3 :Grade: CInput 4 :63Output 4 :Grade: DInput 5 :56Output 5 :Grade: EInput 6 :0Output 6 :Grade: FInput 7 :-5Output 7 :Invalid inputInput 8 :126Output 8 :Invalid input
Problem 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.Marks : 10Negative Marks : 0WhitelistSet 1:voidSet 2:*
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.