Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <iomanip>
- #include <string.h>
- #include <math.h>
- using namespace std;
- int a, i, upperLimit, number = 1, step = 1;
- bool mainchoice;
- void data1() {
- int upperLimit, digit;
- cout << "Enter upper limit: ";
- cin >> upperLimit;
- for (int i = 1; i <= upperLimit; i++)
- {
- digit = i % 10;
- if (digit == 1 || digit == 2 || digit == 4 || digit == 8) {
- cout << i << " ";
- }
- }
- }
- void data2() {
- int upper_limit, digit;
- cout << "Enter upper limit: ";
- cin >> upper_limit;
- for (int i = 1; i <= upper_limit; i++) {
- digit = i % 4;
- if (digit == 1 || digit == 3)
- cout << i << " ";
- }
- }
- void data3() {
- cout << "Enter upper limit: ";
- cin >> upperLimit;
- upperLimit *= 2;
- int number = 1, i = 1;
- while (number <= upperLimit) {
- if (i % 2 == 1) {
- cout << number << " ";
- }
- else {
- cout << i + 2 << " ";
- }
- number += i;
- i++;
- }
- }
- void data4()
- {
- int n;
- double sum = 0.0;
- cout << "Enter n: ";
- cin >> n;
- if (n <= 0) {
- cout << "Invalid input. Please enter a positive integer." << endl;
- }
- int i = 1;
- bool firstTerm = true; // determine if it's the first term in the series
- cout << "Sum of the series: ";
- do {
- if (!firstTerm) {
- cout << " + ";
- }
- else {
- firstTerm = false;
- }
- cout << i << "/" << i + 1;
- sum += static_cast<double>(i) / (i + 1);
- i++;
- } while (i <= n);
- cout << " = " << fixed << setprecision(3) << sum << endl;
- }
- void data5() {
- int num, digit;
- cout << "Enter a number: ";
- cin >> num;
- if (num == 0) {
- cout << "zero " << endl;
- }
- const char* words[] = { "zero ", "one ", "two ", "three ", "four ", "five ", "six ", "seven ", "eight ", "nine " };
- string reverseWords = "";
- while (num > 0) {
- digit = num % 10;
- num /= 10;
- reverseWords = words[digit] + reverseWords;
- }
- cout << "Output: " << reverseWords << endl;
- }
- int main() {
- while (mainchoice = true)
- {
- int choice = 0;
- cout << "Choose one:\n1. Sequence of 1, 2, 4, and 8 Generator\n2. Modulo 4\n3. Alternating Numbers\n4. '1 / 2 + 2 / 3 + 3 / 4 ...'\n5. Numbers to Words\n6. Exit. " << endl;
- cout << "Choice: ";
- cin >> choice;
- switch (choice)
- {
- case 1:
- system("cls");
- data1();
- cout << "\n\n\n";
- break;
- case 2:
- system("cls");
- data2();
- cout << "\n\n\n";
- break;
- case 3:
- system("cls");
- data3();
- cout << "\n\n\n";
- break;
- case 4:
- system("cls");
- data4();
- cout << "\n\n\n";
- break;
- case 5:
- system("cls");
- data5();
- cout << "\n\n\n";
- break;
- case 6:
- system("cls");
- cout << "Program Exited!";
- cout << "\n\n\n";
- return 0;
- default:
- cout << "Please Enter a valid option.";
- cout << "\n\n\n";
- break;
- }
- }
- return 0;
- }
- /*(use for)
- Enter upper limit: 50
- 1 2 4 8 11 12 14 18 21 22 24 28 31 32 34 38 41 42 44 48
- (use for)
- Enter upper limit: 50
- 1 3 9 13 18 19 22 24 30 34 39 40 43 45
- (use while)
- Enter upper limit: 50
- 1 3 3 6 5 11 7 18 9 27 11 38 13 51 15 66 17 83 19
- (use do while)
- Enter n: 10
- sum of the series
- 1/2+2/3+3/4+4/5+5/6+6/7+7/8+8/9+10/11 =. 7.980
- (use while loop)
- Enter a number: 2193
- Output
- three nine one two
- Enter a number: 1020
- Output
- zero two zero one
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement