How would I write the following program in C programming language?
Function header: int sumsort(int *a, int *b, int *c)
This function should arrange the 3 values in the memory locations pointed to by a, b, and c in ascending order and also return the sum of the contents of the memory locations a, b, and c.
#include<stdio.h>
int sumsort(int *a, int *b, int *c){
if(*a>*b) {
int temp=*a;
*a=*b;
*b=temp;
}
if(*b>*c) {
int temp=*b;
*b=*c;
*c=temp;
}
if(*a>*b) {
int temp=*a;
*a=*b;
*b=temp;
}
return (*a) + (*b) + (*c);
}
int main(){
int a=10,b=3,c=15;
int sum=sumsort(&a,&b,&c);
printf("%d %d %d = %d ",a,b,c,sum);
}
Note : Please comment below if you have concerns. I am here to help you
If you like my answer please rate and help me it is very Imp for me
Get Answers For Free
Most questions answered within 1 hours.