Testing.

Sunday, 5 February 2017

C programming language: C program to find minimum/smallest element from the given array in c

#include<conio.h>
#include<stdio.h>
void main()
{
int arr[10];
int i,m;
printf("\nEnter Array Element:\n");
for(i=0;i<10;i++)
scanf("%d",&arr[i]);

printf("\nEntered Array Elements Are:\n");
for(i=0;i<10;i++)
printf(" %d",arr[i]);

m=arr[0];
for(i=0;i<10;i++)
{
if(arr[i]<m)
m=arr[i];
}
printf("\n %d Is The Min Element In Array:\n",m);
getch();
}

C programming language: C program to find maximum/largest element from the given array in c


#include<conio.h>
#include<stdio.h>
void main()
{
int arr[10];
int i,m;
printf("\nEnter Array Element:\n");
for(i=0;i<10;i++)
scanf("%d",&arr[i]);

printf("\nEntered Array Elements Are:\n");
for(i=0;i<10;i++)
printf(" %d",arr[i]);

m=arr[0];
for(i=0;i<10;i++)
{
if(arr[i]>m)
m=arr[i];
}
printf("\n %d Is The Max Element In Array:\n",m);
getch();
}

C programming language: First Array program in c.


#include<stdio.h>
#include<conio.h>
void main()
{
int arr[5]={10,20,30,40,50};
printf("\nArray Elements Are: ");
printf("\n %d",arr[0]);
printf("\t %d",arr[1]);
printf("\t %d",arr[2]);
printf("\t %d",arr[3]);
printf("\t %d",arr[4]);
getch();
}

----------------------------------------------------------------------------------------------------------------
First Array program.
----------------------------------------------------------------------------------------------------------------
#include<stdio.h>
#include<conio.h>
void main()
{
int arr[5];
arr[0]=10;
        arr[1]=20;
arr[2]=30;
arr[3]=40;
arr[4]=50;
printf("\nArray Elements Are: ");
printf("\n %d",arr[0]);
printf("\t %d",arr[1]);
printf("\t %d",arr[2]);
printf("\t %d",arr[3]);
printf("\t %d",arr[4]);
getch();
}

----------------------------------------------------------------------------------------------------------------
First Array program.
----------------------------------------------------------------------------------------------------------------#include<stdio.h>
#include<conio.h>
     void main()
     {
       int arr[5],i;
printf("\nEnter Array Elements: ");
for(i=0;i<5;i++)
scanf("%d",&arr[i]);

printf("\nArray Elements Are: ");
for(i=0;i<5;i++)
printf(" %d",arr[i]);
getch();
     }

C programming language: What is an Array in C ?


An array is a derived data type in 'C' which is constructed from fundamental data types of 'C' programming language.

An array is a collection of same types of data elements in a single entity.

In implementation when we require 'n' numbers of values of same data type, then recommended to create an array.

When we are working with arrays always static memory allocation will happen i.e. compile time memory management.

When we are working with arrays, always  memory   is constructed in continuous memory location that's why it is possible to access the data randomly.

When we are working with arrays all values will share same name with unique  identification value called 'index'.

And this array index must be started with 0 (Zero) and ends with (size-1).

It is required to use subscript operator '[]' while working with arrays.

Subscript operator '[]' require one argument of type  Unsigned integer constant, and its value must be ' > 0'  (greater than)only.

Syntax to create an array:-
                             DataType ArrayName[size];
         Example:-
               int arr[10];
               char arr[10];

In general arrays are classified into two types:
1) Single -dimensional arrays.
2) Multi dimensional arrays.

1) Single-dimensional arrays:-
                A single dimensional array and one-dimensional array consist of a fixed number of elements of the same data organized as a simple linear sequence. The elements of a single-dimensional array can be accessed by using a single subscript operator, thus they are also known as single sub-scripted variable.and it is also known as linear arrays and vectors.
     Single dimensional array is shown as below:-



 Declaration of a single-dimensional array:-
                The general form of a single-dimensional array declaration is 
                                 DataType ArrayName[size];
Example of single-dimensional array:-
                   int arr[5]; //array of 5 integers.
                   float arr[5];  //array of 5 floats.
                   char[10]; //array of 10 characters.

2) Two-dimensional arrays:-

 In 2D array, elements are arranged in rows and column format.

When we are working with 2D array , we required to use 2 subscript operators which indicates row size and column size.

The main memory of 2D array is row size and elements are available in column.

On 2D array when we are applying one subscript operator then it gives row name, row name always provides corresponding row address.

From 2D array when we required to access the element then 2 subscript operators required to use.

Array name always provides main memory address of an array, 

  Two-dimensional array is shown as below:-

Declaration of a two-dimensional array:-
                The general form of a two-dimensional array declaration is 
                                 DataType ArrayName[Rsize][Csize];
               where Rsize indicates row size and Csize indicates column size.
Example of two-dimensional array:-
                   int arr[2][3]; // integer array of  2 rows and 3 columns.
                   float arr[5][1];  // float array of  5 rows and 1 columns.
                   char[3][3]; // character array of  3 rows and 3 columns.