Results 1 to 11 of 11
Thread: C++
Hybrid View
-
17th December 2012 12:41 #1
C++
!
C++:
Write a program that reads a positive number and prints out all its divisors.
- , negative number, Error: Negative number.
.
:
Code:#include <iostream> using namespace std; int main() { int i, numb; cout << "Please enter a number" << endl; cin >> numb; cout << "The numbers divisable by " << numb << " are:" << endl; for (i = 1; i <= numb; i++) if (numb % i >= 0) cout << i << endl; else cout << "Error: Negative number.\n"; return 0; }Last edited by Bombera; 17th December 2012 at 13:04.
The Beast
--> | HAF-X | X570 Aorus Ultra | Ryzen 5800X3D @ H100i PRO RGB | 32GB (2x16GB) HyperX Predator DDR4-3600MHz |
| EVGA RTX 3080 ULTRA | 2x1TB Kingston M2 NVMe + 2x1TB Samsung Evo 860 | Corsair RM750i | Dell S2721DGF 165Hz | SteelSeries Arctis 7 | MX518 @ QcK+|
-
17th December 2012 12:53 #2Registered User
Join Date: Oct:2003
Location:
Posts: 4,317
for.
-
17th December 2012 12:56 #3Mire-x
Join Date: Apr:2005
Location: Sofia
Posts: 763
, CODE , . 10- , - , - , . , , , .

, , 1 ( , !, .. true). , . , (numb % i == 0), true i, false (.. else).(10b) || !(10b)
-
17th December 2012 13:27 #4
for (i = 1; i <= numb; i++)
numb < 0, i = 1
numb < 0 .ASRock B550M Pro 4; Ryzen R5 3600; 2x16 GiB G.SKILL Aegis 3200; 1TB Samsung QVO 960 + 3TB Seagate IronWolf; Zalman Z1
-
17th December 2012 13:56 #5, .Code:
if (numb % i >= 0) cout << i << endl;
Laa shay'a waqi'un moutlaq bale kouloun moumkine.
Nulla é reale, tutto é lecito.
-
19th December 2012 01:20 #6
, , , :
Code:#include <iostream> using namespace std; /** Defines the entry of positive numbers only and computes their devisors. */ int custom(int i_1 ,int numb_1) { for (i_1 = 1; i_1 <= numb_1; i_1++) if (numb_1 % i_1 == 0) cout << i_1 << endl; if (numb_1 < 0) cout << "Error! Please enter a positive number" << endl; else if (numb_1 == 0) cout << "Error! You can't divide by zero" << endl; } int main() { int numb, custom1; int i = 1; cout << "Please enter a positive number" << endl; cin >> numb; cout << "The numbers divisable by " << numb << " are:" << endl; custom1 = custom(i, numb); return 0; }The Beast
--> | HAF-X | X570 Aorus Ultra | Ryzen 5800X3D @ H100i PRO RGB | 32GB (2x16GB) HyperX Predator DDR4-3600MHz |
| EVGA RTX 3080 ULTRA | 2x1TB Kingston M2 NVMe + 2x1TB Samsung Evo 860 | Corsair RM750i | Dell S2721DGF 165Hz | SteelSeries Arctis 7 | MX518 @ QcK+|
-
19th December 2012 01:35 #7Mire-x
Join Date: Apr:2005
Location: Sofia
Posts: 763
. i custom(). main(), custom(). i custom() . custom() "numb_1"; "numb", . if(numb_1 < 0)/elseif(numb_1 == 0) for(), . , , - .
(10b) || !(10b)
-
19th December 2012 14:37 #8
int custom(int i_1 ,int numb_1) ... ?
void custom(int i_1 ,int numb_1)
custom1 = custom(i, numb);
custom(i, numb);
0 , - ... ( ) 0 .ASRock B550M Pro 4; Ryzen R5 3600; 2x16 GiB G.SKILL Aegis 3200; 1TB Samsung QVO 960 + 3TB Seagate IronWolf; Zalman Z1




Reply With Quote
Lenovo ThinkPad 15 IdeaPad 15
5th May 2023, 22:16 in