answersLogoWhite

0


Best Answer

#include
#include

using std::cin;
using std::cout;
using std::endl;
using std::string

int main()
{
const int numberOfdigits = 5;
string myNumber = "0";
char myNumberChar[numberOfdigits] = {0};
cout << endl << "Enter 4 digit integer: ";
cin >> myNumber;

int sumOfDigits = 0;
int temp = 0;
for (int arrayIndex = 0; arrayIndex < (numberOfdigits - 1); arrayIndex++)
{
temp = atoi(&myNumber.substr(arrayIndex, 1)[0]);
sumOfDigits += temp;
}
cout << endl << "Sum of 4 digits is: " << sumOfDigits << endl;


system("PAUSE");
return 0;

}

User Avatar

Wiki User

15y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Sum of 4digit of a number in c?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

Give you a free 4digit number?

5295


What is the smallest 4digit even number?

It is 1,000.


4digit number divisible by 9 and 10?

9000


What is the smallest 4digit non zero number?

1000


Give you a 4digit lottery number?

Oh, dude, you want a lottery number? Alright, how about 1-2-3-4? I mean, statistically speaking, it's just as likely to win as any other combination. Good luck, but like, don't get your hopes up too high, okay?


Sum of number multiplied by itself?

kl


Can you add an irrational number and a rational number?

Let `a` be a rational number and `b` be an irrational number,assume that the sum is rational. 1.a +b =c Where a and c are rational and b is irrational. 2.b=c-a Subtracting the same number a from each side. 3.b is irrational c-a is a rational number we arrived at a contradiction. So the sum is an irrational number.


Adding rational number and an irrational number to get a rational number?

The sum of a rational and an irrational number is always irrational. Here is a brief proof:Let a be a rational number and b be an irrational number, and c = a + b their sum. By way of contradiction, suppose c is also rational. Then we can write b = c - a. But since c and a are both rational, so is their difference, and this means that bis rational as well. But we already said that b is an irrational number. This is a contradiction, and hence the original assumption was false. Namely, the sum c must be an irrational number.


What is the algebraic expression for half the sum of a variable c and a number 4?

(c+4)/2


What is the connection between the number of sides and the sum of the angles?

A + b = c


Why does the sum of rational number and irrational numbers are always irrational?

Let your sum be a + b = c, where "a" is irrational, "b" is rational, and "c" may be either (that's what we want to find out). In this case, c - b = a. If we assume that c is rational, you would have: a rational number minus a rational number is an irrational number, which can't be true (both addition and subtraction are closed in the set of rational numbers). Therefore, we have a contradiction with the assumption that "c" (the sum in the original equation) is rational.


What is Peterson number in C?

Peterson Number:145 = 1! + 4! + 5!number=sum of (factorials of digits)