Create a simple C program and use a comment to identify the five basic structures of the c programming language.
Documentation section: It is expected frm programmers to put comments in between the coding sections so as to understand and get the algorithm idea what the code is doing. A c-program allows to add or insert comments using (//) for single line commenting and (/* */) for multiple lines commenting. The commented lines are not compiled during program compilation.
Link section: Header files (library files) included at the top of the programs are linked using the linker section of C-compiler..
Definition section: #define directive is used tom define MACROS in C-program. MACROS are replaced as it is in the entire C-program..
Global declaration section: The variables that are required globally through out the C-program and various functions are called global variables. Each and every program and function can access these variables.
Local variable declaration: Variables that are declared inside the main function or a function has their scope within their respective function only.
Main function section: Any C-program has primarily two parts: decleration part and executable part. Decleration part consists of variable decleration and executrable part includes the instructions or logic implemented using looping instructions and other commands.
A simple C-program to get the sum of first 10 natural numbers is given below:
//Linker Section
# include<stdio.h>
#include<stdlib.h>
//Macros definition
#define N 10
//Main Part
int main()
{
//Decleration
int n,Sum=0;
//Executable Part
for(n=0;n<+N;n++) Sum = Sum + n;
printf("\n\tSum of first %d Natural Numbers = %d",N,Sum);
return(0);
}
Comments
Leave a comment