Need help with 3 tasks for my homework

Write your question here.
1.The user writes a nubmer.Write a program to count the digits of the number.
2.The user writes a number.Write a program that imprints the digits of the number starting from the digit of the ones.
3.The user enters some numbers.The number entering stops when the user enters 0.Write a program to show the biggest of set numbers.

I'm really not that familiar with C++ i will aprecciate it if u use the
#include <iostream>
#include <cstdlib>
using namespace std;
int main ()
{...............
The tasks i need to do are with DO-WHILE loops :)
Last edited on
1:
1
2
3
4
5
6
7
8
9
10
11
12
13
#include <iostream>
#include <cstdlib>
#include <string>

using namespace std;

int main() {
    do {
        std::string n;
        std::cin >> n;
        std::cout << n.size() << '\n';
    } while (false);
}


2:
1
2
3
4
5
6
7
8
9
10
11
12
13
#include <iostream>
#include <cstdlib>
#include <string>

using namespace std;

int main() {
    do {
        std::string n;
        std::cin >> n;
        std::cout << std::string(n.rbegin(), n.rend()) << '\n';
    } while (false);
}


3:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <iostream>
#include <cstdlib>
#include <string>
#include <limits>

using namespace std;

void do_it(int biggest = std::numeric_limits<int>::min()){
    int n;
    std::cin >> n;

    if (n) {
        do_it(n > biggest ? n : biggest);
        return;
    }

    std::cout << "The biggest is " << biggest << '\n';
}

int main() {
    do {
        do_it();
    } while (false);
}


I believe those satisfy the constraints.
1:

1
2
3
4
5
6
7
8
9
10
11
12
13
#include<iostream>
using namespace std;

int main()
{
    int i=0;
    char input[100];
    cin>>input;
    for(i=0;input[i]!='\0';i++);
    
    cout<<i;
    return 0;
}


1: Output


1212121212
10


2:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include<iostream>
using namespace std;

int main()
{
    int length=0;
    char num[100];
    cin>>num;
    for(length=0;num[length]!='\0';length++);
    
    
    for(int i=length;i>=0;i--)
    cout<<num[i];
    return 0;
}


2: Output


123456789
987654321


3:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include<iostream>
using namespace std;

int main()
{
    int arr[100],max=0;
    for(int i=0;i<100;i++)
    {
    cin>>arr[i];
    if(arr[i]==0)
    break;
    }
    max=arr[0];

    for(int i=0;i<100;i++)
    {
        if(arr[i]>max)
        max=arr[i];

        if(arr[i]==0)
        break;
    }

    cout<<"\nThe Biggest Number is : "<<max;
    return 0;
}



3: Output


50
70
20
120
10
100
0

The Biggest Number is : 120





Topic archived. No new replies allowed.