C Array Solved Programs
C programming Tutorials

Top 3 C Array Solved Programs

C Array Solved Programs

C Array Solved Programs are discussed and explained in this tutorial. These programs are generally asked in technical interview and in university exam of C Programming.

These Programs are based on One Dimensional Array in C.

I hope that These c array solved programs will be beneficial for the students.

Program 1 : WAP in C to find the sum of array elements

#include <stdio.h>

int main()

{

int i,arr[5];
int sum = 0;
printf(“enter array elements”);
for(i=0;i<5;i++)
{
scanf(“%d”,&arr[i]);
}
for ( i = 0; i < 5; i++)
{
sum = sum + arr[i];
}
printf(“Sum of all the elements of an array: %d”, sum);
return 0;
}

Output

sum of array elements program

Program 2: WAP in C to check that given number is present in array or not.

                                                               OR

                    Write a Program in C to implement Linear Search 

#include<stdio.h>
int main()
{
int arr[5] ;
int n,i,flag = 0;
printf(“Enter number to search\n”);
scanf(“%d”,&n);
printf(“enter array elements”);
for(i=0;i<5;i++)
{
scanf(“%d”,&arr[i]);
}
/*
* iterate the array elements using loop
* if any element matches the key, set flag as 1 and break the loop
* flag = 1 indicates that the key present in the array
* if execution comes out of loop and the flag remains 0, print search not found*/
for(i = 0; i <5; i++)
{
if(arr[i] == n)
{
flag = 1;
break;
}
}
if(flag == 1)
printf(“Given element is Found\n”);
else
printf(“Given element is Not Found\n”);
return 0;
}

Output

linear search program in c

Program 3: WAP in c to find minimum and maximum element in array

#include<stdio.h>
int main()
{
int a[100],i,n,min,max;
printf(“Enter size of the array : “);
scanf(“%d”,&n);
printf(“Enter elements in array : “);
for(i=0; i<n; i++)
{
scanf(“%d”,&a[i]);
}
min=max=a[0];
for(i=1; i<n; i++)
{
if(min>a[i])
min=a[i];
if(max<a[i])
max=a[i];
}
printf(“minimum element in array is : %d”,min);
printf(“\n maximum element in array is : %d”,max);
return 0;
}

Output

maximum and minimum element in array

 

 

 

Leave a Reply

Your email address will not be published. Required fields are marked *