Community Sites
Create your own community website and start earning today !
It's Free !
 
Communities Members BookmarksPolls Fresher Jobs Funny Photos B.Tech Projects New Member FAQ  



My Profile
Active Members
TodayLast 7 Days more...



Awards & Gifts
Online Exams

Fresher Jobs


Our fresher job section is exclusively for fresh graduates! Find jobs for freshers in major Indian cities including Bangalore, Chennai, Hyderabad, Pune or Kochi

Resources


Find educational articles, blogs, discussion threads and other resources.

Colleges


Find details about any college in India or search for courses.

website counter



Array programs in C


Posted Date: 14 Jun 2008    Resource Type: Articles/Knowledge Sharing    Category: Computer & Technology

Posted By: Lenin       Member Level: Diamond
Rating:     Points: 1



Array programs

This section contains example programs demonstrating the use of arrays.

A simple program to demonstrate the definition and use of an array.
#include

main()
{
int i[10],j;

for ( j=0 ; j<10 ; j++)
i[j] = j ;

for ( j=0 ; j<10 ; j++)
printf("%d\n" , i[j]) ;
}

A program to demonstrate the use of an array.
#include
#include

main()
{
int i , min_value , max_value ;
int list[10] ;

for ( i=0 ; i<10 ; i++)
list[i] = rand() ;

/* Find the minimum value */

min_value = 32767 ;

for ( i=0 ; i<10 ; i++)
if (list[i]min_value=list[i] ;
printf("Minimum value generated is %d\n" , min_value) ;

/* Find the maximum value */

max_value = 0 ;

for ( i=0 ; i<10 ; i++)
if (list[i]>max_value)
max_value=list[i];
printf("Maximum value generated is %d\n" , max_value) ;

}

This program uses a bubble sort.
#include
include

main()
{
int item[100];
int a,b,t;
int count;
/* read in numbers */
printf("How many numbers ?");
scanf("%d", &count);
for (a=0;a
/* now sort using bubble sort */
for (a=1; afor (b=count-1; b>=a; --b) {
/* compare adjacent elements */
if (item[b-1] > item[b]) {
/* exchange elements */
t= item[b-1];
item[b-1] - item[b];
item[b] = t;
}
}
/* display sorted list */
for (t=0; t}

An example program using a two-dimensional array now follows.
#include

main()
{
int twod[4][5];
int i,j;

for(i=0; i<4; i++)
for(j=0; j<5; j++)
twod[i][j] = i*j;

for (i=0; i<4; i++) {
for (j=0; j<5; j++)
printf("%d !, twod[i][j]);
printf("\n");
}
}

The program output looks like this:
00000
01234
02468
036912





Responses

Author: Tejwant Singh Randhawa    15 Jun 2008Member Level: Silver   Points : 2
nice program to demonstrate function array in c. array is an continuous memory allocation of same data type. if declare a variable like int a[10] then array variable a is created with 10 elements with subscript from 0 to 9 .


Feedbacks      
Popular Tags   What are tags ?   Search Tags  
(No tags found.)

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Functions and Prototype programs
Previous Resource: C-Pointer programs
Return to Discussion Resource Index
Post New Resource
Category: Computer & Technology


Post resources and earn money!
 
Related Resources

Watch TV Channels



Contact Us    Editors    Privacy Policy    Terms Of Use   

SpiderWorks Technologies Pvt Ltd. 2006 - 2007 All Rights Reserved.