Arrays In C Programming Language


In this tutorial you will understand and see the array in C programming language .


Array is a derived  datatype in c programming language.

 It is the collection of homogeneous data or similar type of data. 

The concept of array says that we can store more than one element/value of similar type inside a single variable by defining a subscript or size.

All the array elements are accessed by the help of an unique index number which is by default starts from zero but we can start it from any other number.

Types of Array ;-

1.      Single Dimensional Array/One Dimensional Array(1d)



Whenever the array elements are stored inside a single variable by defining a single subscript or size then it is called as single dimensional array.



2.      Double Dimensional Array/Two Dimensional Array(2d)




Why do we need of Arrays?


We can use normal variables like  A 1 , B1 for storing  small number of objects but suppose if we have to store a large number of objects for any instances , it becomes difficult to manage them with normal variables and we manage them with the help of the arrays .


Declaration of Array 


int num[35];  /* An integer array of 35 elements */
char ch[10];  /* An array of characters for 10 elements */

Intialization of array


int mark[5] = {19, 10, 8, 17, 9};


Let's do some questions on Array in C programing Language 



Question-1 Write a program to read and display a 1-d array at Runtime?



#include <stdio.h>
int main()
{


int a[100],i,n; 
clrscr();
printf(“enter range\n”); 
scanf(“%d”,&n);
printf(“enter elements into the array\n”); 
for(i=0;i



Question-2 Write a program to display all the array elements in ascending order ?




#include <stdio.h>

int main()
{
int a[100],num,i,temp,j; 
clrscr();
printf(“enter the range of the array\n”); 
scanf(“%d”,&num);
printf(“enter the elements\n”); 
for(i=0;ia[j])
temp=a[i]; 
a[i]=a[j]; 
a[j]=temp;
}
printf(“elements in sorted order are\n”); 
for(i=0;i

Question-3 Write a program to find the largest and smallest element present inside an array?



#include <stdio.h>
int main()
{
int a[100],num,i,large,small; 
clrscr();
printf(“enter the range of the array\n”); 
scanf(“%d”,&num);
printf(“enter the elements\n”); 
for(i=0;ilarge) 
large=a[i];
}
small=a[0]; 
for(i=0;i


Question-4 Write a program to find the two digited element present inside the array?



#include <stdio.h>
int main()
 
{
int a[100],num,i,sum=0; 
clrscr();
printf(“enter the range of the array\n”); 
scanf(“%d”,&num);
printf(“enter the elements\n”); 
for(i=0;i9&&a[i]<100 0="" code="" printf="" return="" sum="%d”,sum);">


Question-5 Write a program to display all the array elements in reverse order ?



#include <stdio.h>
int main()
{
int a[100],i,num; 
clrscr();
printf(“enter range of array\n”); 
scanf(“%d”,&num);  
printf(“enter the elements\n”); 
for(i=0;i=0;i--)
{
printf(“%d\n”,a[i]);
}
return ;
}





Question-6 Write a program to insert an element into an Array ?



#include <stdio.h>
int main()
{
int a[100],n,i,p,k; 
clrscr();
printf(“enter the ranf of the array\n”); 
scanf(“%d”,&n);
printf(“enter elements into the array\n”); 
for(i=0;i=p;i--)
{
a[i+1]=a[i];
a[p-1]=k;
}
printf(array elements are\n”); 
for(i=0;i


Question-7 Write a program to delete an Element from an array?



#include <stdio.h>
int main()
{
int a[100],n,i,p; 
clrscr();
printf(“enter the ranf of the array\n”); 
scanf(“%d”,&n);
printf(“enter elements into the array\n”); 
for(i=0;i=n+1)
printf(“deletion not possible”);
 
else
for(i=p-1;i


If you find anything inappropriate or want to give more knowledge about above topic you can comments us .














Arrays In C Programming Language Arrays In C Programming Language Reviewed by Digital Roy on January 22, 2020 Rating: 5

No comments:

Powered by Blogger.