Showing posts with label array in c. Show all posts
Showing posts with label array in c. Show all posts

Tuesday, February 12, 2013

Array in C

Before you kick start to reading array, you should understand why array concept is comes? How it is requires in C?

Let's read following program:

#include<stdio.h>
int main()
{
 int r;
 r=1;
 r=2;
 printf("The value of r = %d",r);
 getch();
 return 0;
}

The output of above program would be:
The value of r = 2

So, you can understand that when the value 2 is assigned into r, the earlier value of r (i.e. 1) is lost. Thus the ordinary variables are capable of holding only one value at a time.
What we do if we would want to store more than one value at a time in a single variable?
Here, the comes the concept of array.

What is array?
  1. Array is a collection of similar elements.
  2. The first element in the array is numbered 0, so the last element is 1 less than the size of the array.
  3. An array is also known as a subscripted variable.
  4. Before using an array, its type and dimension must be declared.
  5. The array elements are always stored in contiguous memory locations. This is a very important features of array.
Thus, an array is collection of similar elements. These similar elements could be all ints, or all floats, or all chars.

Array of characters is called a string whereas an array of ints or floats is called simply an array.

Keep in mind that all elements of any array must be the same type. i.e. cannot have an array of 10 numbers, of which 5 are ints and 5 are floats.

Saturday, December 10, 2011

C program to print the all elements of any array


.fieldsetOut{
background:#1E90FF;
padding:0px 0px 0px 0px;
font-family: "courier new"
}
.fieldsetIn{
background:white;
margin:1px 1px 1px 1px;
padding:1px 1px 1px 1px;
border: 0px 0px 0px 0px

}
.explanation{
color:#800000;
font-size:25px;
font-weight:900;
letter-spacing:15
}










#include

int main(){



int arr[]={1,2,34,56,89};



int i;



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

Saturday, October 22, 2011

programmable logical array

hi! guys I am a student of b.tech computer science...and have got a project work on progrmmable logical array(PLA)..which I do not find an easy task... so all I want to say is...."please arrange me a very easy C language code and I have to submit it before 26 oct 2011 so please do it fast..I am totally counting on you" try to make the programme easy and short and it must be on C...no other

Thursday, September 1, 2011

C program to find largest and smallest number in an array


.fieldsetOut{
background:#1E90FF;
padding:0px 0px 0px 0px;
font-family: "courier new"
}
.fieldsetIn{
background:white;
margin:1px 1px 1px 1px;
padding:1px 1px 1px 1px;
border: 0px 0px 0px 0px

}
.explanation{
color:#800000;
font-size:25px;
font-weight:900;
letter-spacing:15
}








C
code to find largest and smallest number in an array





#include

int main(){


Saturday, August 13, 2011

Using recursion in c find the largest element in an array


.fieldsetOut{
background:#1E90FF;
padding:0px 0px 0px 0px;
font-family: "courier new"
}
.fieldsetIn{
background:white;
margin:1px 1px 1px 1px;
padding:1px 1px 1px 1px;
border: 0px 0px 0px 0px

}
.explanation{
color:#800000;
font-size:25px;
font-weight:900;
letter-spacing:15
}









C
code to get largest element of an array by recursion:




#include

#define MAX 100

Monday, February 21, 2011

Array tutorials in c programming language by examples



Array
tutorials in c programming language by examples



An array is derived data type in c programming language which can store similar type of data in continuous memory location. Data may be primitive type (int, char, float, double�), address of union, structure, pointer, function or another array.



Example of array declaration:




int arr[5];



char arr[5];



float arr[5];



long

Friday, February 18, 2011

Two dimensional array questions in java



faq 2 dimensional array questions and answers in java

(1)



public class ArrayDemo {

public static void main(String[] args) {

double arr[3];

arr[0]=2.1;

arr[1]=3.1;

arr[2]=4.1;

System.out.println(arr[1]+arr[2]);

}

}



What will be the output of above java program?



(a)7.2

(b) Any number greater than 7.2

(

Saturday, August 7, 2010

How to declare an array in c











.fieldsetOut{
background:#1E90FF;
padding:0px 0px 0px 0px;
font-family: "courier new"
}
.fieldsetIn{
background:white;
margin:1px 1px 1px 1px;
padding:1px 1px 1px

How to initialize an array in c











.fieldsetOut{
background:#1E90FF;
padding:0px 0px 0px 0px;
font-family: "courier new"
}
.fieldsetIn{
background:white;
margin:1px 1px 1px 1px;
padding:1px 1px 1px

Saturday, June 19, 2010

Write a c program to find out second smallest element of an unsorted array


.fieldsetOut{
background:#1E90FF;
padding:0px 0px 0px 0px;
font-family: "courier new"
}
.fieldsetIn{
background:white;
margin:1px 1px 1px 1px;
padding:1px 1px 1px 1px;
border: 0px 0px 0px 0px

}
.explanation{
color:#800000;
font-size:25px;
font-weight:900;
letter-spacing:15
}










C program to find the second
smallest element in an array






#include

int main()

Write a c program for swapping of two arrays


.fieldsetOut{
background:#1E90FF;
padding:0px 0px 0px 0px;
font-family: "courier new"
}
.fieldsetIn{
background:white;
margin:1px 1px 1px 1px;
padding:1px 1px 1px 1px;
border: 0px 0px 0px 0px

}
.explanation{
color:#800000;
font-size:25px;
font-weight:900;
letter-spacing:15
}








Write a c
program for swapping of two arrays




#include

int main(){

int a[10],b

Friday, June 18, 2010

Write a c program which passes two dimension array to function


.fieldsetOut{
background:#1E90FF;
padding:0px 0px 0px 0px;
font-family: "courier new"
}
.fieldsetIn{
background:white;
margin:1px 1px 1px 1px;
padding:1px 1px 1px 1px;
border: 0px 0px 0px 0px

}
.explanation{
color:#800000;
font-size:25px;
font-weight:900;
letter-spacing:15
}












How to pass two dimensional array to a function in c




#include

#define M 3

#

Saturday, June 12, 2010

Array questions with explanation in c







.fieldsetOut{
background:#1E90FF;
padding:0px 0px 0px 0px;
font-family: "courier new"
}
.fieldsetIn{
background:white;
margin:1px 1px 1px 1px;
padding:1px 1px 1px 1px

Sunday, June 6, 2010

INSERT AN ELMENT IN AN ARRAY AT DESIRED POSITION USING C PROGRAM




How
to insert or add an element in the array at specific or desired posting by
using c programming language? Source code is as follow:



#include

int main(){

int
a[50],size,num,i,pos,temp;

printf("\nEnter
size of the array: ");

scanf("%d",&size);

printf("\nEnter
%d elements in to the array: ",size);

for(i=0;iscanf("%d",&a[i]);

printf("\nEnter position and number to insert: ");

Saturday, May 15, 2010