Question

Given the following function prototypes: float asciiAvg(char mystring[], int length); Write the function definition. The asciiAvg...

Given the following function prototypes: float asciiAvg(char mystring[], int length); Write the function definition. The asciiAvg function should return the average of the ascii values for the characters in the array mystring of length characters.

Homework Answers

Answer #1
#include <stdio.h>

float asciiAvg(char mystring[], int length);

int main() {
    printf("%f\n", asciiAvg("Hello", 5));
    return 0;
}

float asciiAvg(char mystring[], int length) {
    int total = 0;
    int i = 0;
    while (mystring[i]) {   // go through each character
        total += (int) mystring[i]; // add character to total
        i++;    // move to next character
    }
    return (float) total / (float) length;  // find the average and return
}

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
/************************************************************************************* Function Prototypes *************************************************************************************/ int ScanArray(char *fname, int myArray[], int nSize); void Ge
/************************************************************************************* Function Prototypes *************************************************************************************/ int ScanArray(char *fname, int myArray[], int nSize); void GenerateFromArray(void); /************************************************************************************/ /************************************************************************************/ int main(void) { /* This is the main() program. It should call the functions ScanArray() and GenerateFromArray() */ GenerateFromArray(); system("pause"); return 0; } /*************************************************************************************** Define this function to scan the elements of an array from the given data file "ArrayInp.dat". If the input file is not found, or contains invalid data, the function should return a 0 and print an error message. If the input...
Fill in the code for the function below called containsAvgValue. It takes as input a float...
Fill in the code for the function below called containsAvgValue. It takes as input a float array of any length and returns 1 if the array happens to contain a value that equals the average of all the values in the array or 0 otherwise. For example, when give the array [2.0, 2.0] it should return 1 since the average value is 2.0 and the array contains that value. To help you, I’ve included a function that computes the average...
Write a function called read floats(int n) that reads n float values from the user into...
Write a function called read floats(int n) that reads n float values from the user into an array and return the array back to the caller. Recall that a regular array will get deallocated when the function returns. (C++ the simplier the better)
Write any 2 C programs of a structure having return type int, char, float. Explain each...
Write any 2 C programs of a structure having return type int, char, float. Explain each step for both the programs. The code should be simple as I am a beginner. Also, I need an urgent answer.
IN C++ struct elementType{      int integer;      float decimal;    char ch; }; struct nodeType{...
IN C++ struct elementType{      int integer;      float decimal;    char ch; }; struct nodeType{    elementType e;    nodeType* link: }; Write a member functions that will find the range of values in a singly linked list. The range is returned to the calling function. PLEASE USE THE STRUCT ABOVE
Write a function int count_consonants(char str[]) that determines and returns the number of consonants in a...
Write a function int count_consonants(char str[]) that determines and returns the number of consonants in a given string. Then write a simple main() function where you can repeatedly enter a string and then the num- ber of consonants is determined and printed on the screen (from the main() function). If the entered string is empty (it will contain only a ’\n’ then) the program should stop its execution. You can safely assume that the entered string will be not longer...
You're given the type length = In of float | Cm of float. Write an OCaml...
You're given the type length = In of float | Cm of float. Write an OCaml function addlen(x,y) that adds two lengths. If x is in inches, the sum should be in inches; if x is in centimeters, the sum should be in centimeters.
float sum( float x, float y, float z ) ​program in c++
Here are the function prototypes for your homeworkWrite out the actual functions themselves Also, create a main function that demonstrates that all four functions work The user should be able to provide four values to your program (three floats and an int) Your program should then use your four new functions and also display the results to the user NONE of these functions should print values themselvesfloat sum( float x, float y, float z ); // returns the sum of three floatsfloat mean( float...
C programming Write a function that takes in a 2D char array (string array) and return...
C programming Write a function that takes in a 2D char array (string array) and return a 1D char array with all the elements connected together Hint: strlen(-char*-) //returns the length of a string strcat(-char* accum-, something to add) //works like string+= in java
Experience with Functions Are the following statements a function header, a prototype or a function call?...
Experience with Functions Are the following statements a function header, a prototype or a function call? double calcMonthlyPmt(double amt); void displayResults() void showMenu(); showNum(45.67); area = CalArea(5,10); Write the function calls for the following headers and prototypes: void showValue(int quantity) void display(int arg1, double arg2, char arg3); pass the following to the call: int age; double income; char initial double calPay(int hours, double rate); What is the output of the following program? #include <iostream> using namespace std; void showDouble(int); //Function...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT