The ones who are crazy enough to think they can change the world are the ones who do.
- Steve Jobs

C Sum of Two Mininum Numbers In An Array

Sum of two minimum numbers

Here your task is to ask user to enter any number of elements in an array and you have to response with the summation of two minimum numbers in an array.

C Program - Sum of Two Minimum Numbers in an Array

Let us write a C program to find the minimum summation of any two numbers in an array.

sum-two-mininum-numbers-array.c
#include <stdio.h>
int main()
{
int a[10], i, j, sum = 0, temp, n;
printf("Enter array size: ");
scanf("%d", &n);
for(i = 0;i < n;i++)
scanf("%d",&a[i]);
for(i = 0;i < n-1;i++)
{
for(j = i;j < n;j++)
{
if(a[i] > a[j])
{
temp = a[i];
a[i] = a[j];
}
}
}
sum = a[0] + a[1];
printf("\nsum of minimum two elements are : %d ", sum);
return 0;
}
Enter array size : 5
1 3 5 7 9
sum of minimum two elements are : 4

Note:

First of all, we sort all the elements in an array in ascending order and then we add the first two elements in an array to produce the summation result of two minimum numbers in an array.

Report Us

We may make mistakes(spelling, program bug, typing mistake and etc.), So we have this container to collect mistakes. We highly respect your findings.

Report