Example of Array program in C

Array is a Type of Variable that can store Multiple Data at Time. Let we learn it today via Example of An array program Example of Array program in C

Program For Array in C

#include <stdio.h>

#include <stdlib.h>
void RotateLeftByOne(int arr[], int size)
{
int first = arr[0], index;
for(index = 0; index < size - 1 ; index++)
arr[index] = arr[index+1];
arr[index] = first;
}
void RotateLeft(int arr[], int d, int size)
{
for(int index = 0; index < d; index++)
RotateLeftByOne(arr, size);
}
void printArray(int arr[], int size)
{
for(int index = 0; index < size; index++)
printf("%d\t", arr[index]);
}
int main()
{
int *arr, size, d;
printf("Enter size of the array\n");
scanf("%d", &size);
printf("Enter elements in array\n");
for(int index = 0; index < size; index++)
scanf("%d", &arr[index]);
printf("Enter value of d\n");
scanf("%d", &d);
RotateLeft(arr, d, size);
printArray(arr, size);
return 0;
}

Two Dimensional Array in C

(ClickHere)

Output

Enter the size of the array 3

Enter elements in array

1

2

3

Enter the value of d 2

3 1 2

Array Program in C

stdlib.h void abort(void); Stop a program abnormally.
stdlib.h    int abs(int n);    Calculates absolute value of an integer argument n.
Else u can create a static array

int arr[10] ;

if the array size is not known and user-defined length is mentioned? then u can create a dynamic array or use some other data structure.

u can also do it like this, set the initial size say 100 items of the array then ask the user how many items u want between 1-100.

Array in C

Example of Array program in C

Otherwise, u can do a dynamic array (ReadHere).

END

Leave a Reply

x