Question

. Assuming that the following integer array ArrayInts [ ] = {54, 99,-8, 5, 124, 29, -13,260, 29,-4, 100, 12, 15, 58, 164, 480

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Dear student,

The complete solution to the above question in C programming language is as below:

Code:

#include <stdio.h>

int main()
{
int ArrayInts[17]={54,99,-8,5,124,29,-13,260,29,-4,100,12,15,58,164,480,60};
int sumeven=0;
//will store the sum of all even integers in ArrayInts
int sumodd=0;//will store the sum of all odd integers in ArrayInts
for(int i=0;i<17;i++)
{
if(ArrayInts[i]%2==0)
//even
sumeven=sumeven+ArrayInts[i];
else
sumodd=sumodd+ArrayInts[i];
}
printf("The sum of all even integers is:%d\n",sumeven);
//prints the sum of even integers to the console
printf("The sum of all odd integers is:%d\n",sumodd);//prints the sum of odd integers to the console
  
//Now Binary search for finding sumodd in ArrayInts
  
int first=0;
int last=16;
//one less than the size of the array ArrayInts
int signal=0;//this will tell if we have found the element or not
int mid=0;
int index1=0;
//stores the index of sumodd if found;
while(first<=last)
{
mid=(first+last)/2;

if(sumodd==ArrayInts[mid]){
signal=1;
//found the element
   index1=mid;
break;
}
else
if(sumodd>ArrayInts[mid])
first=mid+1;
else
last=mid-1;
}

if(signal==1)
printf("\nTarget was found at array index %d",index1);
else
printf("\nTarget was not found");
  

return 0;
}

------------------------------------------------------------------------------------------------------------------------------------------------

Output:

The sum of all even integers is:1300 The sum of all odd integers is:164 Target was found at array index 14

-----------------------------------------------------------------------------------------------------------------------------------------------

I hope the given solution helps clear your doubt.

Don't forget to give it a thumbs up.

Regards

Add a comment
Know the answer?
Add Answer to:
. Assuming that the following integer array ArrayInts [ ] = {54, 99,-8, 5, 124, 29,...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Task 1 Main Function: Declare and fill an array with 1000 random integers between 1 -...

    Task 1 Main Function: Declare and fill an array with 1000 random integers between 1 - 1000. You will pass the array into functions that will perform operations on the array. Function 1: Create a function that will output all the integers in the array. (Make sure output is clearly formatted. Function 2: Create a Function that will sum and output all the odd numbers in the array. Function 3: Create a Function that will sum and output all the...

  • Which of the following are valid array declarations? a. int[] array- new int[10]; b. double [array...

    Which of the following are valid array declarations? a. int[] array- new int[10]; b. double [array double[10]; c. charl charArray "Computer Science"; None of the above Analyze the following code: class Test public static void main(Stringl] args) System.out.println(xMethod(10); public static int xMethod(int n) System.out.println("int"); return n; public static long xMethod(long n) System.out.,println("long"); return n The program displays int followed by 10 The program displays long followed by 10. The program does not compile. None of the above. tions 3-4 are...

  • Lab Topics • The basics of Array object Use the following Coding Guidelines • When declaring...

    Lab Topics • The basics of Array object Use the following Coding Guidelines • When declaring a variable, you usually want to initialize it. Remember you cannot initialize a number with a string. Remember variable names are case sensitive. Use tabs or spaces to indent code within blocks (code surrounded by braces). Use white space to make your program more readable. Use comments after the ending brace of classes, methods, and blocks to identify to which block it belongs. Problem...

  • In Java, Implement a class MyArray as defined below, to store an array of integers (int)....

    In Java, Implement a class MyArray as defined below, to store an array of integers (int). Many of its methods will be implemented using the principle of recursion. Users can create an object by default, in which case, the array should contain enough space to store 10 integer values. Obviously, the user can specify the size of the array s/he requires. Users may choose the third way of creating an object of type MyArray by making a copy of another...

  • 3. Write Java methods to accomplish each of the following Write a method named simpleAry which...

    3. Write Java methods to accomplish each of the following Write a method named simpleAry which accepts and return nothing. It creates an array that can hold ten integers. Fill up each slot of the array with the number 113. Then, display the contents of the array on the screen. You must use a loop to put the values in the array and also to display them. Write a method named sury which accepts an array of type double with...

  • Write a C++ program named, gradeProcessor.cpp, that will do the following tasks: -Print welcome message -Generate...

    Write a C++ program named, gradeProcessor.cpp, that will do the following tasks: -Print welcome message -Generate the number of test scores the user enters; have scores fall into a normal distribution for grades -Display all of the generated scores - no more than 10 per line -Calculate and display the average of all scores -Find and display the number of scores above the overall average (previous output) -Find and display the letter grade that corresponds to the average above (overall...

  • must be coded in c++ without any STL libraries sadly :( so im struggling on this...

    must be coded in c++ without any STL libraries sadly :( so im struggling on this problem, any help would be greatly appreciated, thanks in advance! :) assignment is due tomorrow and im really struggling on this last question :( a. Begin by implementing a BST for integers. The underlying structure is a linked list. You need these methods: i. BST(); -- Constructor ii. void put (int) – Inserts a value into the BST. iii. Void put(int[] a) – Inserts...

  • Create a class named Program10. Your program should have the following 4 methods (other helper methods...

    Create a class named Program10. Your program should have the following 4 methods (other helper methods are allowed, but these four methods must be implemented as specified). You need to define a global scanner object and only use it inside the main method and the getValues method, since other methods do not get any values from the input. getValues: This method does not have any input parameter and returns an array of integers. This method prompts the user with a...

  • Copy the following java codes and compile //// HighArray.java //// HighArrayApp.java Study carefully the design and...

    Copy the following java codes and compile //// HighArray.java //// HighArrayApp.java Study carefully the design and implementation HighArray class and note the attributes and its methods.    Create findAll method which uses linear search algorithm to return all number of occurrences of specified element. /** * find an element from array and returns all number of occurrences of the specified element, returns 0 if the element does not exit. * * @param foundElement   Element to be found */ int findAll(int...

  • Overview: file you have to complete is WordTree.h, WordTree.cpp, main.cpp Write a program in C++ that...

    Overview: file you have to complete is WordTree.h, WordTree.cpp, main.cpp Write a program in C++ that reads an input text file and counts the occurrence of individual words in the file. You will see a binary tree to keep track of words and their counts. Project description: The program should open and read an input file (named input.txt) in turn, and build a binary search tree of the words and their counts. The words will be stored in alphabetical order...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT