Structure of C Program
# include < header file> // # is pre-processor directive
#define x 5 //symbolic constant
int a, b; //global variable declaration
int fxn(); // function declaration
main() //main function
{
int i,j,k; // local variable declaration
Input statements;
Process;
Output Statements;
}
Example
# include <stdio.h>
void main() { char name[20]; int rollno;
scanf(“%[ ABCDEFGHIJKLMN]”, name); /* The characters(as per case) given in scanf are valid character for input. Like space & other given character, if we give input GAGAN DEEP, the input taken upto GAGAN DEE, P terminate the string*/
printf(“%s ”, name); //whereas in output %s works for a full string
}
Your input may be of : GAGAN DEEP
Output is GAGAN DEE
(Only character other than the given character s can terminate the string.)
Example : WAP to find ASCII value of a character
#include <stdio.h>
#include<conio.h>
void main()
{ char c;
printf(“Enter a character: “);
scanf(“%c”,&c); // Takes a character from user
printf(“ASCII value of %c = %d”,c,c);
getch();
}
Decision Making
C program may require that a logical test be carried out at some particular point within the program. One of several possible actions will then be carried out, depending upon the outcome of the logical test. This is known as branching.
There is also a special kind of branching, called selection, in which one group of statement is selected from several available groups.
C conditional statement allow you to make decision, based upon the result of a condition.
These statement are also known as decision making statement, conditional statement, branching statement or selection statements.
Published by