You are on page 1of 9

First program

Standard Input output statemts(I/o)


• scanf( ) :-
• scanf() is used to read information from the standard I/P device.
• Syntax:- scanf(“controlstring”, &variable_names);
Printf(): is used to print information on the standard output device.
Syntax: printf(“control string”, var1,var2……);
Control string / format specifier
Arithmetic Operators
• Integer Arithmetic:
• If both the operands in an arithmetic expression are integers then it is known as integer
arithmetic and the result is an integer.
• Real Arithmetic:
• If both the operands in an arithmetic expression are real operands then it is known as real
arithmetic and the result is real.
• Mixed mode Arithmetic:
• If the operands in an arithmetic expression are of different types then it is known as
mixed mode arithmetic and the result is a real
Arithmetic Operators
• Integer division truncates any fractional part.

• The modulo division operation produces the remainder of an integer


division.

• Modulus operator is not valid for real and mixed mode arithmetic.
Integer Division
• #include<stdio.h> • Out put:
• int main() • 2
• {
• int res;
• res=5/2;
• printf(“%d”,res);
• }
Implicit Conversion
• #include<stdio.h> • Output:
• int main() • 2.000000
• {
• float res;
• res=5/2;
• printf(“%f”,res);
• }
Explicit conversion
• #include<stdio.h> • Output:
• int main() • 2.500000
• {
• float res;
• res=(float)5/2;
• printf(“%f”,res);
• }
Explicit Type casting
In this type of conversion, the programmer can convert one data type to other data type explicitly.
• Syntax: (datatype) (expression)
• Expression can be a constant or a variable
• Ex: y = (int) (a+b)
• double a = 6.5;double b = 6.5
• int result = (int) (a) + (int) (b)
• result = 12 instead of 13.
• int a=10
• float(a)->10.00000

You might also like