CS Electrical And Electronics
@cselectricalandelectronics

Write a C program for the one-dimensional array to store elements in an array and find the smallest element in the array?

All QuestionsCategory: C LanguageWrite a C program for the one-dimensional array to store elements in an array and find the smallest element in the array?
CS Electrical And Electronics Staff asked 4 years ago

I need short info

1 Answers
CS Electrical And Electronics Staff answered 4 years ago

Code:

#include<stdio.h>
#define MAX 50
void read(int a[MAX], int n);
void display(int a[MAX],int n);
void small(int a[MAX],int n);
int main()
{
int n, a[MAX];
printf(“Enter array size”);
scanf(“%d”,&n);
read(a,n);
display(a,n);
small(a,n);
return 0;
}
//Chetan Shidling
void read(int a[MAX], int n)
{
int i;
printf(“Enter the array elements”);
for(i=0;i<n;i++)
scanf(“%d”,&a[i]);
}
void display(int a[MAX],int n)
{
int i;
printf(“Array elements are \n”);
for(i=0;i<n;i++)
printf(“%d \n”,a[i]);
}
//CS Electrical & Electronics
void small(int a[MAX],int n)
{
int i,sml,x=1;
sml=a[0];
for(i=1;i<n;i++)
{
if(a[i]<sml)
sml=a[i];
x=i+1;
}
printf(“Smallest among all=%d”,sml);
}

Output:

Enter array size :4
Enter the array elements :12
2
33
1
Array elements are :
12
2
33
1
Smallest among all=1