Documente Academic
Documente Profesional
Documente Cultură
printf("Unique Elements\n");
for(i = 0; i < num; i++)
{
for (j=0; j<i; j++)
{
if (array[i] == array[j])
break;
}
if (i == j)
{
printf("%d \t", array[i]);
}
}
return 0;
}
Solution 2:
#include <stdio.h>
int main()
{
int arr[10], FreqArr[10], i, j, Count, Size;
printf("\n Please Enter Number of elements in an array:");
scanf("%d", &Size);
printf("\n Please Enter %d elements of an Array\n", Size);
for (i = 0; i < Size; i++)
{
scanf("%d", &arr[i]);
FreqArr[i] = -1;
}
for (i = 0; i < Size; i++)
{
Count = 1;
for(j = i + 1; j < Size; j++)
{
if(arr[i] == arr[j])
{
Count++;
FreqArr[j] = 0;
}
}
if(FreqArr[i] != 0)
{
FreqArr[i] = Count;
}
}
printf("\n List of Unique Array Elemnts in this Array are : ");
for (i = 0; i < Size; i++)
{
if(FreqArr[i] == 1)
{
printf("%d\t", arr[i]);
}
}
return 0;
}
Program 8: Write a C program to count the occurrence of each element in
the array list.
Solution:
#include <stdio.h>
int main()
{
int arr1[100], fr1[100];
int n, i, j, ctr;
printf("\n Input the number of elements to be stored in the array :");
scanf("%d",&n);
if(fr1[i]!=0)
{
fr1[i] = ctr;
}
}
printf("\n The frequency of all elements of array \n");
for(i=0; i<n; i++)
{
if(fr1[i]!=0)
{
printf("\n %d occurs %d times", arr1[i], fr1[i]);
}
}
return 0;
}
Program 9: Write a c program to separate the Odd and Even numbers from
the array list and print them.
Solution:
#include <stdio.h>
int main()
{
int arr1[10], arr2[10], arr3[10];
int i,j=0,k=0,n;
printf("\n Input the number of elements to be stored in the array :");
scanf("%d",&n);
printf("\n Input %d elements one by one \n",n);
for(i=0;i<n;i++)
{
printf("element - %d : ",i);
scanf("%d",&arr1[i]);
}
for(i=0;i<n;i++)
{
if (arr1[i]%2 == 0)
{
arr2[j] = arr1[i];
j++;
}
else
{
arr3[k] = arr1[i];
k++;
}
}
s3 = s1 + s2;
for(i=0;i<s1; i++)
{
arr3[i] = arr1[i];
}
for(j=0;j<s2; j++)
{
arr3[i] = arr2[j];
i++;
}
for(i=0;i<s3; i++)
{
for(k=0;k<s3-1;k++)
{
if(arr3[k]<=arr3[k+1])
{
j=arr3[k+1];
arr3[k+1]=arr3[k];
arr3[k]=j;
}
}
}