8.1.writea Program To Read Structure Elements From Keyboard. Program

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 7

PRACTICAL SET-8

8.1.Writea program to read structure elements from keyboard.

PROGRAM:

#include<stdio.h>

struct student

{char name[50];

int roll;

int marks;

}s;

void main()

{printf("enter name:");

scanf("%s",&s.name);

printf("enter roll number:");

scanf("%d",&s.roll);

printf("enter marks:");

scanf("%f",&s.marks);

printf("Displaying information:\n");

printf("Name:");

printf("%s",s.name);

printf("Roll number:%d\n",s.roll);

printf("Marks:%.1f\n",s.marks);

return 0;

}
8.2.Write a structure type struct personal that would contain person name,date of
joining & salary using this structure to read this information of 5 people & print the
same on screen.

PROGRAM:

#include <stdio.h>

struct personal

char person_name[20];

char join_date[20];

float salary;
};

void main()

int i;

struct personal p;

clrscr();

for(i=1;i<=5;i++)

   printf("#nenter name :- ");

   scanf("%s",p1[i].name);

   printf("#nenter date of join:- ");

   scanf("%s",p1[i].doj);

   printf("#nnter salary:- ");

   scanf("%f",&p1[i].salary);

For(i=1;i<=5;i++)

   printf("\ndispaying datails for %d employe",i);

   printf("\nname of join is %s",p1[i].name);

   printf("\n date of join is %s",p1[i].do);

printf("\n salary is %d",p1[i].salary);}


8.3.Define structure data type called time_struct containing three member’s integer
hour,integer minute & integer second.Devlop a program that would assign values to the
individual number & display the time in the following format. 16:40:51

PROGRAM:

#include<stdio.h>

#include<conio.h>

struct time_struct

int hour;

int minute;

int second;

};

void main()

struct time_struct time;

clrscr();

time.hour=16;

time.minute=40;

time.second=51;
printf("%d:%d:%d",time.hour,time.minute,time.second);

getch();

8.4.Define a structure called cricket that will describe the following information:

Player name,Team name,Batting average

Using cricket,declare an array player with 50 elements & write a c program to read the
information about all the 50 players & print team wise list containing names of players
with their batting average.

PROGRAM:

#include<stdio.h>
#include<conio.h>
#include<string.h>
struct cricket
{
    char     P_Name[20];
    char     T_Name[20];
    float B_Ave;
};
void main()
{
    struct cricket s[6],t;
    int    i,j,n=6;
    float    p;
    clrscr();
    printf("Enter Data Of %d Player\n",n);
    for(i=0;i<n;i++)
    {
        printf("\nEnter Player Name,Team Name And Bating Average For Player %d :- \n",i+1);
        scanf("%s %s %f",s[i].P_Name,s[i].T_Name,&p);
        s[i].B_Ave=p;
    }
    for(i=1;i<=n-1;i++)
    {
        for(j=0;j<=n-i;j++)
        {
            if(strcmp(s[j-1].T_Name,s[j].T_Name)>0)
            {
                t=s[j-1];
                s[j-1]=s[j];
                s[j]=t;
            }
        }
    }
    printf("\nAfter Teamwise Sorting...Player List Is");
    for(i=0;i<n;i++)
    {
            printf("\n%-20s %-20s %.2f",s[i].P_Name,s[i].T_Name,s[i].B_Ave);
    }
    getch();
}

8.5.Design a structure record to contain name,branch & total marks obtained.

Devloped a program to read data for 10 students in a class & print them.

PROGRAM:

#include<stdio.h>

struct student {

char firstName[50];

int roll;

float marks;

} s[10];

int main(){

int i;
printf("Enter information of students:\n");

// storing information

for(i =0; i <5;++i){

s[i].roll = i +1;

printf("\nFor roll number%d,\n", s[i].roll);

printf("Enter first name: ");

scanf("%s", s[i].firstName);

printf("Enter marks: ");

scanf("%f",&s[i].marks);

printf("Displaying Information:\n\n");

// displaying information

for(i =0; i <5;++i){

printf("\nRoll number: %d\n", i +1);

printf("First name: ");

puts(s[i].firstName);

printf("Marks: %.1f", s[i].marks);

printf("\n");

return0;

You might also like