120 likes | 223 Views
Programming Paradigms. Lecturer Hamza Azeem. Lecture 3. C Building Blocks - II. Example of Scanf (). int main() { long years, days; printf ( “Please type your age in years: "); scanf ( “%ld", &years); days = years * 365; printf ( "You are %ld days old", days); }. Output of Example.
E N D
Programming Paradigms LecturerHamza Azeem
Lecture 3 C Building Blocks - II
Example of Scanf() • int main() • { • long years, days; • printf( “Please type your age in years: "); • scanf( “%ld", &years); • days = years * 365; • printf( "You are %ld days old", days); • }
Output of Example Please type your age in years: 25 You are 9125 days old
Address Operator (&) • Scanf() function requires the address of the variable where to put the value obtained. Rather than the variable itself. • The & operator provides the address of the memory location where a variable is stored
GETCH() Function • Getch() is only used for taking character input • It only takes one character • Once types the character can’t be erased • No need for pressing enter key
Example of GETCH() • int main() • { • char ch; • printf("Type any character:"); • ch=getch(); • printf("\n The character you typed: %c",ch); • }
How to display variables on Output ? • C Language uses 4 types of Arithmetic Operators common in most programming. + Addition - Subtraction * Multiplication / Division % Remainder
Remainder Operator • It is also called Modulo Operator • Example19 % 5 = 4