Download presentation
Presentation is loading. Please wait.
1
Programming Fundamental-1
Instructor Name: Muhammad Safyan Lecture-3
2
Cout<< (Statement)
cout << x; cout << x + x; cout << "x="; cout << "x = " << x; cout << x + y << " = " << y + x; // cout << "x + y = " << x + y;
3
Cin>> (Statement)
known as input stream in C++. cin takes data from keyboard and sends it to the memory variable. For the moment it is a screen of the monitor . cin >> x; cin >> x >> y;
4
Escape Sequence Character
Notes: Escape Sequence Character Escape Sequence are Non-printable and control characters to control the output, represented by a so-called escape sequence, which begins with a back-slash (\) Escape Sequence Description \n New-line (or Line-feed) \r Carriage-return \t Tab \" Double-quote (needed to include " in double-quoted string) \' Single-quote \\ Back-slash (to resolve ambiguity) \b backspace Cout<<“\n”; Cout<<x<<“\n”<<y;
5
Escape Sequence Character
Notes: Escape Sequence Character Cout<<“\n”; Cout<<x<<“\n”<<y; Endl (end of line) cout << "*\n**\n***\n****\n*****" << endl;
6
Quadratic Equation In algebra In C y = ax2 + bx + c
y = a*x*x + b*x + c
7
Discriminant b2 - 4ac 2a = b*b - 4*a*c /2 *a Incorrect answer Solution
= (b*b - 4*a*c) /(2 *a) Correct answer
8
Interesting Problem Given a four-digit integer, separate and print the digits on the screen
9
Analysis Number = 1234 Take the remainder of the above number after dividing by 10 Eg 1234 / 10 gives remainder 4 1234 % 10 = 4 Remove last digit 1234/10 = 123.4 123 (Truncation due to Integer Division) 123 %10 gives 3 123/10 = 12.3 12 (Truncation due to Integer Division) 12 % 10 gives remainder 2 12/10 = 1.2 1 (Truncation due to Integer Division) Final digit remains
10
Code #include <iostream.h> main ( ) { int number; int digit;
cout << “Please enter a 4 digit integer : ”; cin >> number; digit = number %10; cout <<“The digit is: “ << digit << ‘\n’; // first digit; and then << ‘\n’ number = number / 10; digit = number % 10; cout <<“The digit is: “ << digit << ‘\n’; cout <<“The digit is: “ << digit; } write a program that takes radius of a circle from the user and calculates the diameter, ircumference and area of the circle and display the resul
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.