* 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.
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.
* 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.
#include <iostream>
usingnamespace std;
int main()
{
constint 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();
}
* 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 .. ???????
@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.
@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.
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!