Question

In: Computer Science

using c language: create an array of the values of a sine wave. Include the math.h...

using c language:

create an array of the values of a sine wave. Include the math.h header to use the sin floating point function. The function sin takes an argument of radians (not degrees). Make your array721 elements and initialize each element with 10 * sin(2*3.1416* (i/360.0) where i is the array index from 0 - 720. When done properly, the array should contain approximately 2 complete sine wave cycles. Similarly, create an array of 721 elements only this time initialize it with a cosine function with amplitude 5 Have the program process and compute the following (in the order given); display the title of the action and answers on the screen: The maximum value of the cos and sin array added together. The mean value of the sin array The mean value of the element by element product of the sin and cos. The median value of the cos array. The dot product of the cos and sin array. The dot product of a reversed cos array with a sin array.

Solutions

Expert Solution

Note: Done accordingly. Please comment for any problem. Please Uprate. Thanks.

Code:


#include<stdio.h>
#include<math.h>
#include<conio.h>
#define SIZE 721
void sort(double *array , int size)
{
// declare some local variables
int i=0 , j=0;
   double temp=0;

for(i=0 ; i<size ; i++)
{
for(j=0 ; j<size-1 ; j++)
{
if(array[j]>array[j+1])
{
temp = array[j];
array[j] = array[j+1];
array[j+1] = temp;
}
}
}
}

double findMean(double arr[],int size){
   double sum=0;
   int i;
   for(i=0;i<size;i++){
       sum=sum+arr[i];
   }
   sum=sum/size;
   return sum;
}

void printArray(double arr[],int size){
   int i;
   for(i=0;i<size;i++){
       printf("%lf ",arr[i]);
   }
}
double findMedian(double arr[],int size){
   double median=0;
double* temp=arr;
   sort(temp,size);
  
   // if number of elements are even
if(size%2 == 0)
median = (temp[(size-1)/2] + temp[size/2])/2.0;
// if number of elements are odd
else
median = temp[size/2];
  
return median;

}

double findMax(double arr[],double size){
   double max=arr[0];
   int i;
   for(i=0;i<size;i++){
       if(max<arr[i])
           max=arr[i];
   }
   return max;
}

double findDotProduct(double arr1[],double arr2[],double size){
   double product=0;
   int i;
   for(i=0;i<size;i++){
       product=product+arr1[i]*arr2[i];
   }
   return product;
}

void main(){
   double max[SIZE];
   double cosArr[SIZE];
   double sinArr[SIZE];
   double elementByElementProductArr[SIZE];
   double addedValues[SIZE];
   double reversedCosArr[SIZE];
   int i=0;
   for(i=0;i<SIZE;i++){
       sinArr[i]=(10 * sin(2*3.1416*(i/360.0)));
       cosArr[i]=(10 * cos(2*3.1416*(i/360.0)));
       addedValues[i]=sinArr[i]+cosArr[i];
       elementByElementProductArr[i]=sinArr[i]*cosArr[i];
   }

   for(i=0;i<SIZE;i++){
       reversedCosArr[i]=cosArr[SIZE-i-1];
   }
   //The maximum value of the cos and sin array added together.
   printf("The maximum value of the cos and sin array added together : %lf \n",findMax(addedValues,SIZE));
   //The mean value of the sin array
   printf("The mean value of the sin array : %lf\n",findMean(sinArr,SIZE));
   //The mean value of the element by element product of the sin and cos.
   printf("The mean value of the element by element product of the sin and cos. : %lf\n",findMean(elementByElementProductArr,SIZE));
   //The median value of the cos array.
   printf("The median value of the cos array. : %lf\n",findMedian(cosArr,SIZE));
   //The dot product of the cos and sin array.
   printf("The dot product of the cos and sin array. : %lf\n",findDotProduct(cosArr,sinArr,SIZE));
   //The dot product of a reversed cos array with a sin array.
   printf("The dot product of a reversed cos array with a sin array. : %lf\n",findDotProduct(reversedCosArr,sinArr,SIZE));
   getch();
}


Related Solutions

Using C++ language, create a program that uses a struct with array variables that will loop...
Using C++ language, create a program that uses a struct with array variables that will loop at least 3 times and get the below information: First Name Last Name Job Title Employee Number Hours Worked Hourly Wage Number of Deductions Claimed Then, determine if the person is entitled to overtime and gross pay. Afterwards, determine the tax and net pay. Output everything to the screen. Use functions wherever possible. Bonus Points: Use an input file to read in an unknown...
Write a statement to call prepare Arr to set values for the array (Using C++) #include...
Write a statement to call prepare Arr to set values for the array (Using C++) #include using namespace std; const int NUM = 10; void prepareArr(int a[]); int countEven (int b[]); int main() { int arr[NUM]; // write a statement to call prepareArr to set values for the array // write a statement to call countEven and print the data returned for(int i = 0; i cout << arr[i] <<" "; cout < return 0; } void prepareArr(int a[]) {...
In C# using a Console App, create an array that stores 20 integer values. Use the...
In C# using a Console App, create an array that stores 20 integer values. Use the random number generator to select an integer value between 0 and 10. Store the 20 random integers in the array. Once the array has been created: Print the values in the array. Print the values in the array in reverse order. Sort and print the values in the array in ascending order. Sort and print the values in the array in descending order. Count...
*C PROGRAMMING LANGUAGE* a) Given an array of size n, sort the array using pointers using...
*C PROGRAMMING LANGUAGE* a) Given an array of size n, sort the array using pointers using malloc or calloc. Examples: Input: n = 5, A= {33,21,2,55,4} Output: {2,4,21,33,55} b) Write a function that declares an array of 256 doubles and initializes each element in the array to have a value equal to half of the index of that element. That is, the value at index 0 should be 0.0, the value at index 1 should be 0.5, the value at...
c++ language Create a file program that reads an int type Array size 10; the array...
c++ language Create a file program that reads an int type Array size 10; the array has already 10 numbers, but your job is to resize the array, copy old elements of array to the new one and make it user input and add an additional 5 slots in the array, and lastly do binary search based on user input. close the file.
MUST BE DONE IN C (NOT C++) Using an array and a function, print the values...
MUST BE DONE IN C (NOT C++) Using an array and a function, print the values of an array backwards. Please follow these guidelines: - Setup your array manually (whichever values you want, as many as you want and whichever datatype you prefer). - Call your function. You should send two parameters to such function: the array’s length and the array. - Inside the function, go ahead and print the array backwards. - Your function shouldn’t return anything
Please Solve with c language Create 5-by-5 integer array. Initialize the elements of the array starting...
Please Solve with c language Create 5-by-5 integer array. Initialize the elements of the array starting from 1. Your element [0][0] should be equal to 1; element[4][4] should be equal 25. Print the array. The output should have 5 rows and 5 columns. Specify the width for each output to demonstrate the table in a formatted view. Change the value of the elements: 2nd row 4th column to 24, 1st row 3rd column to 13. Print the array again. Find...
C Language NO ARRAY UTILIZATION OR SORTING Create a .txt file with 20 integers in the...
C Language NO ARRAY UTILIZATION OR SORTING Create a .txt file with 20 integers in the range of 0 to 100. There may be repeats. The numbers must not be ordered/sorted. The task is to find and print the two smallest numbers. You must accomplish this task without sorting the file and without using arrays for any purpose. It is possible that the smallest numbers are repeated – you should print the number of occurrences of the two smallest numbers....
In C Programing Create a stack using an array. Define the index variable of the array...
In C Programing Create a stack using an array. Define the index variable of the array name to be stacktop. Initially set stacktop to -1. Next create two functions push and pop. Both take as input 3 items: a pointer to the stack in memory, stacktop, and maxstack. Make sure to inc stacktop by one and also remember that stacktop[0] is the bottom of the stack and by stack rule cannot be accessed until all the other items are popped....
Using C language: Write a program that asks the user for the size of an array,...
Using C language: Write a program that asks the user for the size of an array, then reads a number of integer values (from user input) into the array. Write a function to print out the array and call it to print the array out after all values are read in. Write a function to implement Insertion Sort and run it on the data array to sort the array. Write another function to implement Selection Sort and run it on...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT