-->

Program to input name,address and roll number of some students using struct/ array of struct.

using codeblocks
---------------------------------------------------------------------------------------
// program to enter detail of some  students       //comment abt. program
#include <stdio.h>                                 //header file
struct data                                        //struct tag named data
{
    char name[80];                                //member1 of struct
    char address[80];                             //member2 of struct
    int roll;                                     //member3 of struct

}access[100]; //'access' is a variable to access members. This can hold maximum 100 members.it is called array of struct.
int main()
{
   int n,i;                                         //variable declaration
   printf("enter total value of n\n");
   scanf("%d",&n);                                  //accepts total value
   for(i=0;i<n;i++)
   {                                                 //execution of loop with inputs
    puts("enter roll number \n");
   scanf("%d",&access[i].roll);                      //gets data in different member
   puts("enter name \n");
   scanf("%s",access[i].name);
   puts("enter address \n");
   scanf("%s",access[i].address);

   }
   printf("entered data are\n");                  //loop execution to display data
   for(i=0;i<n;i++)
   {
    printf("roll is\n");
   printf("%d",access[i].roll);
   printf("name is\n");
   puts(access[i].name);                            //prints data from related member
   printf("address is\n");
   puts(access[i].address);                         //prints output from related member

    }
    return 0;
}
-----------------------------------------------------------------------------------------------------
using turbo c++
-------------------------------------------------------------------------------------------------
// program to enter detail of some  students       //comment abt. program
#include <stdio.h>                                 //header file
#include<conio.h>
struct data                                        //struct tag named data
{
    char name[80];                                //member1 of struct
    char address[80];                             //member2 of struct
    int roll;                                     //member3 of struct

}access[100]; //'access' is a variable to access members. This can hold maximum 100 members.it is called array of struct.
int main()
{
   int n,i;                                         //variable declaration
   printf("enter total value of n\n");
   scanf("%d",&n);                                  //accepts total value
   for(i=0;i<n;i++)
   {                                                 //execution of loop with inputs
    puts("enter roll number \n");
   scanf("%d",&access[i].roll);                      //gets data in different member
   puts("enter name \n");
   scanf("%s",access[i].name);
   puts("enter address \n");
   scanf("%s",access[i].address);

   }
   printf("entered data are\n");                  //loop execution to display data
   for(i=0;i<n;i++)
   {
    printf("roll is\n");
   printf("%d",access[i].roll);
   printf("name is\n");
   puts(access[i].name);                            //prints data from related member
   printf("address is\n");
   puts(access[i].address);                         //prints output from related member

    }
getch();
    return 0;
}

No comments:

Post a Comment