answersLogoWhite

0

I don't know if I fully understand but here goes

int a[]={2,4,8,0,2};

int y = 0;

int x = 0;

while(y<a.length()){

x += a[y];

y++;

}

then you just reference x.

User Avatar

Wiki User

14y ago

What else can I help you with?

Continue Learning about Engineering

What does the cons function do in clojure?

Returns a new sequence where the first parameter is the first element and the second parameter is the rest.


Which scanner class method would you use to read integer as input?

The method Scanner.nextInt() returns an integer obtained as user input.


D Write a function that returns 2n where n is an input parameter?

int 2n(int n){return n &lt;&lt; 1;)


When a function is overloaded there are multiple definitions of the functions What makes the various definitions of the function different from each other?

Their parameter-lists and returns values.


How do you write a program for counting and displaying occurrence of a number in an array?

Your first step is accepting input, which is done using the scanf() function:scanf("%d", &number);This means that you want scanf() to accept input, convert the input to a number, and store it in the memory at the address of number.Use a for() loop, counting from 0 to 9, and an array of integers to hold the numbers. Then simply scanf("%d", &intarray[counter]);The next step is a little tricky, but not very if you plan it out in advance.Each integer can contain 256, 65,536 or 4,294,967,296 different numbers. Creating an array to hold the count of each of those numbers is a waste of RAM.Instead, you'll want an "associative" array as follows:int numcount[MAXNUM][2];MAXNUM is 10, or the number of integers in the array you're checking. The second dimension, 2, consists of the number and its count.Obviously, you'll want a way to keep track of how many integers you've stored in numcount. An int called numcountnuminitialized to 0 would be the fastest way.Use a for() loop to iterate through the integers. If the integer does not exist in numcount, then set numcount[numcountnum][0] to the integer, set numcount[numcountnum][1] to 1, and increment numcountnum. Otherwise, if the integer exists, increase numcount[the integer index][1].Once the for() loop is finished, display the results. The only thing you have left to figure out is the function that searches the numcount array for an integer, and returns its index (or -1 if it's not found).

Related Questions

What does the cons function do in clojure?

Returns a new sequence where the first parameter is the first element and the second parameter is the rest.


What is the use of the parameter in java?

A parameter is a variable that is passed to a method. It is not specific to Java, and is used in almost all programming languages. The parameter is used by the method in whatever way that it wants. Example: public void add(int x, int y) { return x + y; } In this case, the parameters are two integers, x and y. They are passed to the method 'add' which returns the sum of the parameters.


How can you check if a variable is a string or an integer in PHP?

Integers - The "is_int()" function can be used to check if a variable is has an integer for its value. ---- is_int($variable); // Returns true if $variable is an integer - otherwise false ---- Numeric Strings - Numeric strings are strings with numbers (or things that count as numbers) in them. Numeric-string variables are not integer variables. Numeric-string variables are passed on through forms, instead of integer variables - if you were wondering. Check form values using string formats, and not integer formats. The "is_numeric()" function can be used to check if a variable is a string with numbers - and only numbers - in it (except things that add up to be numbers). ---- is_numeric($variable); // Returns true if $variable is a string, and only contains numbers (broadly speaking) - false otherwise ---- Strings - String values are just text, basically. String variables can contain integers, but that does not make it an integer-type variable - it makes it a numeric string variable. The "is_string" function can be used to check if a variable contains the value of a string. ---- is_string($variable); // Returns true if $variable is a string - false otherwise


Which scanner class method would you use to read integer as input?

The method Scanner.nextInt() returns an integer obtained as user input.


D Write a function that returns 2n where n is an input parameter?

int 2n(int n){return n &lt;&lt; 1;)


When a function is overloaded there are multiple definitions of the functions What makes the various definitions of the function different from each other?

Their parameter-lists and returns values.


How do you write a program for counting and displaying occurrence of a number in an array?

Your first step is accepting input, which is done using the scanf() function:scanf("%d", &number);This means that you want scanf() to accept input, convert the input to a number, and store it in the memory at the address of number.Use a for() loop, counting from 0 to 9, and an array of integers to hold the numbers. Then simply scanf("%d", &intarray[counter]);The next step is a little tricky, but not very if you plan it out in advance.Each integer can contain 256, 65,536 or 4,294,967,296 different numbers. Creating an array to hold the count of each of those numbers is a waste of RAM.Instead, you'll want an "associative" array as follows:int numcount[MAXNUM][2];MAXNUM is 10, or the number of integers in the array you're checking. The second dimension, 2, consists of the number and its count.Obviously, you'll want a way to keep track of how many integers you've stored in numcount. An int called numcountnuminitialized to 0 would be the fastest way.Use a for() loop to iterate through the integers. If the integer does not exist in numcount, then set numcount[numcountnum][0] to the integer, set numcount[numcountnum][1] to 1, and increment numcountnum. Otherwise, if the integer exists, increase numcount[the integer index][1].Once the for() loop is finished, display the results. The only thing you have left to figure out is the function that searches the numcount array for an integer, and returns its index (or -1 if it's not found).


Is factorial an operator?

No, factorial is not an operator in the traditional sense like addition or multiplication. Instead, it is a mathematical function that takes a non-negative integer ( n ) and returns the product of all positive integers up to ( n ), denoted as ( n! ). For example, ( 5! = 5 \times 4 \times 3 \times 2 \times 1 = 120 ).


What day is it today or what day is today?

&lt;script&gt; var day; day = new Date(); var milli = day.getTime(); // returns milliseconds that have elapsed since 1/1/70 var year = day.getFullYear(); // returns the Year var month = day.getMonth(); // returns the month (0-11 January = 0) var dayofmonth = day.getDate(); // returns the day of the month var day2 = day.getDay(); // returns the integer day of the week (Sunday = 0) var hour = day.getHours(); // returns the integer hour (0 -&gt; 23) var minute = day.getMinutes(); // returns the Minute (0 - &gt; 59) var second = day.getSeconds(); // returns the Second (0 -&gt; 59) You can write out the date or time using document.write() document.write("The date is " + (month + 1) + "/" + dayofmonth + "/" + year); &lt;/script&gt;


What is integer in visual basic?

In the computer programming language Visual Basic, the data type integer is a whole number which can be used in calclations. It can be positive, negative, or zero. The default type of integer is 32-bit, but with "short" and "long" you can have 16- or 64- bit answers. The short data type works well with small numbers and saves RAM space. If overflow is a problem, long works better because of its larger capacity. To take the integer portion of a decimal, single, or double, use the int() function. int(3.925604) returns 3 as a decimal To convert a data type to integer, use cint() cint(int(3.925604)) returns 3 as an integer


Write a function prototype named test that accepts two parameters an integer and character and returns a float?

float test(int, char);


What do parameters and return values have to do with methods?

Parameters and return values are a major part of methods. When defining a method, you must include information about the data types of the return value and the parameters. An example of a method definition is this: public int getSumOfNumbers( int number1, int number2, int number3 ) { return ( number1 + number2 + number3 ); } The word "int" right after the word "public" is the return type. It describes what data type will be returned by the method. In this case, it was int, or integer. The sequence of words in between the parantheses, "int number1, int number2, int number3", is the parameter list. Each of the phrases separated by a comma in the parameter list is a parameter. The first word - in this case "int" - is the data type of the parameter. It describes what type of variable the parameter will be. The second word - "number1", "number2", or "number3" - is the name of the parameter. Every parameter must have a data type and a name, and every method must have a return type: even a method that returns nothing. For example: public void evaluateNumber(int number) { if ( number &gt; 0 ) { System.out.println( number + " is positive." ); } else if ( number &lt; 0 ) { System.out.println( number + " is negative." ); } else { System.out.println( number + " is zero." ); } } When a method does not return data, its return type must be defined as void, as it is above.