C and C++

Moderators: None (Apply to moderate this forum)
Number of threads: 28695
Number of posts: 94715

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
seperates the five digit integers Posted by prakhargarg009 on 21 Jul 2010 at 10:28 AM
wap a c++ program that takes input of 5 digit integer from user and prints each digit seperated from each other with three spaces each
Report
Re: seperates the five digit integers Posted by Cypher1x on 5 Aug 2010 at 2:00 PM
you can make divisions by 10 on the integer, like this:



#include <iostream>

using namespace std;

int main()
{
    int i;
    cout << "Put an Integer: ";
    cin >> i;

    while(i >= 10) {
        int q = i / 10;
        cout << i - q * 10 << "   ";
        i = q;
    }
    cout << i << endl;

    return 0;
}



the only problem here is that it prints the integers starting by the last one, so if you like to do the opposit, put them in a table and then print them correctly :d



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.