C Examples

 

C Programs


C “Hello, World!” Program

 


C Program to print Hello World without using Semicolon

 


C Program to Time Delay function

 

 


C Program to print integer


C Program to Add Two Integers

  • Add Two Integers.c
  • FAQ : What will happens if we add two char value maximum and store in char value

C Program to Add two integer without using arithmetic operator


C Program for Increment & Decrement operators


C Program to Multiply two Floating Point Numbers


C Program to convert Inch to Feet

Pr-Request to learn

  • Preprocessor command #
  • Header file
  • Variable declare & define
  • Multiplication * operator
  • printf() function

 

Code

 

Output : there are 120 inches in 10 feet

 

Code Explanation

  • #include<stdio.h> is a standard input output header file.
  • C requires a ; semicolon at every end of the statement.
  • printf() is a standard C function (Called from main)
  • \n signifies new line.

ASCII Value

Printing ascii value using c program 

 

C code for ASCII table 

C program to display ASCII values 

 

 


C Program to Compute Quotient and Remainder


C Program to Find the Size of int, float, double and char


C Program to Demonstrate the Working of Keyword long


C Program to Ascending Order of N Numbers in Array


C Program to Descending Order of N Numbers in Array


C Program to Swap Two Numbers


C Program to Check Whether a Number is Even or Odd


C Program to Check Whether a Character is Vowel or Consonant


C Program to Find the Largest & Smallest Number Among Three Numbers

Using Ternary Operator

  • This below program for find the largest number. if you wanna check smallest number just the line 9 small=a<b ? (a<c?a:c) : (b<c?b:c);


C Program to find the smallest & Largest of N numbers using array.

Using Array


C program to fine Largest & Smallest Number and Position of N numbers in Array.c


C Program find the duplicate number and delete the number in Array

 

 


C program to Find Mean and Standard Deviation in Array Element.c


C Program to Find all Roots of a Quadratic Equation


C Program to Check Leap Year


C Program to Check Whether a Number is Positive or Negative


C Program to Check Whether a Character is an Alphabet or not


C Program to Calculate the Sum of Natural Numbers


Perfect Number

Definition of perfect number or What is perfect number? 

 Perfect number is a positive number which sum of all positive divisors excluding that number is equal to that number. For example 6 is perfect number since divisor of 6 are 1, 2 and 3.  Sum of its divisor is  1 + 2+ 3 =6  Note: 6 is the smallest perfect number.  Next perfect number is 28 since 1+ 2 + 4 + 7 + 14 = 28 Some more perfect numbers: 496, 8128 

Code 1: 

  1. C program to check perfect number

 

 

Code 2: 

  1. C program to find perfect numbers
  2. C perfect number code
  3. Perfect number program in c language

 

Code 3: 

  1. C program to print perfect numbers from 1 to 100

 



C Program to Find Factorial of a Number

 

Code 1:

  1. C code for factorial of a number
  2. C program to find the factorial of a given number
  3. Factorial program in c using while loop
  4.  Factorial program in c without using recursion

 

Code 2:

  1. Factorial program in c using for loop
  2. Simple factorial program in c
  3. C program to calculate factorial

 

Code 3: 

  1. Factorial program in c using pointers
  2. How to calculate factorial in c
  3. Factorial program in c language

 

Code 4: 

  1. Factorial program in c using function
  2. C program to find factorial of a number

 

 

Code 5: 

  1. Factorial series in c

 


C Program to Find Factorial of a Number Using Recursion

 


C Program to count set bits in an integer

FAQ :

  • C Program to Count the Number of Bits set to One using Bit-wise Operations
  • Write an efficient program to count number of 1s in binary representation of an integer

Code

 



C Program to Generate Multiplication Table

 



C Program to Display Fibonacci Sequence

 

Algorithm: 

  • What is Fibonacci series? 
  • Logic of Fibonacci series 

Definition of Fibonacci numbers: 

  • We assume first two Fibonacci are 0 and 1
  • A series of numbers in which each sequent number is sum of its two previous numbers is known as Fibonacci series and each numbers are called Fibonacci numbers. So Fibonacci numbers is 

Algorithm for Fibonacci series  : Fn= Fn-2+ Fn-1 

Example of Fibonacci series: 0 , 1 ,1 , 2 , 3 , 5 , 8 , 13 , 21 , 34 , 55 ... 

 5 is Fibonacci number since sum of its two previous number i.e. 2 and 3 is 5 

8 is Fibonacci number since sum of its two previous number i.e. 3 and 5 is 8 and so on. 

Code 1: 

  1. Write a program to generate the Fibonacci series in c
  2. Write a program to print Fibonacci series in c
  3. Basic c programs Fibonacci series
  4. How to print Fibonacci series in c
  5. How to find Fibonacci series in c programming
  6. Fibonacci series in c using for loop

 

 

Code 2: 

  1. Fibonacci series using array in c
  2. Fibonacci series program in c language
  3. Source code of Fibonacci series in c
  4. Wap to print Fibonacci series in c

 

Code 3: 

  1. Fibonacci series in c using while loop
  2. C program to calculate Fibonacci series
  3. C program to display Fibonacci series
  4. Fibonacci series in c with explanation
  5. C code to generate Fibonacci series

 

 

Code 4: 

  1. Sum of Fibonacci series in c

 



C Program to Floyd’s Triangle


Pascal triangle

  1. Pascal triangle in c without using array
  2. C code to print Pascal triangle
  3. Simple c program for Pascal triangle
  4. C program to generate Pascal triangle
  5. Pascal triangle program in c language
  6. C program to print Pascal triangle using for loop

 



C Program to Find GCD of two Numbers

Greatest Common Divisor


C Program to Find LCM of two Numbers


C Program to Display Characters from A to Z Using Loop


C Program to Count Number of Digits in an Integer


C Program to Reverse a Number


C Program to Calculate the Power of a Number


C Program to Check Whether a Number is Palindrome or Not


C Program to Check Whether a Number is Prime or Not


C Program to Display Prime Numbers Between Two Intervals

 



C Program to Check Armstrong Number

Definition of Armstrong number or what is an Armstrong number: 

Definition according to c programming point of view: 

Those numbers which sum of the cube of its digits is equal to that number are known as Armstrong numbers. For example 153 since 1^3 + 5^3 + 3^3 = 1+ 125 + 9 =153 . Other Armstrong numbers: 370,371,407 etc. 

In general definition:  

Those numbers which sum of its digits to power of number of its digits is equal to that number are known as Armstrong numbers.  

Example 1: 153  

Example 2: 1634  

Examples of Armstrong numbers: 1, 2, 3, 4, 5, 6, 7, 8, 9, 153, 370, 371, 407, 1634, 8208, 9474, 54748, 92727, 93084, 548834, 1741725 

 

Code 1 :

  1. Warp to check a number is Armstrong
  2. C program to check whether a number is Armstrong or not
  3. Simple c program for Armstrong number
  4. Armstrong number in c with output

Code 2 : while loop

Code 3 :

  1. Armstrong number in c using for loop

 

 


C Program to Display Armstrong Number Between Two Intervals

Code 1 : C program for Armstrong number generation

 

Code 2 :

  1. C program to print Armstrong numbers from 1 to 500
  2. C program for finding Armstrong numbers

 

 

 


C Program to Display Factors of a Number


C Programming Code To Create Pyramid and Structure

  • https://cprogrammingcodes.blogspot.in/p/pyramid.html
  • Generate a following structure : GitHub code Square_Structure.c

@@@@@

@@@@@

@@@@@

@@@@@

@@@@@

#####

####

###

##

#

 


C Program to Make a Simple Calculator Using switch…case


C Program to Display Prime Numbers Between Intervals Using Function


C Program to Check Prime or Armstrong Number Using User-defined Function


C Program to Check Whether a Number can be Expressed as Sum of Two Prime Numbers


C Program to Find the Sum of Natural Numbers using Recursion


C Program to Find G.C.D Using Recursion


C Program to Convert Binary Number to Decimal and vice-versa

 


C Program to Convert Binary Number to Hexa-Decimal and vice-versa


C Program to Convert Octal Number to Decimal and vice-versa


C Program to Convert Binary Number to Octal and vice-versa

 


C Program to Convert Decimal to Binary Number vice-versa


C Program to Convert Decimal to Hexa Decimal Number vice-versa


C program to Reverse a Sentence Using Recursion


C program to calculate the power using recursion


C Program to Calculate Average Using Arrays


C Program to Find Largest Element of an Array


C Program to Calculate Standard Deviation


C Program to Add Two Matrix Using Multi-dimensional Arrays


C Program to Multiply to Matrix Using Multi-dimensional Arrays


C Program to Find Transpose of a Matrix


C Program to Multiply two Matrices by Passing Matrix to a Function


C Program to Access Elements of an Array Using Pointer


C Program Swap Numbers in Cyclic Order Using Call by Reference


C Program to Find Largest Number Using Dynamic Memory Allocation


C Program to Find the Frequency of Characters in a String


C program to count the number of vowels, consonants and so on


C Program to Remove all Characters in a String Except Alphabet


C Program to Find the Length of a String


C Program to Concatenate Two Strings


C Program to Copy String Without Using strcpy()


C Program to Sort Elements in Lexicographical Order (Dictionary Order)


C Program to Store Information of a Student Using Structure


C Program to Add Two Distances (in inch-feet) System Using Structures


C Program to Add Two Complex Numbers by Passing Structure to a Function


C Program to Calculate Difference Between Two Time Periods


C Program to Store Information of Students Using Structure


C Program to Store Information Using Structures with Dynamically Memory Allocation


C Program to Write a Sentence to a File


C Program to Read a Line From a File and Display it


C Program to read excel and store in File


C Program to Display its own Source Code as Output


C Programming Code To Create Pyramid and Pattern


Day Finder (Two dates difference)


Given Number of days into year, week, days.

  • This below program is compiled in gcc version 4.6.3 at online c compiler repl.it

 


Reverse Number in C

 


Find the Largest number in given number

 



C Tutorial -Examples


C Program for Array


C Program for Sum of the Array element

 


C Program for Bubble sort Algorithm (Folder)


C Program to Random Number Generator

Windows Commands

If you want to access the windows commands using C program? its very easy to do. For that you need to include predecessor (stdlib.h) . See the Below code



C program to find area and circumference of circle

Pr-Request to learn

  • Preprocessor command #
  • Header file
  • Variable declare & define
  • Multiplication * operator
  • if , else statement
  • printf() function

 

Code

 

Code Explanation

  • #include<stdio.h> is a standard input output header file.
  • C requires a ; semicolon at every end of the statement.
  • printf() is a standard C function (Called from main)
  • \n signifies new line.

 


Printf Function Example

Example 1 :

Output is dependent on the compiler. For 32 bit compiler it would be fffffffe and for 16 bit it would be fffe.

 

Example 2 :

Output : %s ArunEworld ArunEworld
Explanation: After pre-processing phase of compilation, printf statement will become



Memory Layout

Example 1 :

Output: “Nice test for strings”
The above program works because string constants are stored in Data Section (not in Stack Section). So, when getString returns *str is not lost.

 

 

 

 

  • string constants are stored in Data Section (not in Stack Section)
  • static variable and is stored in Data Section,
  • array variables are stored in Stack Section

 

 



For Loop Example

 

Example : Predict the output of below programs

Output : Above program goes in infinite loop because n is never zero when loop condition (n != 0) is checked.

 

 


C++ Example Programs

 


Reference

0

Your Cart

%d bloggers like this: