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

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.

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

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.

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

We to update you

© Copyright 2018