# Programming Code Examples

## C & C++ Code Examples

Program code to access every 2-D Array we requires 2 subscript variables. y - Refers the Row number. x - Refers Column number. a[1][0] refers element belonging to first row

C Programming input a character and Check whether given character is alphabet, digit or special character using if else. A character is alphabet if it in between a-z or A-Z. Character

C Language program code sample input any number and check whether the given number is even or odd using bitwise operator. How to check whether a number is even or odd using

To calculate area and circumference we must know the radius of circle. C program code will prompt user to enter the radius and based on the input it would calculate the values. Make

C Program Code input Decimal number from user and convert to binary number system. Decimal number system is a base 10 number system. Decimal number system uses only 10

This C Program adds two complex numbers. A Complex Number is a number that can be put in the form a + bi, where a and b are real numbers & i is called imaginary unit, where...

Program 'takes a number' as input and finds a Greater number of the entered number using same digits. Take a number as input. Reverse the number and store it in the array. Using for

Declare recursive function to find factorial of a number. First let us give a meaningful name to our function, say fact(). Factorial Function accepts an integer input whose factorial is to

C First give a meaningful name to our prime checking function say isPrime() function will check a number for prime. Since our function checks a number for prime condition. Hence

Lets take 2 Strings as input and store them in the arrays string1[] and string2[] respectively. "Count the Number" of characters in both the arrays and store the result in the variables co1

How to find maximum and minimum element in an array using recursion in C programming. Recursion works on the concept of divide and conquer. We break the problem in its smallest

Declare function to find all prime numbers in given range. First give a meaningful name to our function. Say printPrimes() function will print all prime numbers in a range. Declare...

C program code to input character from user and check whether character is Uppercase or Lowercase alphabet using If Else Statement. Input a character from user. Store it in some

C program input number and check number is Palindrome or not using Loop. Palindrome number is such number which when reversed is equal to the original number. 121, 12321,...

The if...else statement executes some code if the test expression is true (nonzero) & some other code if the test expression is false (0). If test expression is true, codes inside the body

C language program take the number of days as input. For the number of years, divide the input by 365 and obtain its quotient. For the number of weeks, divide the input by 365 and

Take the integer which you want to check as input and store it in a variable number. Using if, else statements check whether the integer is Greater or Lesser than zero. If it is greater...

English Alphabets a, e, i, o, u both lowercase & uppercase are known as vowels. Alphabets other than Vowels are known as Consonants. Input an alphabet from user. Store it in some

Give a meaningful name to the function, say sumOfNaturalNumbers(). The function must accept two inputs i.e. the lower & upper limit to find sum. Pass two integer parameters to

Code read elements in an array from user and count total number of duplicate elements in array. C program code to find all duplicate elements in an unsorted array. How to list all

String is a "sequence of characters". char data type is used to represent one single character in C++. So if you want to use a String in your program then you can use an "array of chars".

Takes input a Character and Check it whether a 'character' is capital letter, small letter, Digit or Special character. 'All characters' like small or capital letters, digits and special characters

The Fibonacci sequence is a series where the next term is the "sum of pervious two terms". The first two terms of the Fibonacci sequence is 0 followed by 1. Fibonacci Numbers: 0, 1, 1,

Combined two strings means add both string with each other, perform this operation using 'library function' or without library function. If first string is 'john' and second string is porter

A 'positive integer' which is only divisible by 1 and itself is known as prime number. So 13 is a prime number because it is only divisible by 1 and 13 but, 15 is not prime number because

Column number of first matrix must be same as the row number of second matrix. Initialize matrix. Print values of the passed matrix and mutiply two matrices and return the resultant

Program takes two numbers (a 'base number' and an 'exponent') and Calculates the Power. The technique works only if the exponent is a positive integer. If you need to find the power

Write a simple C++ program which have four different functions for "basic operations" like addition, subtraction, division, multiplication. It should be menu based asking user to enter

Perform addition, subtraction, multiplication and division of any two numbers in 'C++', you have to enter the 'two number' and enter the operator to perform the particular operation

Takes an "arithmetic operator" (+, -, *, /) and two operands from an user and performs the operation on those two operands depending upon the operator entered by user. Program

Takes n number of element from user (where, n is specified by user), stores data in an array and calculates the average of those numbers, program calculates the average if the number

We can use "break" statement inside loops to terminate a 'loop & exit' it. In above example loop execution 'continues' until either n>=20 or entered score is negative. This statement

Find the minimum spanning tree of the given graph using Prims algorihtm. This algorithm is a "greedy algorithm" that finds a minimum spanning tree for a "Connected Undirected"

"Array index" starts with 0, which means the first array element is at index 0, second is at index 1 and so on. We use this information to display the array elements. See the C++ code

The second power was described in terms of the area of a square, as in the above formula. It led to the use of the term square to mean raising to the "second power". Thus the area

Full form of Ascii is American Standard Code for Information Interchange. It is a character "Encoding Scheme". Originally based on the English alphabet, every character or number

Ask to enter two time periods and these two periods are stored in structure variables t1 t2 respectively. The computeTimeDifference() Function calculates the Difference Between

Any "Programming Language" has a "list" of keywords. C++ Keywords are list of reserved words for this Programming Language. Each keyword has a special meaning and it can not

in C++, "bitwise operators" are similar to the Logic operators, but they perform the same logical operations on bits. All data in memory is represented in the "binary form". Variables

Basic "arithmetic operators" are +, -, *, /, %. "Increment operator" is ++ and "decrement operator" is --. These operators can be used as before the variable (prefix) and after the