1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
|
#include <iostream>
#include <fstream>
using namespace std;
ifstream inF;
int ArrayA(ofstream& outF, ifstream& inF, int x, int n)
{
inF.open("numbers2.in");
for(x=0;x<n;x++)
inF>>ArrayA[x];
return ArrayA[];
}
int ArrayB(ofstream& outF,int x)
{
for(x=0;x<n;x++)
ArrayB[25]=rand()%100+1;
out<<ArrayB[x];
return ArrayB[];
}
void printArray(int arr[], int n, ofstream& outF)
{
int x=0;
for(x=0;x<n;x++)
out<<arr[x]<<" \n";
}
void Add(int a[], int b[], int c[], int n, ofstream& outF)
{
int x=0;
for(x=0;x<n;x++)
c[x]=a[x]+b[x];
}
void Product(int a[], int b[], int c[], int n, ofstream& outF)
{
int x=0;
for(x=0;x<n;x++)
c[x]=a[x]*b[x];
}
void Average(int a[], int n, ofstream& outF)
{
float sum=0;
int x=0;
for(x=0;x<n;x++)
sum+=a[x];
out<<(sum*1.0)/n<<" \n";
}
void Largest(int arr[], int n, ofstream& outF)
{
int max=-1, x=0;
for(x=0;x<n;x++)
if(arr[x]>max)
max=arr[x];
out<<max<<" \n";
}
void Smallest(int arr[], int n, ofstream& outF)
{
int min=999, x=0;
for(x=0;x<n;x++)
if(arr[x]<min)
min=arr[x];
out<<min<<" \n";
}
void Avg_Odd(int arr[], int n, ofstream& outF)
{
int count=0, sum=0, x=0;
for(x=0;x<n;x++)
if(arr[x]%2==1)
sum+=arr[x];
count++;
out<<(sum*1.0)/count<<" \n";
}
int main()
{
ofstream outF;
outF.open("operation.out");
int A[25], B[25], C[25], x=0;
out<<"array A has :\n ";printArray(A,25);
out<<"array B has :\n ";printArray(B,25);
Add(A,B,C,25);
out<<"array C when A,B are added:\n";printArray(C,25);
Product(A,B,C,25);
out<<"array C when A,B are Multiplied:\n";printArray(C,25);
out<<"Average of array A is:";Average(A,25);
out<<"Average of array B is:";Average(B,25);
out<<"largest number in array A is:";Largest(A,25);
out<<"largest number in array B is:";Largest(B,25);
out<<"smallest number in array A is:";Smallest(A,25);
out<<"smallest number in array B is:";Smallest(B,25);
out<<"Average of odd numbers in array A is:";Avg_Odd(A,25);
out<<"Average of odd numbers in array B is: ";Avg_Odd(B,25);
out.close();
in.close();
return 0;
}
|