Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

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

Answer Posted / vadivelt

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
addition of 'n' numbers.

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



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What are the advantages of inheritance in c++?

1043


What do the keywords volatile and mean mutable?

1005


What is a volatile variable in c++?

1362


How to demonstrate the use of a variable?

1048


When the constructor of a base class calls a virtual function, why doesn't the override function of the derived class gets called?

1048


What relational operators if statements in c++?

1114


Do you need a main function in c++?

1074


What is a template in c++?

1734


What is the purpose of ios::basefield in the following statement?

1199


How come you find out if a linked-list is a cycle or not?

988


Name the debugging methods that are used to solve problems?

1037


Draw a flow chart and write a program for the difference between the sum of elements with odd and even numbers. Two dimensional array.

6342


Can c++ do everything c can?

1003


Can we define a constructor as virtual in c++?

1065


Who invented turbo c++?

1016