Home / Programs / The examination committee of the university has decided to give 5 grace marks to every student of a class. Assume that there are list of students in the class and their marks are stored in a list called marksList. Write a program that adds the grace marks to every entry in the marksList.
Programming Example

The examination committee of the university has decided to give 5 grace marks to every student of a class. Assume that there are list of students in the class and their marks are stored in a list called marksList. Write a program that adds the grace marks to every entry in the marksList.

👁 808 Views
💻 Practical Program
📘 Step by Step Learning

As the problem deals with a list of marks, we can select a one-dimensional array called ‘marksList’ to represent the list. The grace marks are to be added to all the elements of the list, for which we must use the For-loop. The required program is given below:

Program Code

/* This program adds grace marks to all elements of a list of marks */
#include <stdio.h>
void main()
{
    int marksList[5];
    int i;
    int grace = 5;
    /*grace marks */
    /* Read the marksList */
    printf ("\n Enter the list of marks one by one \n");
    for (i = 0; i < 5; i++)
    {
        scanf ("%d", &marksList[i]);
        marksList[i] = marksList[i] + grace;
    }
        /* Print the Final list */
        printf ("\n The final List is ...");
        printf ("\n S. No.\t Marks");
        for (i = 0; i < 5; i++)
        printf ("\n %d\t%d", i, marksList[i]);
}

Output

 Enter the list of marks one by one                                                                                              
50                                                                                                                               
51                                                                                                                               
52                                                                                                                               
53                                                                                                                               
54                                                                                                                               
                                                                                                                                 
 The final List is ...                                                             

Explanation

It may be noted that in the above program, a component by component processing has been done on the all elements of the array called marksList.

How to learn from this program

First read the algorithm, then study the program code line by line. After that, compare the code with the output and finally go through the explanation. This approach helps learners understand both the logic and the implementation properly.