Translate

Labels

Monday 31 December 2012

CONDITIONAL STATEMENTS ( IF )

IF STATEMENT

In C, the conditional statements rely on idea of boolean expressions.The if statements controls conditional branching.The boolean expression or in other words a relation expression will yield true or false value.In C, a value other than 0 is true and 0 is considered as false.The body of an if statement is excuted if the value of the expression is true i.e..,non_zero.There are two forms of if statement.

if (relation expression)
statement;

if(relation expression)
statement 1;
else
statement 2;

 In the first form of, if relational expression is true (non zero), the statement is executed. If the expression is false, the statement is ignored.In the second form ,which uses else, statement 2 is executed if the expression is false.With both forms,control then passes from the statement to the next statement in the program.
Here is a C program demonstrating a simple if statement:

#include<stdio.h>
void main()
{
int x;
printf("Enter an integer:");
scanf("%d",&x);
if(x>0)
printf("The value is positive\n");
}

This program accepts a number from user.It then tests the number using a conditional expression of the if statement to see if it is greater than 0.If it is,the program prints a message.Otherwise,the program is silent i.e..,there will be no output.The (x>0) portion of the program is the boolean expression.C evaluates this expression to decide whether or not to print the message.If the boolean expression evaluates to true, then C executes the single line immediately following the if statement (or a block of lines within braces immediately following the if statement ) .If the boolean expression is false, then C skips the line or block of lines immediately following the if statement.consider another example:

#include<stdio.h>
void main()
{
int x;
printf("Enter an integer:");
scanf("%d",&x);
if(x<0)
printf("The value is negative\n");
else if(x=0)
printf("The value is zero\n");
else
printf("The value is positive\n");


in this example the if_else_if construct is used which we can call as a nested if_else structure.The nested if_else structure is used to perform some operations based on choices.Consider a simple arithmetic problem in which add, subtract, multiply and divide operations are to be carried out depending on the choice.The options may be displayed.The program can be written in two ways:
using simple if:

#include<stdio.h>
void main()
{
int a,b,c,choice;
scanf("%d%d",&a,&b);       /*b is not zero*/
printf("1.addition\n");           /* option 1 */
printf("2.subtraction\n");      /* option 2 */  
printf("3.multiplication\n");   /* option 3 */
printf("4.division\n");           /* option 4 */
scanf("%d",&choice);
if(choice= =1)
c=a+b;
if(choice= =2)
c=a-b;
if(choice= =3)
c=a*b;
if(choice= =4)
c=a/b;
printf("The result =%d\n",c);
}  

The above program estimates the value based on the choice and prints the result.The number of comparisons made in the program is 4 irrespective of any choice.It performs comparisons unnecessarily.When (choice==1) is true, it is not necessary to evaluate the other conditions and may be skipped. The use of nested if_else construct will solve this problem.
using nested if_else construct:

  #include<stdio.h>
void main()
{
int a,b,c,choice;
scanf("%d%d",&a,&b);       /*b is not zero*/
printf("1.addition\n");           /* option 1 */
printf("2.subtraction\n");      /* option 2 */  
printf("3.multiplication\n");   /* option 3 */
printf("4.division\n");           /* option 4 */
scanf("%d",&choice);
if(choice= =1)
c=a+b;
else
if(choice= =2)
c=a-b;
else
if(choice= =3)
c=a*b;
else
if(choice= =4)                  /* comparison is optional */
c=a/b;
printf("The result =%d\n",c);
}  

 The above program uses nested if_else construct.if the first condition is true, that is ,(choice = = 1) is true the statement c=a+b; is executed and the statement following the else is skipped.Therefore, if the first condition is true, only one comparison is made and all the other comparison are skipped.Only when the first condition fails the program continues to compare the second condition and it goes on similarly.This program works faster than the previous program.but if choice is 4, both programs have to do four comparisons.

Sunday 30 December 2012

POINTER VARIABLES

The variables in C are classified into ordinary variables and pointer variables.An ordinary variable can take values of its associated type.
eg:
int x;
Here, x is an ordinary variable of type integer and assumes a whole number as its value.
x=10;
A pointer variable is declared as follows:

int *y;

The above declaration is a pointer variable declaration.Here y is a pointer variable whose type is an integer pointer (int*) .
A pointer variable assumes only the address as its value.Each variable takes some locations in the main memory is addressable.
In the above examples,x is an ordinary variables and y is a pointer variable. x is an ordinary integer and y is a pointer to an integer.Hence, we can store the address of x in y.

                     y=&x;

there are only two operators associated with pointers- an address of (&) operator and an indirection(*) operator.Both operators are unary operators.
since x is an integer it occupies two byte in the memory.

Every byte is addressable in main memory. To obtain the address of the variable we have to use the "address of" operator(&).So in the statement y=&x; the address of x is stored into the pointer variable y.Since y is a pointer variable it can assume only an address of a variable .We can say that y points to x.

Assume the value of x is 10.To retrieve the value of x through pointer variable y( since y already points to x), we can use the "indirection" operator(*)That is *y will give the value contained in the location pointed by y.If the value of x is 10 and the pointer variable y is pointing to x then the value of the expression *y is 10.
In the above example,

  •  y represents the address of the variable x (&x)
  • *y represents the value of the variable x (x)

DERIVED DATA TYPES

Long, double,unsigned ,array and pointers are the derived types from the fundamental primitive 
types.A long integer can be declared as follows:

long int i;

or

long  i;

To store a long integer value, four bytes of memory are required.To store the real (float) values more precise, the type double is used.It occupies 8 bytes n the memory.

Unsigned numbers are represented as follows:

unsigned int i;

 unsigned int occupies 2 bytes as normal integers but all the bits are used to store the value.In a regular integer,the most significant bit (the left most bit is a sign bit)

FUNDAMENTAL DATA TYPES

Data is a one of the most commonly used terms in programming.Data can be defined as the raw information input to the computer.Data is differentiated into various types in C.There are three numeric data types that comprise the fundamental or primary data types are: 

  • int,
  • float and
  • char.

they are also called as pre define primitives associated with C compiler.The C compiler knws about these  types and the operations that can be performed on the values of these types.The following are the declaration statements of variables of different types:

  • int x;
  • float f;
  • char ch;

 We know already that an integer is a whole number, a float is areal number and a character is represented within single quotes.

eg:
1    is an integer (whole number)
1.0 is areal number (floating point number)
'1'  is a character constant
"1" is a string literal

The data types associated with a string literal is char*(character pointer )
An integer requires 2 bytes of memory to store its value, a float requires 4 bytes of memory and a character requires 1 byte of memory

IDENTIFIERS

Identifiers are the names that are to be given to the variables, functions, data types and labels in a program. the names  of a variable can consist of alphabets (letters)and numbers. Other characters are not allowed in the name of variable.An underscore character can be used as a valid character in the variable name.The variable name starts with an alphabet and its length may vary from one character to 32 characters.The first character in a variable's name should be an alphabet. ie..,a number is not allowed as a first character in the variable name.The valid variable names are:
             
                 x
                 length
                 x_value
                 y_value
                 a123

Keywords (which have special meaning in C) cannot be used as identifiers.

STRING LITERAL

A string literal or a string constant is a sequence of characters from the system's character set, 
enclosed in double quotes.By default ,the null character '\0' is assumed as the last character in a 
string literal. To have a double quotes itself as a character in the string constant, an escape 
sequence '\'' is used.

"hello" is a valid string literal.The actual number of characters in this string literal is 6 including 
the null character at the last.The null character is invisible here.Six bytes are required to store this 
string in memory.However, the physical length of the string is 5 characters.

CHARACTER CONSTANT

A character is a letter, numeral or special symbol, which can be handled by the computer 
system.These available symbols define the system's character set.Enclosing a single character 
from the system's character set within single quotation marks forms a character constant. The 
characters used in C language are grouped into three classes .

  • Alphabetic characters (a,b,c,....z A,B,C,......Z)
  • Numeric characters (0 through 9)
  • Special characters (+ - * / % # = ,=.=' " () [] : )

eg:

'1'.'a','+', and '-' are the valid character constants.
 since two single quotes are used to represent the character constant, how do we represent the 
single quote itself as a character constant? It is not possible to represent a single quote character 
enclosed between two single quotes, that is, the representation ''' is invalid.
An escape sequence maybe used to represent a single quote as a  character constant. Character 
combinations consisting of a backslash \ followed by a letter are called escape sequences.

'\'' is a valid single quote character constant .
similarly some non printable character are represented using escape sequence characters.
eg:
'\a'   bell(beep)
'\b'   backspace 
'\f'    forum feed
'\r'    carriage return
'\n'   newline 
'\0'   null character
'\t'    gap

To represent the backslash itself as a character, two backslashes are used('\\')

FLOATING POINT CONSTANT

A floating point constant is a single real number.It includes integer portion, a decimal point, 
fractional point and a exponent.While representing a floating point constant, either the digits 
before the decimal point (the integer portion) or the digits after the decimal point (the fractional 
portion ) can be omitted but not both.The decimal point can be omitted if an exponent is 
included.An exponent is represented in powers of 10 in decimal system.

eg:

12.34 is a valid floating point (real) constant.It can be represented in exponent form as follows:

      1.234E1 -> 1.234*10^1 -> 12.34
      1234E2 -> 1234*10^(-2) -> 12.34
      0.1234e2 -> 0.1234*10^2 -> 12.34

 The letter E or e is used to represent the floating point constant in exponent form.

Saturday 29 December 2012

INTEGER CONSTANT

An integer constant is a decimal number (base 10) that represents an integer value (the whole 
number ).It comprises of the digits 0 to 9.If an integer constant begins with the letter 0x or 0X, it is 
a hexadecimal(base 16) constant.If it begins with 0 then it is an octal (base 8) constant. Otherwise 
it is assumed to be decimal.

  • 64, 73,and 387 are decimal constants 
  • 0x1C, 0xAB, and 0x23 are hexadecimal constants 
  • 032, 065, 064 are octal constants


Integer constants are positive unless they are preceded by a minus sign and hence -16 is also a 
valid integer constant.Special characters are not allowed in an integer constants.The constants 
2,654 is an invalid integer constant because it contains the special character.

CONSTANTS

A constant is a numeric type or non numeric type.It can be a number, character or a character 
string that can be used as a value  in a program.As the name implies, the value of a constant 
cannot be modified. A constant is immutable.Numeric data is primarily made up of numbers and 
can include decimal points.non numeric data may be composed of numbers,letters,blanks and any 
special characters supported by the system. In other words, non numeric data consists of 
alphanumeric characters,A non numeric data can be called as a literal.Constant are characterized 
by having a value and type.

Numeric constant of three types :

  • integer constant,
  • floating_point constant,
  • character constant. 

ARRANGING THE NUMBER IN DESCENDING ORDER USING ARRAY

#include<stdio.h>
#include<conio.h>
void main()
{
int a[10],i,j,n,temp;
clrscr();
printf("Enter the number of elements ");
scanf("%d",&n);
printf("Enter the number one by one ");
for (i=0;i<n;i++)
scanf("%d",&a[i]);
for(i=0;i<n;i++)
{
for(i=0;i<n;i++)
{
if(a[i]>a[j])
{
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
}
printf("Descending order:\n");
for(i=0;i<n;i++)
printf("%d\n",a[i]);
getch();
}

FINDING THE STRING IS PALINDROME OR NOT

#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<conio.h>
void main()
{
char st[50], p[50];
clrscr();
printf("Enter the string:");
scanf("%s",st);
strcpy(p,st);
strrev(p);
if(strcmp(p,st)= =0)
printf("\n\n The given string is palindrome");
else
printf("\n\n The given string is not palindrome");
getch();
}

FINDING A PERFECT NUMBER

A Perfect number is a number that is the sum of all divisors except itself  six is a perfect number 

since the sum of divisors of except itself is 1+2+3=6

#include<stdio.h>
#include<conio.h>
void main()
{
int num,div,i,u,sum=0,r;
clrscr();
printf("Enter any number:");
scanf("%d",num);
i=1;
while(i<num)
{
div=num%i;
r=num%i;
if(r==0)
{
sum=sum+i;
printf("\n\n The divisible number:%d",i);
}
i=i+1;
}
printf("\n\n The sum is%d \n ",sum);
if(sum= =num)
printf("\n Hence%d is a perfect number",num);
else
printf("\n Hence %d is not a perfect number",num);
getch();
}

Friday 28 December 2012

CHANGING BINARY NUMBER TO DECIMAL NUMBER USING C PROGRAM

#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
int n,d,i;
d=0;
i=0;
clrscr();
printf("Enter any number:");
scanf("%d",&n);
while(n!=0)
{
d=d+(n%10)*pow(2,i);
n=n/10;
i=i+1;
}
printf("\n\n The decimal number is %d",d);
getch();
}

ADAM NUMBER

An Adam number is the one which satisfies the following the reverse of the square of the number 

is the square of reverse of that number.That is if the number is 12 the 12^2=144, the reverse is 

441 which is 21^2.

#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
int r,n,m,p,rev,a,c,i,z;
r=0;
clrscr();
printf("Enter any number between 10 to 100:");
scanf("%d",&z);
n=z;
c=n*n;
while(n!=0)
{
m=n%10;
r=r*10+n;
n=n/10;
}
printf("\n\n The square of %d\s\t%d ",z,c);

printf("\n\n The reverse of %d\s\t%d ",z,r);
p=r*r;
printf("\n\n The square of%d\s\t%d",r,p);
while(c!=0)
{
a=c%10;
rev=rev*10+a;
c=c/10;
}
if(rev==p)
printf("\n\n Thus %d is an Adam number",z);
else
printf("\n\n Thus %d is  Not an Adam number",z);
getch();
}

COUNTING NUMBER OF VOWELS IN A STRING

#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
int i, len, v;
char s[20];
clrscr();
printf("Enter a string: ");
scan f("%s",s);
len=strlen(s);
v=0;
for(i=0;i<len;i++)
{
if(s[i]= ='a'||s[i]= ='e'||s[i]= ='i'||s[i]= ='o'||s[i]= ='u')
v=v+1;
}
printf("Number of vowels in a string:%d",v);
getch();
}

FIBONACCI SERIES

#include<stdio.h>
#include<conio.h>
void main()
{
int i, n;
int a=-1;
int b=1;
int c=0;
clrscr();
printf("Enter the number of terms to generate fibonacci series:");
scanf("%d",&n);
for(i=0;i<n;i++)
{
c=a+b;
a=b;
b=c;
printf("%d\n",c);
}
getch();
}

ASCII TABLE USING C PROGRAM


#include<stdio.h>
#include<conio.h>
void main()
{
int i;
clrscr();
printf("The ASCII table is as follows ..............\n");
for(i=0;i<256;i++)
{
printf("%d\t%c\n",i,i);
if(i!=0&&i%21 == 0)
getch();
}
}

PROGRAM TERMINATION



                The termination of the program may happen in one of the following ways,
                Normal termination,
·         by calling return explicitly from the main(),
·         by reaching the end of main() (returns with implicit value 0),
·         by calling exit(),

           Abnormal termination,
·         by calling abort(),
·         by the occurrence of exception condition at runtime ,
·         by raising signals. 

SOURCE FILES


Source files are of two types:
  •  interface source files and
  •  implementation source files. 

     The interface source files are normally referred to as header files normally have .h extension and implementation files have .c extension.
                The interface files contain the function prototypes, variable declarations, structure/union definitions etc.
                The implementation source files contain the information like function definitions, other definitions and the information needed to generate the executable file, allocate and initialize data.     
                The standard header files are examples for the interface files and the code is available as .lib files and are linked at link-time by the linker to generate the .exe file.  It should be noted that only the code for the functions used in the program gets into the .exe file even though many more functions are available in the header files.

FUTURE OF C LANGUAGE


Although the C may be a base for successful object oriented extensions like C++ and Java, C still continues to remain and be used with same qualities as ever. C is still a preferable language to write short efficient low-level code that interacts with the hardware and OS. The analogy may be the following one.

The old C programmers sometimes used assembly language for doing jobs that are tedious or not 

possible to do in C. In future, the programmers in other programming languages may do the same.


 They will write the code in their favorite language and for low-level routines and efficiency they


 will code in C using it as an assembly language. 

ANSI C STANDARD


                Although K& R C had a rich set of features it was the initial version and C had a lot to grow. The [Kernighan and Ritchie 1978] was the reference manual for both the programmers and compiler writers for almost a decade. Since it is not meant for compiler writers, it left lot of ambiguity in its interpretation and many of the constructs were not clear. One such example is the list of library functions. Nothing significant is said about the header files in the [Kernighan and Ritchie 1978] and so each implementation had their own set of library functions. The compiler vendors had different interpretations and added more features (language extensions) of their own. This created many inconsistencies between the programs written for various compilers and lot of portability and efficiency problems cropped up.
To overcome the problem of inconsistency and standardize the available language features ANSI formed a committee called X3J11. Its primary aim was to make “an unambiguous and machine-independent definition of C” while still retaining the spirit of C. The committee made a research and submitted a document and that was the birth of ANSI C standard. Soon the ISO committee adopted the same standard with very little modifications and so it became an international standard. It came to be called as ANSI/ISO C standard or more popularly as just ANSI C standard.
                Even experienced C programmers also doesn’t know much about ANSI standard except what they frequently read or hear about what the standard says. When they get curious enough to go through the ANSI C document, they stumble a little to understand the document. The document is hard to understand by the programmers because it is meant for compiler writers and vendors ensures accuracy and describes the C language precisely. So the language used in the document is jocularly called as ‘standardese’. For example to describe side effects, the standard uses the idea of ‘sequence-points’ that may help confusing the reader more. L-value is not simply the ‘LHS (to =) value’. It is more properly a "locator value" designating an object.
            ANSI standard is not a panacea for all problems. To give an example, ANSI C widened the difference between the C used as a ‘high-level language’ and as ‘portable assembly language’. The original [Kernighan and Ritchie 1978] is more preferred even now by the various language compilers to generate C as their target language. Because it is less-typed than ANSI C. To give another example, many think ‘sequence-points’ fully describe side-effects and the belief that knowing its mechanism will help to fully understand side-effects. This is a false notion about sequence-points of [ANSI C 1989]. Sequence points doesn’t help fully understand side-effects.

A BRIEF HISTORY OF C


C language is the member of ALGOL-60 based languages. As I have already said, C is neither a language that is designed from scratch nor had perfect design and contained many flaws.
CPL (Combined programming language) was a language designed but never implemented. Later BCPL (Basic CPL) came as the implementation language for CPL by Martin Richards. It was refined to language named as B by Ken Thompson in 1970 for the DEC PDP-7. It was written for implementing UNIX system. Later Dennis M. Ritche added types to the language and made changes to B to create the language what we have as C language.

C derives a lot from both BCPL and B languages and was for use with UNIX on DEC PDP-11 computers. The array and pointer constructs come from these two languages. Nearly all of the operators in B is supported in C. Both BCPL and B were type-less languages. The major modification in C was addition of types. [Ritchie 1978] says that the major advance of C over the languages B and BCPL was its typing structure. “The type-less nature of B and BCPL had seemed to promise a great simplification in the implementation, understanding and use of these languages… (but) it seemed inappropriate, for purely technological reasons, to the available hardware”. It derives some ideas from Algol-68 also.

Saturday 22 December 2012

A C PROGRAM TO PRINT MULTIPLICATION TABLE


main()
{
int x,n,z;
for(x=1;x<=3;x++)
{
printf("\n Multiplication table for%d:",x);
for(n=1;n<=10;n++)
{
z=n*x;
printf("\n%d*%d=%d",x,n,z);
}
getch();
}
}

  • By above program you can print so many tables as your need.
  • In this program, x is multiplier
  •                            n is multiplicand
  •                            z is product.
  • It is the nested for loop program, the first for loop is used to determine the multipliers which the user requires.second for loop is used to determine the multiplicand.
  • z=n*z    in this statement the multiplicand and the multiplier are multiplied and then the value is assigned to the product(Z).

SQUARING AN INTEGER


main()
{
int i,square,;
clrscr();
printf("Number \t square(x)\n\n");
for(i=1;i<=8;i++)
printf("%d\t%d\n",i,i*i);
getch();
}

Friday 21 December 2012

FINDING THE CASE OF THE GIVEN INPUT


 main()
{
int input_char;
printf("\n Enter character:");
input_char=getchar();
if(input_char==EOF)
{
printf("End of file encountered \n");
}
else if(input_char>='a'&& input_char<='z')
{
printf("Lowercase character\n");
}
else if(input_char>='A'&& input_char<='Z')
{
printf("uppercase character \n");
}
else if(input_char>=0 && input_char<=9)
{
printf("Digit \n");
}
}

DATA TYPES AND THEIR RANGE


                                                                                                     2^(X-1)  to  2^(x-1)-1
TYPE
LENGTH
RANGE
Unsigned char
8 bits-> 1 byte
0 to 255
char
8 bits-> 1 byte
-128 to 127
enum
16 bits->2 byte
-32,768 to 32,767
Unsigned int
16 bits-> 2byte
0 to 65,535
Short int
16 bits-> 2 byte
-32,768 to 32,767
int
16 bits-> 2 byte
-32,768 to 32,767
Unsigned long
32 bits->4 byte
0 to 4,294,967,295
long
32 bits->4 byte
-2,147,483,648 to 2,147,483,647
float
32 bits-> 4 byte
3.4*(10**-38) to 3.4*(10**+38)
double
64 bits-> 8 byte
1.7*(10**-308) to 1.7*(10**+308)
Long double
80 bits-> 10 byte
3.4*(10**-4932) to 1.1*(10**+4932)



                                                                                       x->bits

FINDING LEAP YEAR, SWAP OF TWO NUMBERS WITHOUT TEMP VARIABLE


The program which displays the string which you given as input

main()
{
char line[80];
clrscr();
printf("Enter the phrase:");
scanf("%[ABCDEFGHIJKLMNOPQRSTUVWXYZ]",line);
scanf("%[abcdefghijklmnopqrstuvwxyz]",line);
printf("\n The phrase you had typed in was :%s",line);
getch();

o/p
Enter the phrase:hello
The phrase you had typed in was:hello 


The program to find leap year


main()
{
int month,day,year, feb_max;
clrscr();
printf("\n Enter month and year:");
scanf("%d%d",&month,&year);
if(month==2)
{
printf("\n Month is February");
feb_max=28;
if((year%4)==0)
{
printf("\n Leap year");
feb_max=29;
}
printf("\n Max days in this month:%d", feb_max);
}
getch();
}


How the pre-increment and post-increment works


main()
{
int i;
clrscr();
i=3;
printf("i=%d\n",i);
printf("i=%d\n",++i);
printf("i=%d\n",i);
printf("i=%d\n",i++);
printf("i=%d\n",i);
getch();
}
o/p
i=3
i=4
i=4
i=4
i=5


Swap of two numbers without temp variable


main()
{
int a,b;
clrscr();
a=5;
b=10;
a=a+b;
b=a-b;
a=a-b;
printf("%d\n%d\n",a,b);
getch();
}

CHANGING UPPERCASE CHARACTER TO LOWERCASE CHARACTER

program displays a character entered in the uppercase in the lowercase
main()
{
int c;
printf("Enter an uppercase letter:");
c=getchar();
printf("Lowercase=");
putchar(c+32);
}

HOW TO DENOTE END OF FILE

How CTRL+Z can be used to denote end of file:
main()

{
int c;
print("Enter the character (CTRL+Z to end):");
c=getchar();
if(c!=EOF)
printf("End of file not encountered ");

o/p:
Enter the character (CTRL+Z to end):d
End of file not encountered.

Thursday 20 December 2012

INTRODUCTION


Dennis ritchie at AT & T bell laboratories developed the C language three decades ago.C language is the general purpose language .it is efficient, flexible and portable language.c has wide diversity of operators and commands.c has been effectively utilized for the development of system software like, operating systems, compilers, text processor, and database management systems.C is well suited for developing applications programs too.c language is composed of the following basic types of elements:

  •  constants,
  • identifiers,
  • operators,
  • punctuation and
  •  keywords.


A SAMPLE C PROGRAM:

c programs are made up of functions.A program cannot be written without function.A function may be pre-defined or user-defined.The C program code is given below:

#include<stdio.h>   /*preprocessor statement*/
main()                       /*function header  statement*/ 
{
printf("hello");        /*function call statement*/   
}

here, main() is calling function and printf() is the called function.
After the execution the program will display the message"hello".main() function is the user defined one.When the C program runs the control is transferred to this function.
This is called as the program's entry point.The program has two function, one is the user-defined which is main()function and the other one is pre-defined which is printf()function
The first line in the program #include<stdio.h> is a preprocessor statement.#include is a preprocessor directive .Preprocessor is a software program that will expand the source code
while it is compiled.Stdio.h (standard input and output header file, the content of the pre-defined output and input function like printf() and scanf() etc..., 
The C compiler is able to recognize the pre-defined functions only because of their  declaration in the appropriate header files.

Statements
Each and every line of a C program can be considered as a statement. There are four types of 
statements.They are 

  • preprocessor statement,
  • function header statement,
  • declaration statement,
  • executable statement.


#include<stdio.h> -> preprocessor statement
main()                       ->function header statement 
{
int a,b,c;                   ->variable declaration statement 
int sub(int,int);       ->function declaration statement     
a=17;                         ->executable statement
}  

Input and output statements
As we have seen already,the function printf() is used to display the results on the standard 
output(screen).Actually,the first parameter of the printf() function is a string which is used to control the output and hence it can be called as"control string".This parameter is used to format the output for display and hence we also call  it as a "formatting string".
for example:
To print a value of integer datatype
int x; /*variable xis declared as integer*/
x=17;
printf("%d",x);
 In the above example,'%d' is used as a formatting character within the control string of printf() function to display the value of an integer.The control string of printf() function can take three types of characters.They are,

  • ordinary characters,
  • formatting characters,
  • escape sequence characters.


In case of printf("hello"); statement, the control string has ordinary characters only

FORMATTING SPECIFICATIONS
FORMATTING CHARACTERS DATA TYPE
%d                                 Int
%f                                   Float
%c                                 Char
%s                                 Char[]
%ld                                 Long int
%lf                                 Long float
ESCAPE SEQUENCE CHARACTERS

ESCAPE SEQUENCE NON-GRAPHIC CHARACTER
\a                 Bell
\b                 Back space
\n                 New line/ line feed
\t                 Horizontal tab
\v                 Vertical tab
\\                 Back slash
\’ or \”         Single/ double quotes
\o                 Octal number
\x                 Hexa decimal number
\0                 Null
\f                 Form feed
\r                 Carriage return


Input (scanf())
To read a value from the keyboard(standard input),the function scanf() is used.The protype of scanf() is similar to the protype of the printf().It can take the variable number of the parameter.To read a value of an integer variable is given below:

int x;
scanf("%d",&x);

while the scanf() function is being executed,the system waits for the user's input.The user has to provide data through keyboard .The data will be placed in the location of x only after the "enter " key is pressed on the keyboard The second parameter of the above scanf() function &x,which represents the address of x.& is the address of operator and when it is being used with a variable,it provides the address of the variable.