Tag Archives: C program

C013 A C program that will take as input a set of integers and find and display the largest and the smallest values within the input data values

Let’s identify variables needed for this program. In this program, we need several variables to store and compare the values to find the largest and the smallest out of them. Its not recommended to take number of variables declared of the same data type with different names and remembering it. It becomes worst when the… Read More »

C012 A C program that uses macros, MIN & MAX, to find and return, respectively the minimum & maximum of two values

Macro are the small code which is substituted wherever the macro is refered. macros can be used in two ways : First way as a replacement to the code which is long in length or repeated all the time.  e.g. #define CUBE(X) (X*X*X) Second way as a small function in which we can pass arguments… Read More »

C011 A C program to write a function that calculates the compounded interest amount for a given initial amount, interest rate & no. of years. The interest is compounded annually. The return value will be the interest amount

First thing to know before writing this program is the Simple interest Formula. COMPOUND INTEREST = (P *(1+R) N) P = PRINCIPAL AMOUNT. N = NUMBER OF YEARS (TIME). R = RATE OF INTEREST. Here the problem is the rate of interest should be in the form of 0.10 instead of 10%. Now, find out the variables… Read More »

C010 A C program to write a function invert(x, p, n) that returns x with the n bits that begin at position p inverted. You can assume that x, p & n are integer variables and that the function will return an integer

As an example, if x = 181 in decimal which is 10110101 in binary, and p = 4 and n = 2, then the function will return 10101101 or 173 in decimal. The underlined bits are the changed bits. Note that bit positions are counted from the right to the left and that the counts… Read More »

C009 An interactive C program to find the roots of a Quadratic equation

First thing to know before writing this program is the Quadratic Equation Formula. Here the problem is the this whole Quadratic Equation can not be written on single line. Now, find out the variables needed for calculating Roots of Quadratic Equation. X1 = (-B-Square Root(b 2 – 4AC))/2A    AND   X2 = (-B+Square Root(b 2 – 4AC))/2A… Read More »

C008 An interactive C program to check whether given two numbers are amicable numbers or not

Amicable numbers are two numbers so related that the sum of the proper divisors of the one is equal to the other, unity being considered as a proper divisor but not the number itself. Let’s identify variables needed for this program. First two variables will be the one which will save the values entered by… Read More »

C007 An interactive C program to check whether a given number is a perfect number or not

A positive number is called Perfect Number if it is equal to the sum of all of its positive divisors,  excluding number itself. Let’s identify variables needed for this program. First variable will be the one which will save the value entered by the user and it will be NUM. Second variable will be i… Read More »

C005 An interactive C program to generate the divisors of a given integer

Divisors are the numbers which can divide the number given and are less than the given number. Let’s identify variables needed for this program. First variable will be the one which will save the value entered by the user and it will be NUM. Other variable will be i which will be for FOR Loop.… Read More »

C004 An interactive C program that reads in integers until a zero is entered and display total of odd and even numbers and average of odd and even numbers

Let’s identify variables needed for this program. First variable will be the one which will save the value entered by the user and it will be NUM. Other variables will be according to the output requirements that are Total of even numbers (TOTAL_EVEN), Total of odd numbers (TOTAL_ODD), Average of even numbers (AVG_EVEN), Average of… Read More »