Professional Documents
Culture Documents
PR 2
PR 2
02
THEORY:
SCANF():
scanf() is a predefined function in "stdio.h" header file. It can be used to read the input
value from the keyword.
SYNTAX:
scanf("format specifiers",&value1,&value2,.....);
EXAMPLE:
#include<stdio.h>
void main()
{
int a, b, sum;
printf("\nEnter two no: ");
scanf("%d %d", &a, &b);
sum = a + b;
printf("Sum : %d", sum);
getch();
}
CONSTANTS:
C Constants are also like normal variables. But, only difference is, their values can not be
modified by the program once they are defined.
#define LENGTH 10
#define WIDTH 5
#include <stdio.h>
void main() {
int area;
printf("%c", NEWLINE);
getch();
getch();
}
VARIABLE:
A variable definition tells the compiler where and how much storage to create for the
variable. A variable definition specifies a data type and contains a list of one or more
variables of that type as follows,
Page 2 of 4
type variable_list;
Here, type must be a valid C data type including char, w_char, int, float, double, bool, or
any user-defined object; and variable_list may consist of one or more identifier names
separated by commas. Some valid declarations are shown here,
int i, j, k;
char c, ch;
float f, salary;
double d;
The line int i, j, k declares and defines the variables i, j, and k which instruct the compiler
to create variables named i, j and k of type int.
Variables can be initialized (assigned an initial value) in their declaration. The initializer
consists of an equal sign followed by a constant expression as follows,
type variable_name = value;
DATA TYPES:
A programming language is proposed to help programmer to process certain kinds of data
and to provide useful output. The task of data processing is accomplished by executing
series of commands called program. A program usually contains different types of data
types (integer, float, character etc.) and need to store the values being used in the program.
C language is rich of data types. A C programmer has to employ proper data type as per
his requirements.
Page 3 of 4
EXERCISE:
Write a C program
1. To find an area of Circle.
2. To find area of Triangle and Rectangle.
3. To convert the temperature entered by user in Centigrade to Ferenhit.
4. To convert the entered days by user in months.
5. For swapping of two numbers using third variable method and without using third
variable method.
Page 4 of 4