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
|
#include <iostream>
#include <cstdlib>
#include <cmath>
using namespace std;
void create_array(double arr[], int size_arr, double k);
void display_array(double arr[], int size_arr, int a, int b);
void create2_array(double arr[], int size_array, double sum);
void display2_array(double arr[], int size_arr, double sum);
int main()
{
cout << "9A" << endl;
const int array_size=150;
double B[array_size]={0};
double x;
double summ;
cout<<"type in x value: "; cin>>x; cout<<endl;
create_array(B,array_size,x);
display_array(B,array_size,149,0);
create2_array(B,array_size,summ);
display2_array(B,array_size,summ);
cout<<endl;
return 0;
}
void create_array(double arr[], int size_arr, double k)
{
for(int i=0; i<size_arr; i++)
{
arr[i]=((i+1)/(k))*pow(-1,i);
}
}
void display_array(double arr[], int size_arr, int a, int b)
{
cout<<endl;
for(int i=size_arr-1; i>=0; i--)
{
cout<<arr[i]<<" ";
}
}
void create2_array(double arr[], int size_arr, double sum)
{
for(int i=size_arr-1; i<=0; i--)
{
sum=0;
if(arr[i]<0)
{
sum=sum+arr[i];
}
}
}
void display2_array(double arr[], int size_arr, double sum)
{
cout<<endl;
cout<<endl;
{
cout<<"SUM of all elements less than zero: "<<sum;
}
}
|