C Program: Average Function
#include <limits.h> int avg(int a, int b) { int max = INT_MAX; int min = INT_MIN; int hmax = max / 2; int hmin = min / 2; if ((a == max) && (b == max)) { return max; } else if ((a == min) && (b == min)) { return min; } else if (a == b) { return a; } // 2 conditions of failure left to cover // 1 A == max , B > hmax // 2 B == max , A > hmax // Fuck if(a > hmax ) { if (b > hmax) { return hmax + (((a - hmax) + (b - hmax)) / 2); } else if (b > 0) { return (a / 2) + (b / 2); } else { return ((a + b) / 2); } } else if (a < hmin) { if (b < hmin) { return hmin + (((a - hmin) + (b - hmin)) / 2); } else if (b < 0) { return (a / 2) + (b / 2); } else { return ((a + b) / 2); } } else { return ((a + b) / 2); } }
Learn More :
Average
- C Program Array Example: Average
- Write the procedure , which is one of a sum , a product and a geometric average in the panel for the NxM elements are located on opposite diagonal and main diagonal . Remind ! Counting only odd elements !
- C Program Array NxM Elements Geometric/Arithmetic
- C Program To Find The Average Of n Numbers
- C Program to Average temperature in quarters
- C Program Average Temperature in Quarters
- C Program Number of Judge and Score From Each Judge
- C Program to accept n numbers from user store these numbers into an array & calculate average of n numbers
- Accept n number from user, store these number into an array and calculate the average of n number
Function
- How to pass one dimensional array to function in c.
- Write a c program which passes two dimension array to function.
- Write overloaded function templates for finding the roots of the linear (a * x + b = 0) and square (a * x2 + b * x + c = 0) uravneniy.Zamechanie: in function to send coefficients of the equations.
- C Program Character toupper() Example
- C Program Function Example
- Napisać funkcję obliczającą funkcję geometryczną w tablicy NxM elementowej z elementów o wartościach parzystych znajdujących się pod główną i ponad przeciwną przekątną.
- C Program To Find LCM and HCF Of Two Number Using Function - 2
- C Program To Convert Temperature In Celsius To Fahrenheit, Using Function
- C Program To Find Simple Interest
- C Function to Check Vowel
- Factorial Program In C Using Function
- C Program For Prime Number Using Function
- C Function to xorSwap and addSwap in C Programming
- C Program to concatenate two strings without using string functions
- C Function to read instructions from the file and obey them
- C program calculates a given function in range given by user, stores the data in arrays and displays the answer in a table.
- C Program to Implements a dictionary's functionality.
- = (int*)malloc(sizeof(int)) ??
- Design a C function that shortens a string to 8 characters
- C Program to Implements a dictionary's functionality
- C Program that prompts the user to input a string, (whitespaces allowed)
- Local sounds functions in C Program
- Function Get the resource that will be gathered from the zone name
- C Program to Find the Size of File using File Handling Function