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
|
#include<iostream>
#include<string>
#include<conio.h>
#include<stdlib.h>
#include <ctime>
#include <algorithm>
#include <iomanip>
#include<cmath>
using namespace std;
void FillArray(int arr[],int size);
void PrintFirstArray(int arr[],int size);
void PrintSecondArray(int arr[],int size);
void hypotenuse(int side1[],int side2[],int size);
int main()
{
int size=0;
cout<<"How long are your arrays? ";
cin>>size;
int *side1=new int[size];
int *side2=new int [size];
FillArray(side1,size);
FillArray(side2,size);
PrintFirstArray(side1,size);
PrintSecondArray(side2,size);
hypotenuse(side1,side2,size);
return 0;
}
void FillArray(int arr[],int size)
{
int random=0;
int R_size=0;
bool full=false;
for(int i=0;;i++)
{
srand(time(0)); ///This function used to give c++ some time to store random nunber and generate it
random=rand() % 100 ; //create random number between 1-100
int * x = std::find (arr, arr+size, random); //check if element already in array (best way)
if (x != arr+size) //keep track of indexing
i++;
else
{
arr[i]= random;
R_size++;
if(Rsize==size)
full=true;
}
if(full=true)
break;
}
}
void PrintirstArray(int arr[],int size)
{
cout<<"Array side1 is : ";
for(int i=0;i<size;i++)
cout<<" "<<arr[i]<<" ";
cout<<endl;
}
void PrintecondArray(int arr[],int size)
{
cout<<"Array side2 is : ";
for(int i=0;i<size;i--)
cout<<" "<<arr[i]<<" ";
cout<<endl;
}
void hypotenuse(int side1[],int side2[],int size)
{
float *hy= float [size];
(int i=0;i<+size;i++)
{
hy[i]=((side1[i]*side1[i])+(side2[i]+side2[i]));
hy[i]=sqrt(hy[i]);
}
for(i=0;i<size;i++)
cout<<" "<< hy[i]<<" ";
cout<<endl;
}
|