HOME

Thursday, April 2, 2015

C PROGRAM OF STRUCTURE ARRAY TO TAKE DATA AND DISPLAY IT

#include<stdio.h>
#include<conio.h>
struct student
{
    char name[20];
    int roll,age;
};
void stud(struct student s[],int n);
void main()
{
    struct student s[10];
 int i,n;
 printf("how many data you want to print\n");
 scanf("%d",&n);
 for(i=0;i<n;i++)
 {
    printf("enter the name %d\n",i+1);
    scanf("%s",s[i].name);
    printf("enter the roll no\n");
    scanf("%d",&s[i].roll);
    printf("enter the age\n");
    scanf("%d",&s[i].age);
 }
     stud(s,n);
}
stud(struct student s[],int n)
{
    int i;
    printf("the data you have entered are:\n");
    printf("name\troll no\tage\n");
    for(i=0;i<n;i++)
    {
        printf("%s\t%d\t%d\n",s[i].name,s[i].roll,s[i].age);
    }
}

No comments:

Post a Comment