Showing posts with label Example. Show all posts
Showing posts with label Example. Show all posts

C programming examples

These programs illustrate various programming elements, concepts such as using operators, loops, functions, single and double dimensional arrays, performing operations on strings, files, pointers etc. 
Browse the code from simple c program to complicated ones you are looking for, every one of them is provided with output. 
C program download with executable files, so that you save on your computer and run programs without compiling the source code. All programs are made using c programming language and Codeblocks, most of these will work under Dev C++ compiler also. 
The first program prints "Hello World" on screen.


  1. Hello World
  2. Print Integer
  3. Addition
  4. Odd or Even
  5. Add, Subtract, Multiply and Divide 
  6. Leap year
  7. Factorial
  8. HCF and LCM
  9. Add n numbers
  10. Swapping
  11. Reverse number
  12. Palindrome number
  13. Print Pattern
  14. Prime numbers
  15. Find Armstrong number
  16. Fibonacci series

C hello world program

C hello world program: c programming language code to print hello world. This program prints hello world, printf library function is used to display text on screen, '\n' places cursor on the beginning of next line, stdio.h header file contains declaration of printf function. 
The code will work on all operating systems may be its Linux, Mac or any other and compilers. To learn a programming language you must start writing programs in it and may be your first c code while learning programming.

Hello world in C language

//C hello world example
#include 
 
int main()
{
  printf("Hello world\n");
  return 0;
}
Purpose of Hello world program may be to say hello to people or the users of your software or application.


Solved Examples for an algorithm

1. Write an algorithm to assign the value of a variable to another variable.

The algorithm can be written as:

1. Declare X and Y.
2. Read value for X.
3. Assign value of X and Y.
4. Print value of X and Y.


2. Write an algorithm that prints the smaller of any two given numbers.

Solution:

Steps : 1. Read two numbers X and Y.
           2. Compare X and Y.
           3. If X is smaller than Y print X else print Y