Thread: How do I modify thing program??

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Oct 2010
    Posts
    5

    How do I modify this program??

    I've managed to write this following program which accepts values for 5 students and works on it. But, for the life of me, I can't figure out how to modify this for 'n' number of students! I've tried almost everything I know but I can't get it to work without errors! Does anyone have any ideas?? Thanks!

    Code:
    #include <stdio.h> 
    #include <conio.h>
    #include <stdlib.h> 
    
    #define NUM_STUDENTS 5 
    
    #define IND_REGNO 0 
    #define IND_FAIL 1 
    #define IND_RANK 2 
    #define IND_TOTAL 3 
    #define IND_MARKS 4 
    
    int st[NUM_STUDENTS][9]; 
    int sortarr[NUM_STUDENTS]; 
    
    int sortfunc(const void* p1, const void* p2) { 
        int id1=*(int*)p1, id2=*(int*)p2; 
    
        return st[id2][IND_TOTAL]-st[id1][IND_TOTAL]; 
    } 
    
    int main() { 
        printf("\n Enter the register number and marks in each subject");
        int i, j, passers=0, passrate=0, topper=0; 
    
        for(i=0; i<NUM_STUDENTS; i++) { 
            scanf("%i %i %i %i %i %i", &st[i][IND_REGNO], &st[i][IND_MARKS+0], &st[i][IND_MARKS+1], 
                  &st[i][IND_MARKS+2], &st[i][IND_MARKS+3], &st[i][IND_MARKS+4]); 
    
            for(j=0; j<5; j++) { 
                st[i][IND_TOTAL]+=st[i][IND_MARKS+j]; 
                if(st[i][IND_MARKS+j] < 50) { 
                    st[i][IND_FAIL]=1; 
                } 
            } 
    
            if(st[i][IND_FAIL] == 0) { 
                passers++; 
            } 
        } 
    
        for(i=0; i<NUM_STUDENTS; i++) { 
            sortarr[i]=i; 
        } 
    
        qsort(sortarr, NUM_STUDENTS, sizeof(int), sortfunc); 
    
        for(i=0; i<NUM_STUDENTS; i++) { 
            st[sortarr[i]][IND_RANK]=i+1; 
        } 
        passrate=(passers*100) / NUM_STUDENTS; 
        topper=st[sortarr[0]][IND_REGNO]; 
    printf("\nNo \tM1 \tM2 \tM3 \tM4 \tM5 \tTOTAL \tP/F \tRANK \n \n \n");
        for(i=0; i<NUM_STUDENTS; i++) { 
            printf("\n%i \t%i \t%i \t%i \t%i \t%i \t%i \t%s \t%i\n", st[i][IND_REGNO], st[i][IND_MARKS+0], st[i][IND_MARKS+1], 
                  st[i][IND_MARKS+2], st[i][IND_MARKS+3], st[i][IND_MARKS+4], st[i][IND_TOTAL], 
                  (st[i][IND_FAIL]==0) ? "PASS" : "FAIL", st[i][IND_RANK]); 
        } 
    
        printf("\nPass Percentage - %i%%\nTopper - %i\n", passrate, topper); 
        getch();
        return 0; 
    }
    Last edited by gouthamgmv; 10-30-2010 at 01:08 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Free program I'm sharing: ConvertEnumToStrings
    By Programmer_P in forum Projects and Job Recruitment
    Replies: 101
    Last Post: 07-18-2010, 12:55 AM
  2. c program help :>
    By n2134 in forum C Programming
    Replies: 9
    Last Post: 02-06-2010, 12:12 PM
  3. Program Crashes when i modify one of the parameters
    By pinkcheese in forum C++ Programming
    Replies: 2
    Last Post: 01-28-2003, 08:46 AM
  4. fopen();
    By GanglyLamb in forum C Programming
    Replies: 8
    Last Post: 11-03-2002, 12:39 PM