Tuesday, December 30, 2014

C using strcture program



Program 1

#include
#include
struct student
{
char name[21];
int rollno,m1,m2,tot;
float avg;
};
void main()
{
struct student s[10];
int i,n;
clrscr();
          printf("Enter how many students?\n");
          scanf("%d",&n);
          for(i=0;i
          {
          printf("\n Enter name, rollno,m1,m2");
          scanf("%s%d%d%d",s[i].name,&s[i].rollno,&s[i].m1,&s[i].m2);
          s[i].tot=s[i].m1+m2;
          s[i].avg=s[i].tot/2.00;
          }
          printf("\n \t\t Student Mark List\n");
          printf("\n Name \t Rollno \t Mark1 \t Mark 2 /t Total \t Average \n");
          printf("\n **********************************************");
          for(i=0;i
          {
printf("\n %s\t%d\t%d\t%d\t%d%f",s[i].name,s[i].rollno,s[i].m1,s[i].m2,s[i].tot,s[i].avg);
}
printf("\n *********************************************");
getch();
}

Output

Enter how many students?
2
Enter name,rollno,m1,m2
Raja
21
60
80
Enter name, rollno,m1,m2
Ragul
22
70
90
Student Mark List
*************************************************************
Name          Rollno         Mark1         Mark2         Total           Average
*************************************************************
Raja            21               60               80               140             70
Ragul          22               70               90               160             80
*************************************************************
Program2

#include
#include
void printline();
struct payment
{
char name[20];
int rollno,nofint,instamt,totamt;
};
void printline()
{
int i,n;
for(i=0;i<80 i="" span="">
printf("=");
}
void main()
{
struct payment pay[10];
int i,n,gtoal=0,totamt;
clrscr();
          printf("\n How many students pending in payment ?\n");
          scanf("%d",&n);
          printf("Enter payment details of %d student(s).\n",n);
          for(i=0;i
          {
          printf("Enter student name, Rollno, No.of instalmant, Ins.amt\n");
           scanf("%s%d%d%d%d",pay[i].name,&pay[i].rollno,&pay[i].nofint,&pay[i].instamt);
          pay[i].totamt=pay[i].nofint*pay[i].instamt;
          gtotal=gtotal+pay[i].totamt;
          }
          printline();
          printf("S:no\tName\tRollno\tNo.of.instalmant\tIsn.amt\tTotal\n");
          printline();
          for(i=0;i
          {
          printf("\n %d \t %s \t %d \t %d \t %d\t%d\n",(i+1),pay[i].name,pay[i].rollno,pay[i].nofint,pay[i].instamt,pay[i].totmat);
          }
printline();
printf("\n Grand total of payments \t\t\t %d",gtotal);
printline();
getch();
}

Output
          
          How many peoples
          2
          Enter payment details of 2 student(s)
          Enter student name, Rollno, No.of instalmant, Ins.amt
          Ragul
          34
          3
          1000
          Enter student name, Rollno, No.of instalmant, Ins.amt
          Raja
          35
          4
          500
          ==================================================
          S.no  Student name       Rollno         No.of instalmant  Ins.amt       Total
          ==================================================
          1        Ragul                    34               3                           1000           3000
          2        Raja                      35               4                           500             2000
          ==================================================    
          Grand total of payments                                                                    5000
          ==================================================




No comments:

Post a Comment