محاضرة 2
User Input (cin) and Arithmetic Operations
استقبال مدخلات من المستخدم والعمليات الحسابية الأساسية
ملخص المحاضرة
📜 Lecture 2: Input, Output, and Arithmetic
This lecture covers how to get input from the user (cin) and perform basic math operations.
Key Concepts
- Output Formatting:
\t: Adds a tab to the output for spacing. Example:cout << "Hello \t world";.\norendl: Adds a new line.
- User Input:
cin >> variableName;: The standard input command (see-in).- The
>>operator is the "stream extraction" operator. - You can chain inputs:
cin >> x >> y;reads two values from the user intoxandy.
- Variables Example: The lecture shows how to declare, assign, and print various data types.
bool sucess=true;will output1when printed.
- Arithmetic Operations:
+(Addition),-(Subtraction),*(Multiplication).
- Division (
/):- Integer Division: If you divide two
intvariables, the result is also anint. The decimal part is truncated (cut off).- Example:
int z = 5 / 3;results inzbeing1.
- Example:
- Floating-Point Division: To get a decimal result, at least one of the numbers must be a
floatordouble.- Example:
float z = 5.0 / 3;results inzbeing1.66667.
- Example:
- Integer Division: If you divide two
- Modulus (
%):- Finds the remainder of a division.
- Example:
7 % 3is1. - Modulus Rules:
number % same_number = 0(e.g.,5 % 5 = 0).small % big = small(e.g.,4 % 5 = 4).big % small = remainder(e.g.,7 % 6 = 1).
محتويات المحاضرة
اختبر فهمك للمحاضرة
تصحيح فوري بالذكاء الاصطناعي