Program:to find number occurring only once
If there are integers in an array,you have to find out the numer
that occurs only once
Input Format
The first line of the input indicates the number of integers.
The next line is integers that form the array.
The next line is integers that form the array.
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
int lonelyinteger(int a_size, int* a) {
int
a_count[100],i,count=0,c;
for(i=0;i<
100;i++)
{
a_count[i]=0;
}
for(i=0;i<
a_size;i++)
{c=*(a+i);
a_count[c]=(a_count[c])+1;
}
for(i=0;i<
100;i++)
{
if(a_count[i]==1)
{return
(i); }
}
return count;
}
int main() {
int res;
int _a_size, _a_i;
scanf("%d",
&_a_size);
int _a[_a_size];
for(_a_i = 0; _a_i
< _a_size; _a_i++) {
int _a_item;
scanf("%d", &_a_item);
_a[_a_i] =
_a_item;
}
res =
lonelyinteger(_a_size, _a);
printf("%d", res);
return 0;
}
No comments:
Post a Comment