Results 1 to 11 of 11

Thread: C++

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    .:OVERLOAd :. cvtmih's Avatar
    Join Date: Dec:2010
    Location: Sofia
    Posts: 652

    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+|

  2. #2
    Registered User
    Join Date: Oct:2003
    Location:
    Posts: 4,317
    for.

  3. #3
    Mire-x
    Join Date: Apr:2005
    Location: Sofia
    Posts: 763
    , CODE , . 10- , - , - , . , , , .

    , , 1 ( , !, .. true). , . , (numb % i == 0), true i, false (.. else).
    (10b) || !(10b)

  4. #4
    Registered User hateras's Avatar
    Join Date: Jan:2011
    Location: Kronos III
    Posts: 1,028
    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

  5. #5
    AMD fan EvilDevil_'s Avatar
    Join Date: Dec:2010
    Location:
    Posts: 1,275
    Code:
    if (numb % i >= 0)
    cout << i << endl;
    , .

    Laa shay'a waqi'un moutlaq bale kouloun moumkine.
    Nulla &#233; reale, tutto &#233; lecito.

  6. #6
    .:OVERLOAd :. cvtmih's Avatar
    Join Date: Dec:2010
    Location: Sofia
    Posts: 652
    , , , :

    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+|

  7. #7
    Mire-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)

  8. #8
    Registered User hateras's Avatar
    Join Date: Jan:2011
    Location: Kronos III
    Posts: 1,028
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

Copyright © 1999-2011 . .
iskamPC.com | mobility.BG | Bloody's Techblog | | 3D Vision Blog |