Chap (Ter 01 - C Language Tutorial For Beginners - Getting Started (Variabls & Constants) - Shared
Chap (Ter 01 - C Language Tutorial For Beginners - Getting Started (Variabls & Constants) - Shared
By
Mohammad Fazlur Rahman
EPS, Bhopal
The C
Characters
Characters…
C uses all sort of characters in computer keyboard.
Alphabets:
“A to Z” and “a to z”
Digits:
0 to 9
Special Characters:
~`!@#%^&*()_-+=|\{}[]:;“‘<>
,?/$
The C
constants and variables
Constants…
C language has data and it can be constants and variables.
C Constants
Primary Secondary
Constant Constant
Any
Question…
Rules….
for
constructing
variable names
Variable names…
Any
Question
Work out
Example
Work out examples…
Do a simple programming in C
Language to calculate a simple interest
for a given principal amount at a given
rate for a given amount of time.
Convert the same programme for taking
inputs from outside.
Work out examples…
// Calculation of simple interest
// Author: Put your name here.
# include <stdio.h>
Int main ()
{
int p, n; // defining
float r, si; // defining
p = 1000; // assigning
n = 3; // assigning
r = 8.5; // assigning
si = p * n * r/100; // formula for simple interest
printf(“Simple Interest calculated is = %f\n”,si);
return(0);
}
Recommended format of C programming…
• Each instruction in a C program is written as a separate
statement.
• The statements in a program must appear in the same order
in which we wish them to be executed.
• Blank spaces may be inserted between two words to improve
the readability of the statement.
• All statements should be in lower case letters.
• C has no specific rules for the position at which a statement
is to be written in a given line. That’s why it is often called a
free-form language.
• Every C statement must end with a semicolon (;), thus “;”
acts as a statement terminator.
Comments on
Example
Work out examples… Form of a C
Programme
What is main()
…?
Variables and
Salient Features of the C Programming
their usage…
Do a simple programming in C
Language to calculate a simple interest
for a given principal amount at a given
rate for a given amount of time.
Convert the same programme for taking
inputs from outside.
Work out examples…
While receiving inputs from outside, we use the command
“scanf()” and store the data in appropriate variables.
int main()
{
int a, b, c;
printf(“Please enter the number of people…\n”);
scanf(“%d”,&a);
printf(“Total number of people is : %d\n”,a);
}
Work out examples…
The entries must be separated by a blank (Spacebar), a
tab (tab key) or a new line (Enter key).
int main()
{
int a, b, c;
printf(“Please enter three numbers…\n”);
scanf(“%d %d %d”,&a, &b, &c);
printf(“The numbers are: %d %d %d\n”,a,b,c);
}
Summary
of the
Learning
Summary…
• Constant is an entity whose value remains fixed.
• Variable can change during course of execution.
• Keywords are special words whose meaning is known to the
Compiler.
• There are certain rules that must be followed while building
constants or variables.
• The three primary constants and variable types in C are
integer, float and character.
Summary…
• We should not use a keyword as a variable name.
• Comments should be used to indicate the purpose of the
program or statements in a program.
• Comments can be single line or multi-line.
• Input/output in C can be achieved using scanf( ) and printf( )
functions.