C Programming language

adplus-dvertising
How to make a simple c program
Previous Home Next

There are some rules by the help of which we can make a simple C program. The rules are given below:

  1. Each instruction in a C program is written as a separate statement. Therefore a complete C program would comprise of a series of statements.
  2. he statements in a program must appear in the same order in which we wish them to be executed; unless of course the logic of the problem demands a deliberate 'jump' or transfer of control to a statement, which is out of sequence.
  3. Blank spaces may be inserted between two words to improve the readability of the statement. However, no blank spaces are allowed within a variable, constant or keyword.
  4. All statements are entered in small case letters.
  5. Every C statement must end with a ;. Thus ; acts as statement terminator.

Let us take an example to understand the first C program

/* Calculation of simple interest 

main( )
{
int p, n ;
float r, si;
p = 1000;
n = 3;
r = 8.5;
/* formula for simple interest */
si = p * n * r / 100 ;
Printf ("%f", si);
}

main( ) is a collective name given to a set of statements. This name has to be main( ), it cannot be anything else. All statements that belong to main( ) are enclosed within a pair of braces { } as shown below:

main ( )
{
statement 1;
Statement 2;
}

Technically speaking main () is a function.
Any variable used in the program must be declared before using it.

Example

int p, n;

The printf ()function is used to display the value. The general form of the printf () function is:

Printf (“<format string>", <list of variables> ) ;

<format string> can contain

%f for printing real values
%d for printing integer values
%c for printing character values
Previous Home Next