```
hi.. i am trying want to solve this
Write a complete program that reads 11 integers from a file called ‘file.txt’ and stores them in an array. Your program should then remove the duplicated numbers, find and print the sum of all the even numbers in the array as well as the sum of all the odd numbers in the array and then decides and prints the which sum is larger.
Your program should at least have the following functions:
1- Function remove_dup which removes duplicated elements from the array.
2- Function even_sum which takes an array and returns the sum of the even numbers in it.
3- Function odd_sum which takes an array and returns the sum of the odd numbers in it.
Example of a single run of the program:
Array filled from a file: 1 15 7 2 13 12 7 15 4 8 2
Array after removing duplicated numbers: 1 15 7 2 13 12 4 8
Sum of even numbers = 26
Sum of odd numbers = 36
The sum of odd numbers is greater
here is my code but let us write the numbers without file to check first
#include <stdio.h>
#define s 4
void remove_dup (int [],int);
void FA(int [],int);
int even_sum (int [],int);
int odd_sum (int [],int);
int main()
{
int A[s];
int i;
for (i=0;i<s;i++)
{
printf ("enter number\n");
scanf ("%d",&A[i]);
}
remove_dup(A,s);
return 0;
}
void remove_dup(int A[],int n)
{
int i,j,index,flag=0;
int count=0;
for (i=0;i<n-1;i++)
{
for (j=i+1;j<n;j++)
{
if (A[i]!=-1&& A[j]!=-1 && A[j]==A[i]){
A[j]=-1;
index = i ;
count= count + 1 ;
flag = 1 ;
}
}
if (flag == 1){
A[index]=-1 ;
count++;
}
}
for(i=0;i<s;i++)
printf("%d \n",A[i]);
n=n-count;
FA(A,n);
//printf("\n%d\n" , count);
}
void FA (int A[],int n)
{
int B[n];
int c=0;
int k,es,os;
printf ("Array after removing duplicated numbers: ");
for (k=0;k<s;k++)
{
if (A[k]!=-1)
{
B[c]=A[k];
c++;
printf ("%d ",B[c]);
}
}
es=even_sum(B,n);
os=odd_sum(B,n);
printf("\nSum of even numbers = %d\n",es);
printf("Sum of odd numbers = %d\n",os);
if (os>es)
printf ("The sum of odd numbers is greater");
else if (es>os)
printf ("The sum of even numbers is greater");
else printf ("The sum of odd numbers = The sum of even numbers");
}
int even_sum(int B[],int n)
{
int i;
int sum=0;
for (i=0;i<n;i++)
{
if (B[i]%2==0)
sum+=B[i];
}
return sum;
}
int odd_sum(int B[],int n)
{
int i;
int sum=0;
for (i=0;i<n;i++)
{
if (B[i]%2!=0)
sum+=B[i];
}
return sum;
}
//
there are problems in writing the array after removing duplicated numbers it prints such stubid numbers "5465465021"
and a broblem with the counter..
i need to fix it today help plzz..
thxx
note : there are some print codes to check if things correct.. as the one prints the array after first change to -1 and others..
```

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.