Rewrite this code fragment to improve its efficiency Find at


Rewrite this code fragment to improve its efficiency. Find at least 2 improvements. Find the integer sum of four successive characters and compare to UserSum Rewrite the improved code fragment below (assume the character array a has more than 4 elements)

Solution

//improvement 1 calculating length so that it does not calculate the length every time of loop

Length=strlen(a)-4;

isum=0;

for(i=0;i<length;++i){//improvement no2 applying loop for calculation

for(j=i;j<i+4;j++){

isum=isum+a[j];

if(isum==atoi(iUserSum))

printf(\"Match at %d\ \",i);

}

}

 Rewrite this code fragment to improve its efficiency. Find at least 2 improvements. Find the integer sum of four successive characters and compare to UserSum R

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site