Devang
Page 1
10/15/2008
1) The Basic sections of ‘C’ are explained taking an example:: /* A program to calculate average of 5 nos given by the user */ /*----------Defining of Constants and Inclusion Of Header Files------*/ #include<stdio.h> #define M 10 /*------------Start Of The Main Program---------------------------------*/ main() { /*----------------Declaration of Variables----------------------*/ int i; int sum ; /*-----------------Initialization of Values----------------*/ sum=avg=0; /*---------------Interaction With User and Receiving Required Data----*/ printf(“Please Enter The Values::”\n”); for (i=0; i<=M; i++) { scanf(“%d”, &n); sum=sum+n; } /*---------------Display Of Final Result with The Computation-----------*/ printf(“The Sum of All The Nos is: %d \n The Average of All The 10 Nos is: %d\n”, sum, sum/10); }
Devang
Page 2
10/15/2008
2) The various data types supported in C are basically divided into 4 types: primary or fundamental, user-defined, derived and empty data set. The Primary Data Type are mainly divided into 3 types which are sub-divided into many types like: 1) INTEGER (int): different types of integers are: int, unsigned int, short int, unsigned short int, long int, and unsigned long int 2) Character (char): different types of characters are: signed char, unsigned char 3) Floating Point (float): different types of floats are: float, double, long double An Example Program to Display Various Primary Data Types:: main() { int a; short int c; long int d;
/*------int range : -32,768 to 32,767-------*/ /*------short int range : -127 to 128-------*/ /*------long int range : -2,147,483,648 to 2,147,483,647-------*/
float e; double f;
/*------float range : -3.4E-38 to 3.4E+38-------*/ /*------double range : -1.7E-308 to 1.7E+308 -------*/
char g;
/*------int range : -127 to 128-------*/
a=30007; c=120; d=89654785; e=954651.6216549; f=1.6E; g=’M’; printf (“a=%d\n c=%d \n d=%d \n e=%f \n f=%f \n g=%c\n”, a, b, c, d ,e ,f ,g); RESULT: a=30007 c=120 d=89654785 e=954651.6216549 f=1.6E g=M