Question
Please solve this question using c++ language
Problem 2. More Probleml. The program builds the array of integers that contains duplicates as well. Your program should find
0 0
Add a comment Improve this question Transcribed image text
Answer #1

CODE IN C++:

#include <iostream>

using namespace std;

int main()
{
int arr[100];
int length = 0 , temp;
cout<<"Enter a list of numbers ending with -999"<<endl;
while(true){
cin>>temp;
if(temp==-999)
break;
arr[length] = temp;
length += 1 ;
}
int sum = 0 ;
bool flag;
for(int i=0;i<length;i++){
flag = true;
for(int j=0;j<i;j++){
if(arr[i]==arr[j]){
flag = false;
break;
}
}
if(flag)
sum += arr[i];
}
cout <<"The sum of unique numbers is:"<<sum<<endl;
return 0;
}
OUTPUT:

input Enter a list of numbers ending with -999 1 3 1 4 5 5 -999 The sum of unique numbers is:13 |- . .Program finished with e

Add a comment
Know the answer?
Add Answer to:
Please solve this question using c++ language Problem 2. More Probleml. The program builds the array...
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
  • use c++ language, keep it simple i am using code block Exercise#2: Arrays with Random Numbers...

    use c++ language, keep it simple i am using code block Exercise#2: Arrays with Random Numbers Write a program that generates n random numbers as follows: Asks the user to input a positive integer n Asks the user to input the maximum value (say m) for the integers to be generated. Write a program that generates the n numbers in the range 0 to m. The program stores the generated numbers in an array A[ Asks the user to enter...

  • Please help C++ language Instructions Write a program that prompts the user to enter 50 integers...

    Please help C++ language Instructions Write a program that prompts the user to enter 50 integers and stores them in an array. The program then determines and outputs which numbers in the array are sum of two other array elements. If an array element is the sum of two other array elements, then for this array element, the program should output all such pairs.

  • Please solve this C language progrm (2-D Array program) the most basic way ! Thank You!...

    Please solve this C language progrm (2-D Array program) the most basic way ! Thank You! Write a function that takes a 4 x 4 array of integers as its parameter. The function must use two nested for-loops to determine the largest integer in the array as well as its row and column numbers. Recall that C-functions cannot return multiple values. Use pointers in the function parameter list to relay the results to the caller program. Write another function, which...

  • Please answer using C ++ programming language ONLY! We have only used <stdio.h> if that helps....

    Please answer using C ++ programming language ONLY! We have only used <stdio.h> if that helps. This is a basic course and the furthest we have gone is BASIC arrays. Write the code for the following problems using arrays. Write what would go in the “int main()” part of the program. For these problems, the entire program and program output is not needed. Just include what goes in the int main() part of the program. 1. Declare an integer array...

  • python language Problem Description: In this program we are going to explore a list or an...

    python language Problem Description: In this program we are going to explore a list or an array of integers using Python. Your program should read a set of integers from the user and store them in a list. Read numbers from the user until the user enters 0 to quit. Then store them in a list. Your program should them compute the sum of all the numbers in the list and output to the user. You will use lists and...

  • Write a program that asks the user to input 10 integers of an array. The program...

    Write a program that asks the user to input 10 integers of an array. The program then inserts a new value at position (or index) given by the user, shifting each element right and dropping off the last element. For example, in the sample input/output below, the program will insert the value 30 at index 3. All the previous numbers of the array starting from position 3 (i.e., 7 1 20 9 23 8 22 will be shifted one position...

  • Write a program that reads a sequence of integers into an array and that computes the...

    Write a program that reads a sequence of integers into an array and that computes the alternating sum of all elements in the array. For example, if the program is executed with the input data: 2 1 4 9 16 9 7 4 9 11 Then it computes 2 - 1 + 4 - 9 + 16 - 9 + 7 - 4 + 9 – 11 = 4 Use a scanner object to gather the inputs from the user....

  • Write a Program in C language for: 1. Create a C program to read 7 integers...

    Write a Program in C language for: 1. Create a C program to read 7 integers and store them in an array. Next, the program is to check if the array is symmetric, that is if the first element is equal to the last one, the value of the second one is equal to the value of the last but one, and so on. Since the middle element is not compared with another element, this would not affect the symmetry...

  • Q1. Write a program in Java         a. Create 2 separate arrays, of user defined values,...

    Q1. Write a program in Java         a. Create 2 separate arrays, of user defined values, of same size         b. Add these 2 arrays. ........................................................................................................................... Q2. Write a program in java (using loop) input any10 numbers from user and store in an array. Check whether each of array element is positive, negative, zero, odd or even number. ............................................................................................................................ Q3. Write a program in Java to display first 10 natural numbers. Find the sum of only odd numbers. .............................................................................................................................. Q4....

  • Write a Java program that generates an array of Fibonacci numbers. Specifications: The program -Fills a...

    Write a Java program that generates an array of Fibonacci numbers. Specifications: The program -Fills a one-dimensional array with the first 30 Fibonacci numbers using a calculation to generate the numbers. Note: The first two Fibonacci numbers 0 and 1 should be generated explicitly as in -long[] series = new long[limit]; //create first 2 series elements series[0] = 0; series[1] = 1; -But, it is not permissible to fill the array explicitly with the Fibonacci series’ after the first two...

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