20_10

Write a C program which find the student name who obtain the highest marks.

Source code:

//Consider the following program statement:

/*One needs to first input a set of N number of ALPHABETIC Strings each representing a name of a student in an array studname [N] . Assume each string can be Max. 40 Character Long. Subsequently , one needs to input Marks obtained by those students in another array marks [N] . Assume that studname [I] i.e. ith student in the list of student names has obtained Marks [I] in the Marks List.  You need to find out and print the Max Marks obtained by a student and also print the name of the student who has obtained this marks. Considering here both the arrays of size 5. */


#include <stdio.h>

#include <string.h>

typedef char st[10];

int main ()

{

    st studname[10];

    int marks[10];

    int i; int n=5; int imaxpos=1;

for (i = 1 ; i<=n ; i++)

    {

    printf("Enter name of %d : ",i);

        scanf("%s", studname[i]);

    }

        

    for (i = 1 ; i<=n ; i++)

    {

    printf("Enter marks of %d : ",i);

    scanf("%d", &marks[i]);

    }


    for (i =2; i <= n; i++)

    {

        if (marks [i]  > marks [imaxpos] )

        {

            imaxpos = i;

        }

    }

printf ("The largest marks=%d\nObtained by student : %d Name: %s\n", marks[imaxpos] , imaxpos, studname[imaxpos]);

    return(0);

}

Output:

C program which find the student name who obtain the highest marks


No comments:

Post a Comment

Write a program in C to convert a decimal number to binary using recursion.

 Source code: //Write a program in C to convert a decimal number to binary using recursion. #include<stdio.h> long convertB_to_D(int d...