C PROGRAMMING PROGRAM • BASICS & INPUT/OUTPUT
Read and Display Different Data Types
Learn how to read and display different data types using a clear C program.
PROBLEM UNDERSTANDING
Input and expected output
Sample input
18 86.5 A
Sample output
Age = 18 Percentage = 86.50 Grade = A
COMPLETE C PROGRAM
Complete C implementation
#include <stdio.h>
int main(void)
{
int age;
float percentage;
char grade;
printf("Enter age, percentage and grade: ");
scanf("%d %f %c", &age, &percentage, &grade);
printf("Age = %d\nPercentage = %.2f\nGrade = %c\n", age, percentage, grade);
return 0;
}CURRENT STEP
SELECTED LINE
EXPECTED OUTPUT FOR THE SAMPLE
Age = 18 Percentage = 86.50 Grade = A
Step 0 of 0
PROGRAM EXPLANATION
Algorithm and explanation
- Read the required input values.
- Read values with matching format specifiers and print them using controlled formatting.
- Display the computed result.
Read values with matching format specifiers and print them using controlled formatting.
EFFICIENCY
Time and space complexity
Time complexity
O(1)
Auxiliary space
O(1)
DEBUGGING CHECKLIST
Common mistakes
Check this
Use the correct format specifier for every variable.
Check this
Initialize variables before using their values.
Check this
Check braces, semicolons and input order carefully.
Try it yourself
Practice: Run the program with the sample input, predict its output, and then test one boundary case of your own.
