Monday 5 November 2018

LESSON 6 Details of two students and their three marks m1,m2,m3 C Programming

Details of two students and their three marks m1,m2,m3

#include<stdio.h>
#include<conio.h>
void main()
{
struct stud{
    char name[20];
    int m1;
    int m2;
    int m3;
    int m4;
    int total;
    char grade[20];
    }a[100],temp;
 int n,i,j ;
 clrscr();
 printf("enter no. of students");
 scanf("%d",&n);
 for(i=0;i<n;i++)
 {
printf("enter details \nname,m1,m2,m3,m4");
    scanf("%s",a[i].name);
    scanf("%d%d%d%d",&a[i].m1,&a[i].m2,&a[i].m3,&a[i].m4);
    a[i].total=a[i].m1+a[i].m2+a[i].m3+a[i].m4;
    }
 for(i=0;i<n;i++)
 {
 for(j=0;j<n-i;j++)
 {
 if(a[j].total<a[j+1].total)
  {
  temp=a[j];
  a[j]=a[j+1];
  a[j+1]=temp;
  }
  }
  }printf("\nname\tm1\tm2\tm3\tm4\ttotal");
 for(i=0;i<n;i++)
 printf(" \n%s\t%d\t%d\t%d\t%d\t%d",a[i].name,a[i].m1,a[i].m2,a[i].m3,a[i].m4,a[i].total);
 getch();
 }

0 Comments:

Post a Comment

Facebook Twitter Delicious Digg Stumbleupon Favorites More

 
Design by Free WordPress Themes | Bloggerized by Lasantha - Premium Blogger Themes | coupon codes