Best Answer


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;

return 0;


User Avatar

Wiki User

โˆ™ 2009-09-19 21:41:59
This answer is:
User Avatar

Add your answer:

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

Give you a 4digit lottery number?

4digit number

Give you a free 4digit number?


What is the smallest 4digit even number?

It is 1,000.

4digit number divisible by 9 and 10?


What is the smallest 4digit non zero number?


Sum of number multiplied by itself?


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


Write a program in c language to sum and average a given number?

The sum and average of a given number is just that number, so there is no need to write a program.

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

A + b = c

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 program in C language to find average of the digits of a number?

viod main() { int a,b,c; float sum,avg; a=10; b=20; c=30; sum=a+b+c; avg=sum/3; print("\n Avg : "avg); }

What is Peterson number in C?

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

How to write a program to scan a number n and then output the sum of the powers from 1 to n?

This only works in Xcode Command Line Tool.#include int main (int argc, const char * argv[]){int sum=0, accum1, accum2;int i, c, n;printf("Enter Number: ");scanf("%d", &n);for(i=1;c

Find the sum of the series in c language ie1 3 5 7?

The sum of every odd number is infinite.

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.

C program to check whether the number and its reverse are same or not?

#include &lt;stdio.h&gt; #include&lt;conio.h&gt; void main () { int a,r,n,sum=0; clrscr(); printf("enter the number"); scanf("%d",&amp; n); c=n while (n!=0) { a=n%10; n=n/10; sum=sum*a+a } printf("the reverse is %d \n",sum); if(c==sum) printf("\n the given number is palindrome"); else printf("\n the given number is not a palindrome"); getch(); }

What is the sum Of?

The sum of is the total of everything being summed; the sum total. Thus the sum of a, b and c is therefore a + b + c.

When was J C Sum born?

J C Sum was born in 1976.

Write a javascript code to accept three numbers and display the largest of the three numbers and their sum?

function requestedFunction(a,b,c) { document.write("Largest number:" + Math.max(a,b,c) + "Sum of numbers:" + (a+b+c)) }

Calculate sum of three number in c program?

it's simple: { int a,b,c,d; printf("enter the numbers"); scanf("%d %d %d" &amp;a &amp;b &amp;c); d=a+b+c; printf("the sum is=%d" d); }

What is the algorithm of the program to find sum and average of n- different numbers?

1. start2. initialize counter (c = o)3. initialize sum (sum = 0)4. input n 'number of items for which average is to be calculated'5. input the 1st (2nd, 3rd, ....) number6 increment counter (c = c+1)7. add the last number to sum (sum = sum+n)8. make a decision (is counter = number of items?) yes goto 9 No goto 59. find average (ave = sum/n)10. print result11. end

Program in java to add two numbers?

a = 5;b = 10;c = a + b;System.out.println("The sum is " + c);a = 5;b = 10;c = a + b;System.out.println("The sum is " + c);a = 5;b = 10;c = a + b;System.out.println("The sum is " + c);a = 5;b = 10;c = a + b;System.out.println("The sum is " + c);

What is the Aram strong number in c plus plus?

If the sum of squares of digits of a number equals to the number itself, then that number is called an aram strong number.

Which law describes that the product of one number times the sum of two or more numbers is equal to the sum of the products of the first number and each of the other numbers of the sum?

This is the Distributive Law : a x ( b + c) = ab + ac