1. Write a program that performs the following. The user
inputs a number and then enters a series of numbers
from 1 to that number. Your program should determine
which number (or numbers) is missing or duplicated in
the series, if any. For example, if the user entered
5 as the initial number and then entered the
following sequences, the results should be as shown.
Input Sequence Output
---------------------- ---------------
1 2 3 4 5 Nothing bad
However, if 7 were the high number, the user
would see the results on the right for the following
number entries:
Input Sequence Output
---------------------- ---------------
1 3 2 4 5 Missing 6
Missing 7
And if 10 were the high number and the user
entered the numbers shown on the left, note the list
of missing and duplicate numbers:
Input Sequence Output
---------------------- ---------------
1 2 4 7 4 4 5 10 8 2 6 Duplicate 2 ( 2 times)
Missing 3
Duplicate 4 ( 3 times )
Missing 9
Answer Posted / md. mohaiminul islam
#include <stdio.h>
#include <conio.h>
void main(void)
{
int a[100];
int s,c;
int b=0;
clrscr ();
printf("type lage number of your serise:\n");
scanf("%d",&c);
printf("Plz type how many numbers you want to check:\n");
scanf("%d",&s);
printf("Type the numbers you want to check\n");
for (int i=0;i<s;i++)
scanf("%d",&a[i]);
for (int x=1;x<=c;x++)
{
for (int y=0;y<s;y++)
if (a[y]==x)
b++;
if (b>=2)
printf("Duplicate %d :(%d) time's\n",x,b);
if (b==0)
printf("%d is missing.\n",x);
b=0;
};
getch ();
}
Is This Answer Correct ? | 16 Yes | 12 No |
Post New Answer View All Answers
Write a C/C++ program that connects to a MySQL server and checks if the InnoDB plug-in is installed on it. If so, your program should print the total number of disk writes by MySQL.
write a program that prompt the user to enter his height and weight,then calculate the body mass index and show the algorithm used
Code for Method of Handling Factorials of Any Size?
Definition of priority queue was given. We have to implement the priority queue using array of pointers with the priorities given in the range 1..n. The array could be accessed using the variable top. The list corresponding to the array elements contains the items having the priority as the array index. Adding an item would require changing the value of top if it has higher priority than top. Extracting an item would require deleting the first element from the corresponding queue. The following class was given: class PriorityQueue { int *Data[100]; int top; public: void put(int item, int priority); // inserts the item with the given priority. int get(int priority); // extract the element with the given priority. int count(); // returns the total elements in the priority queue. int isEmpty(); // check whether the priority queue is empty or not. }; We had to implement all these class functions.
how to write a program that opens a file and display in reverse order?
What output does the following code generate? Why? What output does it generate if you make A::Foo() a pure virtual function? class A { A() { this->Foo(); } virtual void Foo() { cout << "A::Foo()" << endl; } }; class B : public A { B() { this->Foo(); } virtual void Foo() { cout << "A::Foo()" << endl; } }; int main(int, char**) { A objectA; B objectB; return 0; }
Performance Algorithm A performs 10n2 basic operations and algorithm B performs 300 lg n basic operations. For what value of n does algorithm B start to show its better performance?
write a program using virtual function to find the transposing of a square matrix?
write a program to perform generic sort in arrays?
develop a program to calculate and print body mass index for 200 employees
Write a (n) algorithm that sorts n distinct integers, ranging in size between 1 and kn inclusive, where k is a constant positive integer. (Hint: Use a kn-element array.)
How can I Draw an ellipse in 3d space and color it by using graph3d?
Write a simple encryption program using string function which apply the substitution method.
find level of following tree (state, parent) " J,D I,D H,C E,B F,B G,C B,A D,A C,A A,& K,E L,E L,F M,F N,G O,H P,I P,H Q,I R,J S,K U,P T,L
Code for Small C++ Class to Transform Any Static Control into a Hyperlink Control?