You are here:

C/Turbo c

Advertisement


Question
hi respectable
iam a student of computer system enginerring
iam facing problem how to use Arrays in programming.


Answer
Hi Owais

To use array, you have to first create an array like this
datatype name[size] i.e.
int arr[10] where int is what type of values the array can hold arr is the user defined name to refer to the array and [10] is the size i.e. the number of ints the array can hold
so with int arr[10] we can store 10 different or same iteger values in arr ... ranging from arr[0],arr[1]...,arr[9] total 10.

Now for example you can use loop to iterate the array like this
for(i=0;i<10;i++)//this loop generates no from 0 yo 9
{
scanf("%d",&arr[i]);
since i increases everytime so we are taking values from user and storing every element at different index of the array later you can also use similar loops to calculate anything within the array
}

For example now i am adding up all the elements stored in the array
for(i=0;i<10;i++)
sum = sum + arr[i];

going through all the index and making su of all the values stored in arr.

I hope this clears your dubt a little for more please get back to me or read the chapter array which will now look much more easier and comfortable to you.

regards
Joydeep Bhattacharya
http://www.scodz.com

C

All Answers


Answers by Expert:


Ask Experts

Volunteer


Joydeep Bhattacharya

Expertise

Ability to solve C and Data Structure problems and puzzles with simple and easy to understand logic.

Experience

C, C++, Java, Data Structure, PHP, Web Designing

Organizations
http://www.scodz.com Designation: webmaster

Publications
http://www.scodz.com

Education/Credentials
Master of Computer Applications

Past/Present Clients
http://analysingc.50webs.com http://www.funforu.com

©2012 About.com, a part of The New York Times Company. All rights reserved.