i want solve this problems ??

Pages: 12
* write a programe that calculate and print the number of digits of any number . for example if the user types in the number 42339 , the program should print 5 ???
* write a c++ program that declares an array a of 100 components of type int . Initialize the array so that the first 75 components are equal to the index variable modules 10,and the last 25 components are equal to five times the index variable . Output the array so that 5 elements per line are printed. The program should compute and print the number of array elements greater than 50.
1
2
3
4
5
6
7
#include <iostream>

int main() {
    int x;
    std::cin >> x;
    if( x == 42339 )
        std::cout << 5 << std::endl;


... Sigh ...

We don't generally spoonfeed answers. Show what you've done so far and ask a more specific question, then we'll help.
thx for you answer

but this answer for this number but i talk at any number

i want for example enter 5263 print 4 , 2556352 print 7 ???
He knows what you mean... he was being sarcastic because you haven't shown any effort whatsoever to solve the problem yourself.
Okay so write a program where you input into a string, and then cout the size of the string... it should literally take you a minute and a half.
Okay so write a program where you input into a string, and then cout the size of the string... it should literally take you a minute and a half.


yeah, I believe that there is a a command or function for that? (@ OP)
i want full program ?? and i want this program integer not string ??

Can you help me ?? and write full program ??
this code does not exist any further..
Last edited on
Someone please slap timmy...

And we know what the goal of your program is, for the second time... and we're telling you that you can solve this problem using strings. We're not going to give you the answer because you wouldn't learn anything, and I for one don't want another uneducated fool polluting the market.
very thx timmy ...

please ,, can you answer this programe ??

* write a c++ program that declares an array a of 100 components of type int . Initialize the array so that the first 75 components are equal to the index variable modules 10,and the last 25 components are equal to five times the index variable . Output the array so that 5 elements per line are printed. The program should compute and print the number of array elements greater than 50.
Here you are:
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
27
#include <iostream>
using namespace std;

int main()
{
     const int size = 100;
     int array1[size];
     for (int i = 0; i < 75; i++)
          array1[i] = i % 10;
     for (int i = 75; i < size; i++)
          array1[i] = i * 5;
     for (int i = 0; i < size; i++)
     {
         if (i % 5 == 0)
            cout<<endl;
         cout<<array[i]<<"  ";
      }
     cout<<endl;
     int num = 0;
     for (int i = 0; i < size; i++)
     {
            if (array1[i] > 50)
                num++;
      }
     cout<<"There are "<<num<<" of array elements grater than 50."<<endl;
cin.get();
}

<sigh>

This forum is dead to me...
very very thx bl4ckb3rry ;

can solve this program ???

* write a function named "digit_name"that takes an integer argument in the range from 1 to 9 , inclusive , and prints the English name for that integer on the computer screen . The function should nor return a value . if the argument is not in the required range, then the function should print "digit error" . Thus, for example , the statement digit_name(7); should print seven on the screen ; the statement digit_name(0); should print digit error on the screen .. ???????

closed account (D80DSL3A)
@packetpirate
I doubt that any student will get further than passing their first intro class this way.
No way prof a7med will finish a degree in CS if he can't write programs like these himself.
He'll wash out in the first year.
Do universities still give written exams? If so, those will be failed.

@timmy and bl4ckb3rry: These problems are so elementary that few will be impressed by you solving them. What's your motivation here?

I'll admit though, I think I did it a few times when I was new here too - until I was corrected by a few regulars.
prof a7med what are you going to do when your professor asks you to explain your code? You're digging yourself a hole here. Do some research and at least try to solve the problems yourself before dumping some questions on the first C++ forum you could find. Though there are two answers already posted, try to optimize them so you can get at least something out of them. And as for your next question, try to solve it yourself. What do you know so far? What will you need? Come back with some code and people will be more than happy to help. I advise you look into switch statements.
Last edited on
@packetpirate
yeah i admit my fault....i am new to this forum....thanx for correcting me...i'll make sure that i dont do this next time..but you should have been little polite....
No, timmy. This happens too frequently. It should be a bannable offense to post a solution to someone's homework. Not to mention the solution should be deleted.
Last edited on
do a do-while loop that add to the number x until dividing by 10^x result in a float/double less than 1. return x. convert the int to a double or float for this.

Silly idea though. string length of cin input is a way better solution without looping or <math.h>'s pow(x, ^n)

To show the silly idea, let's say the loops checks this.

check: let's say given the number 4495.
4495 / 10^1 = 449.5 (not <1)
4495 / 10^2 = 44.95 (not <1)
4495 / 10^3 = 4.495 (not <1)
4495 / 10^4 = 0.4495 (< 1)
found it, return 4!
Last edited on
Pages: 12