Solved programming problem

Scan and Print Structure in C.

Source code

#include <stdio.h>

struct student   /// structure declaring

{

    char name[100];

    int id;

};

int main()

{

    struct student info[100];   ///structure containing array

    int i,n;

    printf("Please Enter how many student information you want to Entry: ");

    scanf("%d",&n);

    for(i=0;i<n;i++)

    {

        printf("Name: ");

        getchar();

        gets(info[i].name);  ///scaning structure  element

        printf("ID: ");

        scanf("%d",&info[i].id);

    }

   printf("
Your saving Data:
");

     for(i=0;i<n;i++)

    {

        printf("Name: %s
",info[i].name);  ///printing structure  element

        printf("ID: %d
",info[i].id);

    }

    return 0;

}

Output

Please Enter how many student information you want to Entry: 2
Name: ali
ID: 1
Name: Fahim
ID: 2
Your saving Data:
Name: ali
ID: 1
Name: Fahim
ID: 2

 

Join the discussion

Add your comment