Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR C

Array in C

#include<stdio.h>
#include<string.h>
#define MAX 2

struct student
{
    char name[20];
    int roll_no;
    float marks;
};

int main()
{
    struct student arr_student[MAX];
    int i;

    for(i = 0; i < MAX; i++ )
    {
        printf("
Enter details of student %d

", i+1);

        printf("Enter name: ");
        scanf("%s", arr_student[i].name);

        printf("Enter roll no: ");
        scanf("%d", &arr_student[i].roll_no);

        printf("Enter marks: ");
        scanf("%f", &arr_student[i].marks);
    }

    printf("
");

    printf("Name	Roll no	Marks
");

    for(i = 0; i < MAX; i++ )
    {
        printf("%s	%d	%.2f
",
        arr_student[i].name, arr_student[i].roll_no, arr_student[i].marks);
    }

    // signal to operating system program ran fine
    return 0;
}
Source by overiq.com #
 
PREVIOUS NEXT
Tagged: #Array #C
ADD COMMENT
Topic
Name
5+3 =