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.
#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 }
Get Answers For Free
Most questions answered within 1 hours.