4 Introduction To C
4 Introduction To C
programming
Structured programming
Input radius
Area=3.14*radius*radius
Output area
/*Program to compute area of a circle */
#include <stdio.h>
int main()
{
int rad; float area; const pi=3.14; //variable
declaration
printf (“Enter radius”);
scanf (“%d”,&rad); // input radius
area= pi * rad * rad;
printf (“Area is %f”, area);
Main() formats
• All
the statements between the { and } forms the
function body and are the instructions to perform the
given task.
• All
statements in the Declaration and Executable parts
must end with a semicolon (;)
Formats of main()
• main()
• int main()
• void main()
NB:
Int main()
scanf (“%s”,&prdname);
printf(“Enter Quantity”);
scanf (“%f”,&qty);
printf(“Enter Price”);
scanf (“%f”,&prc);
tprice=qty*prc;
}
C Program Tokens
• Identifiers
• Constants
• Variables
• Operators
• Special symbols
Reserved Words
3. Cannot be a Keyword.
• Integer (int)
• Character (char)
• Void
Integer data types
examples
• int count;
• E.g. x=60;
Reading data from the keyboard (scanf())
scanf(“%d”, &marks);
• Example
•x = a * b – c;
• y = b/c * a;
Operator Precedence
• Z=x/y*s+x
• Z=x/(y*(s+t))