Posts

Showing posts from April, 2017

C program Simple Interest and Compound Interest

Image
This is a C programming code which calculates banking interest on principle amount for N years using Simple interest formula and Compound Interest formula. The input values for principle amount and number of years is read from user. Simple interest - formula I - Interest Amount P - Principle Amount to be deposited N - Number of years the principle amount to be deposited R - Rate of interest per year in percentage Simple interest - example calculation Assume that, we are going to deposit 5000$ in bank at rate of interest 8% for 5 years, calculate simple interest for the principle amount after 5 years P=5000; R =8; N=5; I =? I = 5000 x 5 x 8/100 I = 25000 x 0.08 I = 2000$ after 5 years , we will get additionally 2000$ as interest along with principle amount (10000$)

Number System Binary to Octal Conversion

Image
It is a C program which executes number system conversion from binary to octal numbers. Binary to Octal - algorithm set octal [] Read binary_bits form user reverse(binary_bits) while not EOF(binary_bits) read 3-bits from binary_bits convert 3-bits to decimal append decimal to octal end print reverse(octal) Binary to Octal conversion example The given binary number is 01101010010 and converts it into octal number binary = 01101010010, octal = ?, split binary 3 bits group from right to left direction and carried out binary to decimal conversion on each 3 bits group binary = 01 | 101 | 010 | 010 octal = 1 5 2 2 if

Convert Octal to Binary

Image
The C program carry out number system conversion from a octal value (base-8) to binary numbers (base-2) is called octal to binary conversion. A octal number is represented by binary 3 bits. Octal number system The octal number system has the following unique digits. {0, 1, 2, 3, 4, 5, 6, 7} As the octal number system has the 8 unique digits, it is called base 8 or radix 8 number system. Each octal digit can be represented by binary 3 bits. Binary number system The Binary number system has the following unique digits. {0, 1} As the binary number system has the 2 unique digits, it is called base 2 or radix 2 number system. The computer can only understand this number system and is operated by this binary number system, therefore it accepts data,instruction and everything in binary numbers format. Octal to Binary conversion example

Binary to Hexadecimal Conversion

Image
The number system conversion C program which converts binary number to a hexadecimal number, is called binary to hexadecimal conversion. alternatively, it is said be a conversion from base-2 to base-16 number system or radix-2 to radix-16 number system conversion. Binary to Hexadecimal - algorithm set hexa =[] Read binary_bits form user reverse(binary_bits) while not EOF(binary_bits) read 4-bits from binary_bits convert 4-bits to decimal append decimal to hexa end print reverse(hexa) Binary to Hexadecimal conversion example The given binary number is 11101101010110 and converts it into hexadecimal number binary = 11 1011 0101 0110, hexadecimal = ?, 1. split binary numbers into 4

Hexadecimal to Binary Conversion

Image
The number system conversion from hexadecimal number to binary number is explained by algorithm steps and it is tested by C programming implementation. Hexadecimal number system The hexadecimal number system has the following unique digits. {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, a, b, c, d, e, f} As the hexadecimal number system has the 16 unique digits, it is called base 16 or radix 16 number system. Each hexadecimal digit can be represented by binary 4 bits, therefore the hexadecimal numbers helps remember long binary sequence. Binary number system The Binary number system has the following unique digits. {0, 1} As the binary number system has the 2 unique digits, it is called base 2 or radix 2 number system. The computer can only understand or is operated by binary number system, therefore it accepts data,instruction and everything in binary numbers format.

C programming Minimum and Maximum of Numbers

It has two C programming code to find minimum value and maximum value of numbers, they are Minimum of Numbers - The input of the program is N numbers and the output is minimum of given inputs Maximum of Numbers - The input of the program is N numbers and the output is maximum of given inputs Minimum of array of numbers - Algorithm set min=INT_MAX Read N integers For i=1 : N IF integers[i] < min then min =integers[i] End IF End For print min Maximum of array of numbers - Algorithm set max=0 Read N integers For i=1 : N IF integers[i] > max then max =integers[i] End IF End For print max Minimum of Numbers - C programming code The C program reads N integers from user while the program is

C program Sum and Average of N numbers

It has two C program to do sum and average of N numbers. Sum of N numbers - N integers are given to it as input and return sum of input integers as result Average of N numbers - N integers are given to it as input and return average of inputs integers as result Sum of N numbers - algorithm The input N integers read from user add the N integers store result into a variable sum. and then prints sum value after end of loop. set sum=0 Read N integers For i=1 to N sum = sum + integers[i] End For print sum Average of N numbers - algorithm The input N integers read from user add the N integers store result into a variable sum. after end of loop, divide sum value by N and store results into a variable average, then prints average value . set su

C program Roots or solution of Quadratic Equation

Image
It has two C programs, they are function of quadratic equation - A value x is input and f(x) is output of the program. solving a quadratic equation - The coefficients a,b and c values are input and the solution value x1 and x2 are output of the program. Function of x to Quadratic equation The quadratic equation formed by three coefficients a,b and c are set constant in the program and a input x value is read from user to find f(x) (function of x). y =f(x) = ax 2 + bx + c it is a quadratic function, find y =? of given x value Given : a=1.0,b=2.0,c=1.0 and x = 0.5 substitute the given into quadratic function. y = 1 * 0.5 2 + 2*0.5 + 1 = 1 * 0.25 + 1 +1 = 0.25 + 2 y= f(0.5) = 2.25 Function of x to Quadratic equation - C program The C program find

C program Factorial number

Factorial number - it is iterative multiplication from 1 to a given factorial number. The C program finds decimal value equivalent to given factorial number using iterative manner or for-loop . Factorial number - example calculation find decimal value for given factorial number F =6! F = 1 x 2 x 3 x 4 x 5 x 6 F = 24 x 5 x 6 F = 120 x 6 F = 720 decimal value 720 is equal to factorial 6! Factorial - C programming code The input,factorial number is read from user, while the program is running and calculate result for the factorial number using for-loop. # include <stdio.h> int main () { int x=0; printf("\n Find decimal value for given factorial number"); printf("\nEnter factorial number x :"); scanf("%d",&x); int F=1; for ( int n=1; n<=x ; n++) { F = F * n; } print

C program String Reverse and palindrome

A array of characters enclosed by double quote and delimited by a NULL character is called string. The string is transformed into reverse string without using build-in function by this c programming given below. char name[20] = "dennis ritchie"; String Reverse string reverse - read a character by character from last to first index and copy it into another character array and finally add NULL character (delimiter) at end of the string ------------ "dennis ritchie" ----> | Reverse | ---> "eihctir sinned" ------------ String Reverse - C programming code The C program transform a given string into reverse string . The input string is to reverse read from user and prints reversed string as result of the program. # include <stdio.h> # include < str

C program Hello world

Helloworld.c, This is a first C program for a learner who is interested in C programming language. The Helloworld program explains basic structure of code in c to the learner. The C program learners are going to understand the following from this program. A C program must have a main function. The main function may have a return type or void. The main function may have commandline argument or not. The C program starts execution from the main function. The printf build-in function prints formatted string or any datatype on computer screen. Helloworld C Program The helloworld c program just prints hello world message on computer screen # include <stdio.h> int main () { printf("\n Hello world C "); return 0; } Helloworld C++ Program The helloworld c++ program just prints hello world message on computer screen # include < iostream > using namespace std ; int main () {

C program Fibonacci series and Fibonacci number

This C program prints Fibonacci number series to a given number x. The Fibonacci series starts with two number 0 and 1, and then successive numbers are find by its previous two number in the series. Fibonacci series start F.series = {0,1} next number in the series F.series = {0,1,0+1} next number in the series F.series = {0,1,1,1+1} next number in the series F.series = {0,1,1,2,1+2} process continue till next number < x Fibonacci series - C program The C program read a integer value x from user and then prints fibonacci series numbers less than integer value x. # include <stdio.h> int main () { int x=0; int cF=0,pF=1; printf("\n print Fibonacci series"); printf("\nEnter value x :"); scanf("%d",&x); printf("\n Fibonacci Series :"); do { printf( "%d ",cF); cF= cF + pF;

C program Biggest of 3 number

The following two C program finds biggest of given 3 numbers read from the user using if conditional statement and ternary operator. The input 3 numbers read from user as inputs and finds biggest number from the inputs. IF condition and ternary operator if-else ladder if ( <condition-1> ) { <statements 1 > } else if ( <condtion-2>) { <statements 2 > } else { <statements 3 > } if-else ladder has successive one or more if and if-else conditional statements, if any one of condition satisfied in if-else ladder, control executes following statements enclosed by curly brace { <statement>} and then control come out of if-else ladder. if a condition is not satisfied in if-else ladder, control goes to next condition else-if (<statement>). if none of condition satisfied in if-else ladder, the control executes else part

C program Leap year or not and Odd or Even

It is a program to find a year given by user is leap year or not . The input integer, year is read from user verified by modulus operator and condition statement. If the condition is satisfied, the year is leap year, otherwise it is not a leap year. Year is leap or not if the given year divided 4 and returns reminder 0, it is leap year, otherwise not leap year READ year reminder = year modulus 4 if reminder == 0, PRINT it is leap year else PRINT it is not leap year end Year is leap or not - C program The C program finds a given year is leap or not # include <stdio.h> # include < string .h> int main () { int year; int reminder=0; printf ("\n Find a given year is Leap year or not "); printf("\n Enter a Year :" ); scanf("%d", &year); reminder = year % 4; i

A character is vowel or not

It is a program to find a character given by user is vowel or not. The character read from user verified by condition statement. If the condition is satisfied, the character is vowel, otherwise it is not a vowel character. The two C program shown below finds a character is vowel or not by two different technique. They are, IF conditional statement switch case statement A character is vowel or not - C program using If condition The C program finds a given character is vowel or not using a If conditional statement. while the program is running, a character is read from user and verify the given character is satisfied by condition or not. # include <stdio.h> # include < string .h> int main () { char ch; printf("\n Find a given character is vowel or not "); printf("\n Enter a character :"); scanf("%c",&ch) ; if ( ch=='a' || ch=='e' || ch