C programmers help me-Simple program...

senewimala1988

Well-known member
  • Dec 5, 2007
    7,706
    2,577
    113
    Kadawatha, Sri Lanka
    Meka thama question eka mata mekata coding tika kiyanavada..Simple program 1k..arrays & loops use karanna oni...

    Suppose there are 4 students each having marks of 3 subjects. Write a program to read the marks from the keyboard and calculate and display the total marks of each students. Use a 2-D array to store marks. An example would be as follows.

    Enter the marks of four students, on four rows:
    50 60 80
    60 75 90
    30 49 99
    66 58 67

    Total marks of four students:
    190
    225
    178
    191


    Meka thama mage program eka...Eth segmentation fault kiyala enava...I am new for C programming...Help me...

    #include<stdio.h>
    int main()
    {
    int i,j;
    int tot;
    int a[4][3];
    printf("Enter marks of four students, on four rows: \n");
    for(i=0;i<4;i++);
    {
    tot=0;
    for(j=0;i<3;j++)
    {
    scanf("%d",&a[j]);
    tot+=a[j];
    }
    }
    printf("Total marks of four students: \n");
    for(i=0;i<4;i++)
    {
    printf("%d\n",tot);
    }
    return 0;
    }
     

    crazycombo

    Member
    Jul 4, 2008
    3,101
    13
    0
    A Land Like No Other!
    Code:
    #include <stdio.h>
    #include <conio.h>
    
    
    void main()
    {
        int marks[4][3];
        int x=0;
        int y=0;
        int total=0;
    
        
        for (int x=0;x<4;x++){
            for (int y=0;y<3;y++){
                printf("Enter %d Student's Marks for subject %d: ",x+1,y+1);
                scanf("%d",&marks[x][y]);
            }
        }
    
        printf("Student Number\t\tTotal Marks\n");
        for (x=0;x<4;x++){
            total=0;
            for (y=0;y<3;y++){
                total+=marks[x][y];                        
            }
            printf("%d\t\t\t%d\n",x+1,total);
        }
        getch();
    }
    hope this helps.

    but maybe the input method may vary!
     

    senewimala1988

    Well-known member
  • Dec 5, 2007
    7,706
    2,577
    113
    Kadawatha, Sri Lanka
    crazycombo said:
    Code:
    #include <stdio.h>
    #include <conio.h>
    
    
    void main()
    {
        int marks[4][3];
        int x=0;
        int y=0;
        int total=0;
    
        
        for (int x=0;x<4;x++){
            for (int y=0;y<3;y++){
                printf("Enter %d Student's Marks for subject %d: ",x+1,y+1);
                scanf("%d",&marks[x][y]);
            }
        }
    
        printf("Student Number\t\tTotal Marks\n");
        for (x=0;x<4;x++){
            total=0;
            for (y=0;y<3;y++){
                total+=marks[x][y];                        
            }
            printf("%d\t\t\t%d\n",x+1,total);
        }
        getch();
    }
    hope this helps.

    but maybe the input method may vary!
    umbata sure neda mekaC++ nemei kiyala???
    conio.h eka mokatada ban???
    void main kiyala damme ai???
     

    nagaya

    Member
    Mar 18, 2007
    12,671
    194
    0
    void main kiyanne main eken value ekak return karanne ne NULL kiyanna

    conio.h one getch(); nathnm stdio eken getchar(); use karanna
     
    Last edited:

    nagaya

    Member
    Mar 18, 2007
    12,671
    194
    0
    try this edited one from crazycombo

    #include <stdio.h>


    int main()
    {
    int marks[4][3];
    int total=0;
    int x,y;


    for ( x=0;x<4;x++){
    for ( y=0;y<3;y++){
    printf("Enter %d Student's Marks for subject %d: ",x+1,y+1);
    scanf("%d",&marks[x][y]);
    }
    }

    printf("Student Number\t\tTotal Marks\n");
    for (x=0;x<4;x++){
    total=0;
    for (y=0;y<3;y++){
    total+=marks[x][y];
    }
    printf("%d\t\t\t%d\n",x+1,total);
    }
    getchar();
    return(0);
    }
     
    Last edited:

    nagaya

    Member
    Mar 18, 2007
    12,671
    194
    0
    senewimala1988 said:
    ara uda program eke wage input ekak dunnama e godakin max & min vena venama pennanne kohomada kiyala...


    menna min ekata.max ekata meka balala liya ganna :D

    #include <stdio.h>


    int main()
    {
    int marks[4][3];
    int max[4],min[4];
    int x,y;


    for ( x=0;x<4;x++){
    for ( y=0;y<3;y++){
    printf("Enter %d Student's Marks for subject %d: ",x+1,y+1);
    scanf("%d",&marks[x][y]);
    }
    }


    for (x=0;x<4;x++){

    for (y=0;y<3;y++){
    if (marks[x][y] < min[x])
    {
    min[x] = marks[x][y];
    }
    }

    printf("%d\n",min[x]);
    }
    getchar();
    }
     
    Last edited:

    senewimala1988

    Well-known member
  • Dec 5, 2007
    7,706
    2,577
    113
    Kadawatha, Sri Lanka
    nagaya said:
    menna min ekata.max ekata meka balala liya ganna :D

    #include <stdio.h>


    int main()
    {
    int marks[4][3];
    int max[4],min[4];
    int x,y;


    for ( x=0;x<4;x++){
    for ( y=0;y<3;y++){
    printf("Enter %d Student's Marks for subject %d: ",x+1,y+1);
    scanf("%d",&marks[x][y]);
    }
    }


    for (x=0;x<4;x++){

    for (y=0;y<3;y++){
    if (marks[x][y] < min[x])
    {
    min[x] = marks[x][y];
    }
    }

    printf("%d\n",min[x]);
    }
    getchar();
    }
    Thanx macho...
    I will try...