Rules to Write a C program

  • − All lines of C statements must end with a semicolon.
  • − C is case-sensitive. That is, uppercase and lowercase characters are different. Usually, the statements are typed in lowercase.
  • − A C Program statement can be split into many lines or can be written in one line.
  • − Braces must always match upon pairs, i.e., every opening brace { must have a matching closing brace }.
  • − All C program starts with void main( ) function. 6. Comments cannot be nested. For example,
  • − /* Welcome to C World ,/* programming*/ */
  • − Comment can be split into more than one line as per by the user preference.

Execution of C Program

To write and run a C program, given steps should be followed.

Creation of Source Program

  • −Create a C program file in various C compilers are available under MS-DOS, Turbo C Editor etc.

Compilation of a C Program

  • − Turbo C compiler is user friendly yet free and provides integrated program development environment. So, selecting key combination can do compilation. That means press Alt + F9 for compilation.on.

Program Execution

  • − In Turbo C environment, the RUN option will do the compilation and execution of a program. Press Ctrl + F9 for execution the program.

printf( ) Function: Writing Data for Output

The printf( ) function is used to write information to console (normally computer screen). The main structure of this function is printf(format string, list of arguments);The format string contains the following:

  • − Characters that can be simply printed on the screen.
  • − Specifications that begin with a % sign and define the output format for display of each item.
  • − Escape series characters that start with a \ sign such as \n, \t, \b etc.
Character Argument Resulting Output
c character A Single Character
d integer Signed decimal integer
s String Print Character Strings
f floating Point Single floating point Number

scanf( ) Function: getting user input

scanf() function used for accept value from the standard input device. This means that the program gets input values for variables from users. The scanf( ) function is a built-in C function that allows a program to accept user input from the keyboard. The structure of this function is scanf(format string &list of arguments);

  • Examples:-
  • − scanf %d , &a ;
  • − scanf %d %c %f ,&a, &b, &c ;