Data Structure
Contents:
Array
In C programming, one of the frequently arising problem is to handle similar types of data. For example: If the user want to store marks of 100 students. This can be done by creating 100 variable individually but, this process is rather tedious and impracticable. These type of problem can be handled in C programming using arrays.
Computer programs store data in varied ways. These storage options allow programmers to create and access data structures within their applications. One of the most simple data storage items in programming is a variable. Variables store individual items of data. An array is another type of data structure, storing a series of values at consecutive positions. Once a program has an array structure in it, it can enter and access the values at specific array positions.
Computer programs store data in varied ways. These storage options allow programmers to create and access data structures within their applications. One of the most simple data storage items in programming is a variable. Variables store individual items of data. An array is another type of data structure, storing a series of values at consecutive positions. Once a program has an array structure in it, it can enter and access the values at specific array positions.
-
When a program creates an array, it will typically indicate
certain aspects of the array, which is in turn represented as a variable
within the application. The following sample Java code demonstrates
creating an array to store a certain number of integer values:
int [] myNums = new int [6];
This array can hold six values of integer type. When this line of code has executed, the program has an empty array structure, but no values are stored at any of the element positions yet.
Array of C Programming
/* C program to find the sum marks of n pupils using arrays */
#include <stdio.h> int main() { int marks[10],i,n,sum=0; printf("Enter number of pupils: "); scanf("%d",&n); for(i=0;i<n;++i) { printf("\nEnter marks of pupils%d: ",i+1); scanf("%d",&marks[i]); sum+=marks[i]; } printf("Sum= %d",sum); return 0; } |
Here's the Output
Enter number of students: 3 Enter marks of pupils1: 12 Enter marks of student2: 31 Enter marks of student3: 2 sum=45 |