Q:

Write a program that will print the first N numbers for a specific base

0

Write a program that will print the first N numbers for a specific base

Sample Output:

 Print the first N numbers for a specific base:                        
 The number 11 in base 10 = 1*(10^1)+1*(10^0)=11                       
 Similarly the number 11 in base 7 = 1*(7^1)+1*(7^0)=8                 
----------------------------------------------------------------       
 Input the number of term: 15                                          
 Input the base: 9                                                     
 The numbers in base 9 are:                                            
1  2  3  4  5  6  7  8  10  11  12  13  14  15  16

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

#include <iostream>
using namespace std;
int main()
{
    int trm, bs, r, q, i, num;
    cout << "\n\n Print the first N numbers for a specific base:\n";
    cout << " The number 11 in base 10 = 1*(10^1)+1*(10^0)=11" << endl;
    cout << " Similarly the number 11 in base 7 = 1*(7^1)+1*(7^0)=8" << endl;
    cout << "----------------------------------------------------------------\n";
    cout << " Input the number of term: ";
    cin >> trm;
    cout << " Input the base: ";
    cin >> bs;
    cout << " The numbers in base " << bs << " are: " << endl;
    for (i = 1; i <= trm; i++) 
    {
        r = i % bs;
        q = i / bs;
        num = q * 10 + r;
        cout << num << "  ";
    }
    cout << endl;
}

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now