Happy Codings - Programming Code Examples
Html Css Web Design Sample Codes CPlusPlus Programming Sample Codes JavaScript Programming Sample Codes C Programming Sample Codes
CSharp Programming Sample Codes Java Programming Sample Codes Php Programming Sample Codes Visual Basic Programming Sample Codes

C Programming Language Code Examples

C coding to Accessing 2-D Array Elements
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 Checking the Character is Alphabet Digit
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 Programming code Array Concatenation
To concate two arrays, we need at least three array variables. We shall take two arrays and then based on some constraint, will copy their content into one single array. We shall
C Least Significant Bit (LSB) of a number is
C program code input any number from user and check whether the Least Significant Bit (LSB) of the given number is set (1) or not (0). How to check whether the least significant...
Returns a String representation of Integer
Converting an integer to a string with a fixed width. If the width is too small, the minimum width is assumed. Generate digit characters in reverse order. Shift the string to the right
Check Even or Odd using Bitwise Operator
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
C Program Code Clear NTH bit of Number
Program Input number and nth bit position to clear from user. Store it in some variable say j and n. Left shift 1, n times i.e. 1 << n. Perform bitwise complement with the above result...
C Output of a Program is Input of Another
Pipe the output of program to the input of another. Duplicate stdin and stdout so we can restore them later. Make the write end of the pipe stdout. Run the program. Its output will
2d example insertion sort [linked list] in C
C program code to 2d example insertion sort [linked list]. Insert a node directly at the right place in the linked list. Insert some numbers into the linked list. Print the list. Free the list
Calculates Area & Circumference of Circle
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
Checking the Number is a Perfect Number
Program input a number and check whether the number is Perfect number or not. Perfect number is a positive integer which is equal to the sum of its proper positive divisors. So 6 is
C Programming Bubble sort [Linked List]
If the list is empty, create first node. Go to last node. Add node at the end. Preform a bubble sort on the linked list. The 'c' node precedes the 'a' and 'e' node pointing up...
Code Converts Decimal to Binary Number
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
C Program Insertion Sort implementations
'Insertion Sort Algorithm' picks elements one by one & places it to the right position where it belongs in the "Sorted List of Elements". In C program we have "implemented the same"
C Program to Add two Complex Numbers
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...
Checks If the Substring is Present in String
C Program 'checks the substring' is present in a given string. Program accepts both string & substring. Then checks whether the substring is present in the string. Enter search substring
Finds Greater Number of Entered Number
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
Accept Sorted Array and do Binary Search
C Program accepts the sorted array and does search using "Binary Search". Binary search is algorithm for locating the position of an item in a 'Sorted Array'. A search of sorted data, in
C Program Check the String is Palindrome
C program code to 'Check whether a String' is palindrome or not without using loop. How to Check whether a string is 'Palindromic String' or not in C. Palindrome string is special string
Finds Factorial of Number using Recursion
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
Program Find GCD (HCF) of Two Numbers
Recursive function in C language to find GCD (HCF) of two numbers. Find GCD ( Greatest Common Divisor ) or HCF ( Highest Common Factor ) of two numbers using recursion in C
C Program Inputs two Strings & Compares
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
Maximum Minimum Elements in the Array
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
Program for Beginners: Area of Rectangle
A plane figure with 4 sides & 4 right angles & having Equal Opposite sides. Adjucent sides makes an Angle of 90 degree. Just compute the area of a Rectangle if you know its length
Most Significant Bit (MSB) of a number is
In C programming language we use bitwise AND & operator to check status of any bit. Bitwise AND operation evaluate each bit of resultant value as 1, if corresponding bit of...
Prime Numbers in a Range with Functions
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 Analogue Clock create and Display Time
Record the time program starts execution. Record the current time, using the alternate method of. Convert the time_t value into a type tm structure. Create and display a string
Checks Character is Uppercase Lowercase
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
Program code to addition of two matrices
Before accepting the Elements Check if no of rows and columns of both matrices is equal. Accept the Elements in Matrix 1 and Matrix 2. Addition of two matrices. Print out the matrix
If Else Check Given Integer is Odd or Even
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 If a given Integer is Positive or Negative
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...
Amstrong Number Program In C language
C Language program to Amstrong Numbers. Armstrong Number is a number which equal to the sum of the cubes of its individual digits For example, 407 is an armstrong number as
Check Vowel or Consonant use switch case
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
Check Even or Odd number by switch case
Input number from user and check whether the number is even or odd using switch case. A number is said even number if it is exactly divisible by 2. In C we use Modulo operator...
C Program to generate nth Fibonacci term
C Code Declare recursive function to find nth Fibonacci term. Assign a meaningful name to the function, say fibo(). The function accepts an integer hence update function declaration
C Language Break Statements Switch Case
Break Statements are useful when you want your program-flow to come out of the switch body. Whenever break is encountered in the switch body, the control comes out of switch
C Find Sum of Natural numbers in a range
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
2D-Drawing Circles, Arcs, Rectangle, Lines
This 2D-Drawing Program is used for drawing circles, arcs, rectangle, lines and many more. Controls for the two-dimensional drawing. Enter radius of circle, enter radius, starting...
Find Maximum Minimum using Functions
First give a meaningful name to our function. Say max() function is used to find maximum between two numbers. Second, we need to find maximum between two numbers. And
C Check the Number is Armstrong number
C Program to input a number from user and check whether given number is Armstrong number or not. Armstrong number is n-digit number that is equal to the sum of the nth...
Check Prime, Armstrong, Perfect Number
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
C Finds Cube of a Number using Function
C Program code input any number from user and find cube of the a number using function. Lets assign meaningful name to the function, say cube(). Function should accept a number
Converts Decimal to Hexadecimal Number
C program input decimal number and convert to Hexadecimal number system. The Decimal number system is a base 10 number system. Decimal number system uses 10 symbols to...
Check whether a number is Prime number
Prime numbers are positive integers greater than 1 that is only divisible by 1 and self. For example: 2, 3, 5, 7, 11 etc... C program input number and check whether the number is...
Codes Binary Number to Decimal Number
Takes the binary number (entered by user) as input and converts it into a decimal number using function. To understand this program, you should be familiar with the following C...
Input Number & Check it is Palindrome or
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,...
C Programming Uses For Loop Statements
For Loop in C. First initialization happens and the counter variable gets initialized. Second step the condition is checked, where counter variable is tested for the given condition, if...
Convert Decimal number to Octal Number
Accept the given decimal number. If number is less than 8 the octal number is the same. If the number > 7 then Divide the number with 8. Write down the remainder. Do steps 3 and
C Convert Binary to Octal Number System
In C program user is asked to enter the binary number and the program then converts that binary number to the octal number by calling a user defined function. To understand this...
Code Convert a Decimal Number to Binary
C Converts a decimal number into binary and count the number of 1s. The c program uses module operation and multiplication with base 2 operation for conversion. It also uses
Convert a Given Number of Days in Terms
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
C Program Code to Catch pressing Ctrl+C
Program example catches the Ctrl-C (SIGINT) signal for the first time and prints a output rather but exits on pressing ctrl-c again. You have presses Ctrl-C, please press again to exit
C Matrix of Order M x N and Interchange
C language program code to accept a matrix of order M x N and store its elements and interchange the main diagonal elements of the matrix with that of secondary diagonal
C Program Command using System Calls
C language example implementation of LN command using system calls. Error: Too Few Arguments. Error: Too Many Arguments. Error: Invalid Syntax. Error: File name not...
Convert Decimal to Binary number system
C program to input any decimal number from user and convert it to binary number system using bitwise operator. How to convert from decimal number system to binary number...
Bitwise operators are used in C Language
C Program Code Bitwise operators During computation, mathematical operations like: addition, subtraction, addition and division are converted to bit-level which makes and
Function to Return a String representation
C Convert an integer to a string. Caller must allocate string array. Function returns string to allow. Use of the function in an expression. Generate digit characters in reverse order...
C Coding to find Sum of Two Matrices 3x3
C program to read elements in two matrices and add elements of both matrices. C code for addition of two matrix. Matrix addition program in C. Logic to add two matrix in C.
Add Two Matrix Multi-Dimensional Arrays
In this program, user is asked to entered the number of rows r and columns c. The value of r and c should be less than 88 in this program. The user is asked to enter elements of two...
Count total Duplicate Elements in an array
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