Showing posts with label C Programs. Show all posts
Showing posts with label C Programs. Show all posts

Monday, 2 January 2017

C Program to Swap Two Numbers

Program:
This program is saved as Swap.c

Output:

Sunday, 1 January 2017

C Program to find greatest of three numbers

Program:
This program is saved as GreatestOfThree.c

Output:

C Program to Add n numbers

Program:
This program is saved as Add.c

Output:

C Program to Add Subtract Multiply and Divide the numbers

Program:
This program is saved as AddSubMulDiv.c 
Type casting is a way to convert a variable from one data type to another data type. For example, if you want to store a long value into a simple integer then you can type cast long to int. You can convert values from one type to another explicitly using the cast operator.

New data type should be mentioned before the variable name or value in brackets which to be typecast.

Converting an expression of a given type into another type is known as type-casting . typecasting is more use in c programming language.

It is best practice to convert lower data type to higher data type to avoid data loss.

Data will be truncated when higher data type is converted to lower. For example, if float is converted to int, data which is present after decimal point will be lost.

Output:

Saturday, 31 December 2016

C Program to find an Even or Odd Number

Program:
This program is saved as EvenOdd.c

Output:

Friday, 30 December 2016

C Program for Addition of Two numbers

Program:
This program is saved as add.c

Output:

C program to print an Integer number on screen

Program:
This program is saved as PrintIneger.c

Output:

Sunday, 25 December 2016

Structure of C program


1. /* This program........ */
The symbols /*........*/ used for comments. This comment are ignored by the compiler, and are used to provide useful information about program to humans who use it.

2. #include
This is a preprocessor which tells compiler to include stdio.h file.

3. main()
C programs consists of one or more functions. There must be one and only one main function. The brackets following the word main indicate that it is a function and not a variable.

4. { }
Braces surround the body of the function, which may have one or more instructions/statements.

5. printf()
It is a library function that is used to print data on the user screen.

6. "Hello World\n" is a string that will be displayed on user screen.
\n is the newline character.
; a semicolon ends a statement.

7. return 0;
 return the value zero to the Operating System.

NOTE: C is a case sensitive language, so the names of the functions must be typed in lower case as above. C programs are saved with .c extension.


Tuesday, 20 December 2016

Advantages of C

  • C is portable language.
  • C is the collection of lot of libraries.
  • C language is easy to learn.
  • C is widely accepted language.
  • C supports modular programming style.
  • C is native language of UNIX.
  • It is very efficient, It is popular and well understood.
  • It is easy for debugging, error finding, testing and maintenance because of structured programming.

Introduction of C Programming Language

     The C programming language is a general-purpose, high-level language (generally denoted as structured language). C programming language was developed by Dennis Ritchie between 1969 and 1973 at Bell Labs.

     C is one of the most commonly used programming languages. It is used in all extents of application, mainly in the software development. Many software's and applications as well as the compilers for other programming languages are written in C also Operating Systems like Unix, DOS and windows are written in C.

     C has many powers, it is simple, portable and it can control System Hardware easily. C has been standardized since 1989 by the American National Standards Institute (ANSI).