There are some rules for writing a program in C language and before writing the program you should have the knowledge of all the rules. Here are the rules you need to follow.
- Each of the instruction in the C program is written in the separate statement. So we can say that a C program would be composed of a series of statements.
- All the statement in the program should appear in the same order in which we want them to be executed unless the logic of the problem requires a jump or transfer of the control to a statement which is out of sequence.
- You can insert blank spaces between two words to enhance the readability of the statement. However you can not add blank spaces within a variable, constant or keyword.
- All of the statements needs to be entered in small case letters.
- C language has got no specific rules for the position at which the statement needs to be written, therefore it is known as a free-form language.
- Each C statement needs to be ended with a ; so ; acts as a statement eliminator.
Here is an example of C language program
/* Calculation of simple interest */
/* Author gekay Date: 5/10/2020 */
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 ) ;
Here are few tips about the above mentioned program
- The comments about the program needs to be enclosed within /* */. like the first two statements in our program are comments.
- Comments are not necessary but it is advisable to add comments in your program indicating the purpose of the program.
- You can add any number of comments in the program and at any place like you can add comment before the statement, after the statement or within the statement.
- In /* .. */ normal rules of the language do not apply therefore you can type the text in any case or combination.
- A comment can be split over more than one line like
/* This is