Download as pdf or txt
Download as pdf or txt
You are on page 1of 15

CODING FOR BEGINNERS

INTRODUCTION TO VARIABLES AND DATATYPES


PRINTF() FUNCTION

• It is a pre-defined function from header file stdio.h


• It is used to print/write anything on output screen (console)
• The function name printf() should be written in lower case only
SCANF() FUNCTION

• It is a pre-defined function from header file stdio.h


• It is used to read value from console (taking input from user)
• The function name scanf() should be written in lower case only
WHAT IS A VARIABLE?

• A variable is a data name that may be used to store a data value


• Variable may take different values at different time of execution
• Variable name should be meaningful
NAMING CONVENTION FOR A VARIABLE

• Must begin with a letter


• Length should not be more than 8 characters
• Uppercase and lowercase are significant
• Name Amount, amount and AMOUNT are different
• It should not be a keyword
• White space are not allowed
• It should be combination of letters, numbers and _
KEY WORDS

• Words that have special meaning to the C/C++ compiler


• Their meaning can not be changed
• Written in lower case only
KEY WORDS

auto double int struct

break else long switch

case enum register typedef

char extern return union

const float short unsigned

continue for signed void

default goto sizeof volatile

do if static while
Int main()
{
int principal, rate, nyears, interest;
principal = 1000;
rate = 8;
nyears = 5;
interest = ( principal * rate * nyears ) / 100;
printf(“ Simple interest of %d rupees for %d years with %d rate of interest is %d.”, principal,
nyears, rate, interest);
}
DATA TYPES

• The data type in C defines the amount of storage allocated to variables ,the
values that they can accept ,and the operation that can be performed on
those variables
• C is rich in data types.
• The verity of data type allow the programmer to select appropriate data
type to satisfy the need of application
CLASSES OF DATA TYPES

• Primary/ Primitive Data Type


• Derived Data Type
• User Defined Data Type
PRIMARY DATA TYPES

• All C compiler support five type of fundamental data type


1. char: The most basic data type in C. It stores a single character and requires a single
byte of memory in almost all compilers.
2. int: As the name suggests, an int variable is used to store an integer.
3. float: It is used to store decimal numbers (numbers with floating point value) with single
precision.
4. double: It is used to store decimal numbers (numbers with floating point value) with
double precision.
5. void: It used for function with no return value
DATA TYPES

Data Type Memory (bytes) Range Format Specifier

int 2 -32,768 to 32,767 %d

char 1 -128 to 127 %c

float 4 3.4E – 34 to 3.4E + %f


34

double 8 1.7E – 308 to 1.7E + %lf


38
PRACTICAL ASSIGNMENT

• Perform practical to calculate the area and circumference of a circle.


• Perform practical to find the Simple Interest.
• Perform practical to swap of two numbers without using third variable.
• Perform practical to calculate the sum of 5 subject marks and. Also find and display
the total and percentage.
• Perform practical to find gross salary of an employee. Calculate on the basis of
basic_salary, DA(30%), HRA(5%) and PF(10%) and calculate gross_salary and
display the same.
INSTRUCTIONS FOR ASSIGNMENT

• Do all five programs given as assignment


• Mail all five programs to my email id
• Subject of the mail should be [roll number] [your name] Practical Assignment 1
• Send it before 2nd October, 2021
REFERENCE BOOK

• Programming In Ansi C - E Balagurusamy - Google Books

You might also like