Formatted Report Printer:

Formatted Report Printer:

Medium C Control Flow 30 views
Explanation Complexity

Problem Statement

By printing student data (name, roll no, marks) in table format where columns are properly aligned. Names should be left-aligned, numbers right-aligned, and proper spacing maintained.

Input Format

Student records containing:

• name (string)

• roll number (integer)

• marks (integer/float)

Output Format

Student data printed in a table format with:

• Names left-aligned

• Roll numbers and marks right-aligned

• Proper column spacing

Example

Name | Roll | Marks
Amit 101 85
Neha 12 92
Rohit 5 78
Name        Roll    Marks
-------------------------
Amit         101       85
Neha          12       92
Rohit          5       78

Constraints

• Name length may vary

• Roll number and marks are numeric

• Number of students ≥ 1

Concept Explanation

The task is to display data in column-aligned tabular form so it looks clean and readable.

Step-by-Step Explanation

1.Decide fixed column widths for each field (e.g., Name = 12, Roll = 6, Marks = 8).

2.Print the table header using the same column widths.

3.Print a separator line for clarity.

4.For each student record:

• Print name using left alignment within the name column width.

• Print roll number using right alignment within the roll column width.

• Print marks using right alignment within the marks column width.

5.Ensure spacing is consistent for every row so columns line up properly.

Concept Explanation

The task is to display data in column-aligned tabular form so it looks clean and readable.

Step-by-Step Explanation

1.Decide fixed column widths for each field (e.g., Name = 12, Roll = 6, Marks = 8).

2.Print the table header using the same column widths.

3.Print a separator line for clarity.

4.For each student record:

• Print name using left alignment within the name column width.

• Print roll number using right alignment within the roll column width.

• Print marks using right alignment within the marks column width.

5.Ensure spacing is consistent for every row so columns line up properly.

Input / Output Format

Input Format
Student records containing:

• name (string)

• roll number (integer)

• marks (integer/float)
Output Format
Student data printed in a table format with:

• Names left-aligned

• Roll numbers and marks right-aligned

• Proper column spacing
Constraints
• Name length may vary

• Roll number and marks are numeric

• Number of students ≥ 1

Examples

Input:
Name | Roll | Marks Amit 101 85 Neha 12 92 Rohit 5 78
Output:
Name Roll Marks ------------------------- Amit 101 85 Neha 12 92 Rohit 5 78

Example Solution (Public)

C
#include <stdio.h>

int main() {
    char name[3][20] = {"Alice", "Bob", "Christopher"};
    int roll[3] = {101, 12, 7};
    float marks[3] = {89.5, 76.25, 92.0};

    int i;

    printf("n%-20s %10s %10sn", "Name", "Roll No", "Marks");
    printf("----------------------------------------------n");

    for (i = 0; i < 3; i++) {
        printf("%-20s %10d %10.2fn", name[i], roll[i], marks[i]);
    }

    return 0;
}

Official Solution Code

#include <stdio.h>

int main() {
    char name[3][20] = {"Alice", "Bob", "Christopher"};
    int roll[3] = {101, 12, 7};
    float marks[3] = {89.5, 76.25, 92.0};

    int i;

    printf("n%-20s %10s %10sn", "Name", "Roll No", "Marks");
    printf("----------------------------------------------n");

    for (i = 0; i < 3; i++) {
        printf("%-20s %10d %10.2fn", name[i], roll[i], marks[i]);
    }

    return 0;
}
Please login to submit solutions.
Editor
Output

                                        
Please login to submit solutions.