A "C" program contains executable statements. Compilers help translate executable statements into machine language.
When a user runs a program, he/she executes machine language statements through the compiler.
The types of executable statements in C language are as follows:
Storing values into memory is called "input operation".
After a calculation is performed, the results are stored in memory and can be displayed to the user through an "output operation".
All input/output operations are performed using input/output functions.
The most common I/O functions are provided through the preprocessing directive #include
The most commonly used I/O functions are printf() and scanf().
printf() function
The syntax is as follows:
printf("format string", print list);
For example,
printf ("average of 3 numbers = %f",avg);
printf() displays the value of its format string
scanf() function
The syntax is as follows:
scanf ("format string", input list);
For example, scanf("%d %f",&a,&b);
scanf() copies data typed on the keyboard to memory during program execution.
There is an ampersand in front of the input list.
The assignment statement stores a value in a variable and is used to perform arithmetic operations in a program.
Syntax
The syntax is as follows −
variable=expression
For example,
Following is the C program for computing an average of three numbers −
Live Demo
#include<stdio.h> #include<stdio.h> main(){ int a,b,c,d; float avg; printf("Enter values for a,b,c:</p><p>"); scanf("%d%d%d",&a,&b,&c);// The scanf ( ) copies data typed at the keyboard into //memory during program execution. d=a+b+c; //assignment stmt avg=d/3; printf("Average avg=%f",avg); }
You will see the following output −
Enter values for a,b,c:2 3 4 Average avg=3.000000
The above is the detailed content of In C language, executable statements refer to code statements that can be executed by the computer.. For more information, please follow other related articles on the PHP Chinese website!