STRUCT.C

แนะนำ สอบถาม ภาษา C สำหรับผู้เริ่มต้น

Moderator:

User avatar
nokroo
Posts: 178
Joined: 01/01/1970 7:00 am
Location: วัดตะคร้ำเอน ต.ตะคร้ำเอน อ.ท่ามะกา จ.กาญจนบุรี

STRUCT.C

Postby nokroo » 05/10/2013 9:15 am

//PROGRAM TO IMPLEMENT A STUDENT RECORD USNIG STRUCTURES
//Downloaded from http://www.c4cprog.co.nr
#include <stdio.h>
#include <conio.h>

struct student
{
char name[10],sub1[100],sub2[100],sub3[100];
int marks[3],total,rank;
float avg;
struct address
{
int houseno;
long int pcode,phno;
char city[10];
}addr;
}stu[10],temp;

int main()
{
int n,i,j;
char b;

printf("\n\nEnter Student Limit :\n\n");
scanf("%d",&n);
for(i=0;i<n;i++)
{

printf("\n\t\t\t\tStudent %d\n\n",i+1);
printf("\nEnter Student Name :");
scanf(" %s",stu[i].name);
printf("\nEnter House No :");
scanf("%d",&stu[i].addr.houseno);
printf("\nEnter City :");
scanf("%s",stu[i].addr.city);
printf("\nEnter Pincode :");
scanf("%ld",&stu[i].addr.pcode);
printf("\nEnter Phone No :");
scanf("%ld",&stu[i].addr.phno);
for(j=0;j<3;j++)
{
printf("\nEnter Mark Of Subject %d :",j+1);
scanf("%d",&stu[i].marks[j]);
stu[i].total=stu[i].total+stu[i].marks[j];
}
stu[i].avg=stu[i].total/3;
}
for(i=0;i<n;i++)
for(j=0;j<n-1;j++)
if(stu[j].total<stu[j+1].total)
{
temp=stu[j];
stu[j]=stu[j+1];
stu[j+1]=temp;
}

printf("\nRank | Name | H.No | City | P.Code | Ph.No | Mark1 | Mark2 | Mark 3 | Tot | Avg");
for(i=0;i<n;i++)
{
printf("\n\n%d",i+1);
printf("\t%s",stu[i].name);
printf("\t%d",stu[i].addr.houseno);
printf("\t%s",stu[i].addr.city);
printf("\t%ld",stu[i].addr.pcode);
printf("\t%ld",stu[i].addr.phno);
for(j=0;j<3;j++)
printf("\t%d ",stu[i].marks[j]);
printf("\t%d",stu[i].total);
printf(" %.1f",stu[i].avg);
}
getch();
}








/*
OUTPUT


Enter Student Limit : 2
Student 1


Enter Student Name :Sandy

Enter House No :1

Enter City :Mount

Enter Pincode :6854

Enter Phone No :1498

Enter Mark Of Subject 1 :89

Enter Mark Of Subject 2 :86

Enter Mark Of Subject 3 :87


Student 2


Enter Student Name :Steve

Enter House No :2

Enter City :Mount

Enter Pincode :6854

Enter Phone No :1306

Enter Mark Of Subject 1 :87

Enter Mark Of Subject 2 :86

Enter Mark Of Subject 3 :80


Rank | Name | H.No | City | P.Code | Ph.No | Mark1 | Mark2 | Mark 3 | Tot | Avg

1 Sandy 1 Mount 6854 1498 89 86 87 262 87.0

2 Steve 2 Mount 6854 1306 87 86 80 253 84.0
*/

Return to “Programming - C/C<sup>++</sup>& java”

Who is online

Users browsing this forum: No registered users and 1 guest