Answer to Question #215973 in C++ for Hemambar

Question #215973
write a program to get 5 single digit numbers in an array and form a number using the array elements (use function with array as argument and return the number)
Sample input:
Numbers [5]={1,2,3,4,5}
Sample output:
Number=12345
1
Expert's answer
2021-07-11T14:39:19-0400
#include <iostream>//Input output stream
using namespace std;
//implement function wich get 5 number(array) and return number
int DigitToNum(int ar[5])
{
	int ans= 0;
	//1 2 3 4 5=0*10+1=1->1*10+2=12->12*10+3=123->123*10+.... (use this)
	for (int i = 0; i < 5; i++)
		ans = (ans * 10) + ar[i];
	return ans;
}
int main()
{
	cout << "Please enter 5 single number(digit)\n";
	int ar[5];
	for (int i = 0; i < 5; i++)
		cin >> ar[i];//Scaner each digit
	int number = DigitToNum(ar);//return num
	//Output this number
	cout << number << endl;
	return 0;
	//Input test
	//Please enter 5 single number(digit)
	//4 8 5 2 3
	//Output
	//48523
}

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