BASIC IN C LANGUAGE
Once armed with the knowledge of variables, constants and keywords, the next logical step would be to combine them to form. instructions. However, instead of this, we would write our first C program now. The first program is very simple.
simple program - odd even
#include
#include
void main()
{
int a;
printf("enter a number=");
scanf(the number is "%d",a);
if(a%2==0)
{
printf("the given number is even");
else
printf("the given number is odd");
}
getch();
}
odd-even programming |
NOW UNDERSTAND THIS PROGRAM IN DETAIL
Form of a C program indicates how it has to be written/typed.There area certain rule about the form of a C program that are applicable to all C programs. These are as under :
1) Each instruction in a C program is written as a separate statement.
2) The 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 a may be inserted between two words to improve the readability of the statement. However, no blanks spaces are allowed within a variable, constant or keyword.
4) All statements should be in small case letters.
5) C has no specific rules for the position at which a statement is to be written in a given line. That's why it is often called a free-form language.
6) Every C statement must end with a;. Thus ; acts as a statement terminator .
comments in a c program
Comments are used in a C program to clarify either the purpose of the program or the purpose of some statement in the program. Although a lot of comments are probably not necessary in a program, it is usually the case that programmers tend to use too few comments rather than too many. An adequate number of comments can save hours of misery and suffering when later try to figure out what the problem does.
here are a few things that you must remember while writing comments in a C program.
a) Comments about the program should be enclosed within " /* */ " . for example , the first two statement in our program are comments.
b) Though comments are not necessary, it is a good practice to begin a program with a comment indicting the purpose of the program, its author and the date on which the program was written.
c) Any number of comments can be written in any place in the program. For example, a comment, after the statement or within the statement as shown below :
example
1) /*formula */ si=p*n*r/ 100;
2) si= p*n*r/100; /*formula*/;
3) si= p*n*r /*formula*/ 100;
d) Sometimes it is very obvious as to what a practical statement accomplish. At which times it is worthwhile mentioning the purpose of the statement using a comment.
example
/*formula of simple interst*/
si= p*n*r/100;
e) The normal language rules do not apply to text written within /*..*/.Thus we can type this
text in small case, capital or a combination. This is because the comments are slowly given for the understanding of the programmer or the fellow programmers and are completely ignored by the compiler.
what
f) Comments can't be nested.
example
/* programming language /*c language*/*/ in not valid.
g) A comment can be split over more than one line, as in,
example
/* my name is bharat
i am programmer*/
h) ANSI permits comments to be written in the following way:
https://www.ansi.org/
// odd and even number
//check this even or not