Follow Our FB Page << CircleMedia.in >> for Daily Laughter. We Post Funny, Viral, Comedy Videos, Memes, Vines...

If there are 1 to 100 Numbers in array of 101 elements.
Which is the easy way to find repeated number?

Answers were Sorted based on User's Feedback

If there are 1 to 100 Numbers in array of 101 elements. Which is the easy way to find repeated numb..

1.Get i/p of 101 elements and add all the nos.And say the
result of that Addition is 'sum'.

2.We all know that n(n+1)/2 is formula to calculate the

if n = 100 then n(n+1)/2 give addtion of 1....100.
so say total = n(n+1)/2;

3.Now 'sum' holds the addition of 1....101 nos
And 'total' holds the addition of 1....100 nos

So the repeated no would be.,
Result = sum - total;

Equalent Code is.,

#include<stdio.h>
main()
{
int i, n, sum = 0, a[150], Total;
printf("ENTER SIZE OF ARRAY:\n");
scanf("%d", &n);
printf("\nENTER ELEMENTS OF ARRAY:\n");
for(i = 0; i<n; i++)
{
scanf("%d", &a[i]);
sum = sum + a[i];
}
n = n-1;
Total = (n *(n+1) /2);
printf("\nREPEATED NO: %d",sum - Total);
getch();
}

 Is This Answer Correct ? 38 Yes 6 No

If there are 1 to 100 Numbers in array of 101 elements. Which is the easy way to find repeated numb..

Binary Tree. But their exists better solution

 Is This Answer Correct ? 2 Yes 2 No

More C++ General Interview Questions

What are the benefits of pointers?

What is the difference between #import and #include?

what is the C++

Write a program using shift_half( ) function to shift the elements of first half array to second half and vice versa.

Write a c program for binary addition of two 8 bit numbers.

What are pointers used for c++?

What does iomanip mean in c++?

What is the difference between public and private data members?

Am studying basic c++ programming, have been given the following assignment. Design a linear program to calculate the maximum stress a material can withstand given a force and a diameter of a circle. To find the required area pi should be defined. Have most of the program sorted out but am at a loss as to how to show the calculations required. Can anyone help?

When one must use recursion function? Mention what happens when recursion functions are declared inline?

Keyword mean in declaration?

Categories