Professional Documents
Culture Documents
8.1.writea Program To Read Structure Elements From Keyboard. Program
8.1.writea Program To Read Structure Elements From Keyboard. Program
8.1.writea Program To Read Structure Elements From Keyboard. Program
PROGRAM:
#include<stdio.h>
struct student
{char name[50];
int roll;
int marks;
}s;
void main()
{printf("enter name:");
scanf("%s",&s.name);
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++)
scanf("%s",p1[i].name);
scanf("%s",p1[i].doj);
scanf("%f",&p1[i].salary);
For(i=1;i<=5;i++)
PROGRAM:
#include<stdio.h>
#include<conio.h>
struct time_struct
int hour;
int minute;
int second;
};
void main()
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:
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();
}
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
s[i].roll = i +1;
scanf("%s", s[i].firstName);
scanf("%f",&s[i].marks);
printf("Displaying Information:\n\n");
// displaying information
puts(s[i].firstName);
printf("\n");
return0;