Basic Structure of a C Program
Structure of C program
It is necessary to be aware of proper structure flow of programming language you are writing code in. Not following proper structure of program may lead to error. Structure of a language gives a basic idea of the order of sections in a program. Here we will discuss the different section of structure.
Sample code
Let’s take an example for exploring this section. Following is the code in C language to calculate the area of circle whose radius is 5.
Run
#include<stdio.h> #define PI 3.1416 float area (float r); int main(void) { //Example of variables float r = 5; printf("Area: %.2f",area(r)); // This statement will print two digit after the point return 0; } //Example of function float area(float r) { //example of statements & Expression return PI * r * r; }
Output
Area: 78.54
Prime Course Trailer
Related Banners
Get PrepInsta Prime & get Access to all 200+ courses offered by PrepInsta in One Subscription
Get over 200+ course One Subscription
Courses like AI/ML, Cloud Computing, Ethical Hacking, C, C++, Java, Python, DSA (All Languages), Competitive Coding (All Languages), TCS, Infosys, Wipro, Amazon, DBMS, SQL and others
printf(“Area: %.2f”,area(r));
Explain please?
basically printf is for output so in this case (.2) will print only two number after the value of AREA suppose we wrote (.4) then it will print upto 4 number after the value of AREA
so our output woul;d be like this Area:78.54.
the value of r is 5 so it would be multiplied with PI*R*R.