answersLogoWhite

0


Best Answer

for example "sumNums(12345)" would sum 1+2+3+4+5.

the recursive code is just really confusing me.

unsigned sumDigits (unsigned n)

{

. . if (n<10) return n;

. . else return n%10 + sumDigits (n/10);

}

User Avatar

Wiki User

13y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How do you write a recursive function for summing ints?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

What is byvalue for java keywords?

There is no such keyword in Java. In general: whether an argument is passed by value or by reference is determined by whether the argument is a primitive (by value) or an Object (by reference). In reality, it's a little more complicated. It seems to be that the actual reference you send as an argument will not change, but the data it refers to will. // This method will not cause a change in the original value. void changeArg(int[] ints) { ints = null; } // This method will. void changeArg(int[] ints) { ints[0] = 0; }


How do you write a C plus plus statement to allocate memory cells dynamically and store the memory address in a pointer to an integer named gred?

int * gred ; gred = new int [100] ; // this example snippet creates 100 ints


What is a malloc function in C programming with example?

The malloc() function is part of a class of functions that deal with the allocation of memory on the heap. int *a = malloc (sizeof (int) * 100); /* allocate 100 int's */ if (a == NULL) {...} /* deal with possible malloc failure */ /* use a, either as pointer or as array of 100 ints */ free (a); /* release memory back to the library */


How will you declare an array of three functions pointer where each function receives two ints and returns a float?

typedef float (*pt_func)(int, int); pt_func arr[3];another way:float (*pt_func[3])(int, int);


Write a c plus plus program that inputs 5 integers from the user and separates the integer into individual digits and prints the digits separated from one another by three spaces each.?

// create an BufferedReader from the standard input stream BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); String currentLine = ""; int total = 0; int[] ints = new int[5]; // read integers while (total &lt; 5) { // get input System.out.print("Input an integer: "); currentLine = in.readLine(); // parse as integer try { int input = Integer.parseInt(currentLine); ints[total] = input; ++total; } catch (final NumberFormatException ex) { System.out.println("That was not an integer."); } } // print each number for (int i = 0; i &lt; ints.length; ++i) { // get individual digits if (ints[i] == 0) { System.out.println(0); } else { while (ints[i] &gt; 0) { System.out.println(ints[i] % 10); ints[i] /= 10; } } } Note that this prints out the digits in reverse order (2048 will print 8 first and 2 last).

Related questions

When was Ints Dālderis born?

Ints D&#257;lderis was born in 1971.


When was Ints Burans born?

Ints Burans was born on May 2, 1941.


When did Ints Burans die?

Ints Burans died on June 10, 2008, in Riga, Latvia.


What qb has throan most int?

The NFL QB to throw the most Ints in history is Brett Favre, with 310 career ints.


Who is only nfl player to lead the league in interceptions two years in a row?

Through the 2008 season, that has happened twice:1) Bill Bradley, Philadelphia Eagles - led the NFL with 11 INTs in 1971 and 9 INTs in 1972.2) Everson Walls, Dallas Cowboys - led the NFL with 11 INTs in 1981 and 7 INTs in 1982.


How many interceptions did Joe Montana throw?

According to Football Reference, Montana threw 21 playoff INTs in 23 games. He threw 4 INTs in 4 playoff games for the Chiefs and 17 INTs in 19 playoff games for the 49ers.


What is the prefix of irresponsible?

I think ints ir


What is the abbreviation for inbound?

i think ints inb.


How do you pronounce giants?

jy (as in 'jive' ) jy-ints


What is byvalue for java keywords?

There is no such keyword in Java. In general: whether an argument is passed by value or by reference is determined by whether the argument is a primitive (by value) or an Object (by reference). In reality, it's a little more complicated. It seems to be that the actual reference you send as an argument will not change, but the data it refers to will. // This method will not cause a change in the original value. void changeArg(int[] ints) { ints = null; } // This method will. void changeArg(int[] ints) { ints[0] = 0; }


What is the return value of getch function?

It returns an int, representing a character. (Basically, chars are ints.) However, if EOF (End-Of-File) has been read, it will return EOF (-1) and set the eof error flag accordingly.


Who led the 07 NFL season in interceptions?

The QBs that threw the most INTs were Jon Kitna, Carson Palmer, and Eli Manning with 20 apiece. The DB with the most INTs was Antonio Cromartie with 10.