First C Program
It is time to make our first program. we will learn to write the first program in C Language and then try to understand its structure. Let's write a simple and most basic program Hello World in C language.
Program to Display "Hello World"
Algorithm
- start
- write "Hello World"
- end
Flowchart
Program:#include //Pre-processor directive
int main() //main function declaration
{
printf("Hello World"); //to output the string on a display
return 0; //terminating function
}
Explanation
- The program execution begins with the function main().
- The executable statements are enclosed within a block that is marked by ‘{’ and ‘}’.
- The printf() function redirects the output to a standard output, which in most cases is the output on screen.
- Each executable statement is terminated by ‘;’
- The comments are enclosed in ‘/*...*/’
Program using Variables
When we want to process some information, we will save the values in variables. The following program we will define some variables and initialize with values
Algorithm
- start
- a:= 'S'
b:= 10
c:= 25.80
- write a,b,c
- end
.
Flowchart
Program:#include //Pre-processor directive
int main() //main function declaration
{
char a='S'; //Defining variables
int b=10; //initialize with values
float c=25.80;
printf("%c %d %f",a,b,c); // Printing results
return 0; //terminating function
}
Explanation
- For each variable we have to attach some data type. The data type defines the amount of storage allocated to variables, the values that they can accept, and the operations that can be performed on variables
- The ‘%d’ is used as format specifier for the integer. Each data type has a format specifier that defines what type of data will be printed.
Next Topic :Expression