Answer to Question #272030 in Electrical Engineering for Vasu

Question #272030

Initialize a 10 bit number “num” of reg data type with a value 0 (i.e. num=10’b0000000000), now


make use of for loop to get the output result as num=10’b001100110011 (Note: It is mandatory to


use for loop for getting this output)

1
Expert's answer
2021-11-29T00:17:10-0500

#include <iostream> #include <fstream> #include <iomanip> using namespace std; int main() { fstream output ; long int num; // you cant use small c, as cout is a keyword in c++. char exit = 0; // NULL -> gives warning message here. output.open("output.txt", fstream::out); output << "VALUE ENTERED" << left << "\tNUMBER OF DIGITS" << endl; if (output.is_open()) { while (exit != 'n' && exit != 'N') { cout << "Input number: " << endl; cin >> num; if (num > -10 && num < 10) output << num << setw(40) << "\t\t\t1 " << endl; else if (num > -100 && num <= -10 || num >= 10 && num < 100) output << num << setw(40) << "\t\t\t2 " << endl; else if (num > -1000 && num <= -100 || num >= 100 && num < 1000) output << num << setw(40) << "\t\t\t3 " << endl; else if (num > -10000 && num <= -1000 || num >= 1000 && num < 10000) output << num << setw(40) << "\t\t\t4 " << endl; else if (num > -100000 && num <= -10000 || num >= 10000 && num < 100000) output << num << setw(40) << "\t\t\t5 " << endl; else if (num > -1000000 && num <= -100000 || num >= 100000 && num < 1000000) output << num << setw(40) << "\t\t\t6 " << endl; else if (num > -10000000 && num <= -1000000 || num >= 1000000 && num < 10000000) output << num << setw(40) << "\t\t\t7 " << endl; else if (num > -100000000 && num <= -10000000 || num >= 10000000 && num < 100000000) output << num << setw(40) << "\t\t\t8 " << endl; else if (num > -1000000000 && num <= -100000000 || num >= 100000000 && num < 1000000000) output << num << setw(40) << "\t\t\t9 " << endl; if (num > 2000000000 || num < -2000000000) cout << "The number is too large" << endl; else if (num > -10000000000 && num <= -1000000000 || num >= 1000000000 && num < 10000000000) output << num << " 10 " << endl; cout << "do you want to continue? (y/n)" << endl; cin >> exit; } output.close(); } else cout << "unable to open output.txt" << endl; return 0; }

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS