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...

Given an array of numbers, except for one number all the
others occur twice. Give an algorithm to find that number
which occurs only once in the array.

Answer Posted / ruchi

#include<stdio.h>
#include<conio.h>
int main()
{
int a[15],i,j,n,temp,p,k;

printf("\nHow many elements are there in a array ");
scanf("%d",&n);
printf("\nEnter the elements ");
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
for(i=0;i<n;i++)
{
for(j=i+1;j<n;j++)
{
if(a[i]>a[j])
{
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
}
printf("\nThe element which occur once is ");
for(i=0;i<n;i++)
{
k=2*i;
p=2*i+1;

if(a[k]!=a[p])
{
printf("%d\n",a[k]);
break;
}
}

getch();
}

Is This Answer Correct ?    0 Yes 3 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What do header files do?

1072


What are the two types of functions in c?

1004


Explain how can a program be made to print the line number where an error occurs?

1207


Is it better to use a macro or a function?

1155


Should I use symbolic names like true and false for boolean constants, or plain 1 and 0?

1055


What is the best way to store flag values in a program?

1070


Which is not valid in C a) class aClass{public:int x;}; b) /* A comment */ c) char x=12;

1071


Are the variables argc and argv are local to main?

1317


Write a program to check whether a number is prime or not using c?

1056


Explain how can a program be made to print the name of a source file where an error occurs?

1197


How will you declare an array of three function pointers where each function receives two ints and returns a float?

1362


Write a program to check palindrome number in c programming?

1013


What is the purpose of void pointer?

1028


Why is c so important?

1060


How to declare pointer variables?

1239