I want to make sure I did everything possible! Program is C! Many thanks 1. (100
ID: 3814410 • Letter: I
Question
I want to make sure I did everything possible! Program is C! Many thanks 1. (100 pts) Dowload the file assignbonus.c from class webpage and reduce the size of the file without changing the functionality. The two programs should do the same thing but the new file should be shorter. To find the number of characters in the file use the wc command as follows WC c assign bonus .c Original file has 895 characters in it. You can use the following techniques to reduce the size. Remove comments. Declare all variables of one type on one line. Reuse variables instead of declaring new variables. Use operators like instead of using and Other things that you can think of. Once you do all the reductions you can think of, look at the size of the executable file for the original file and new file and see how they differ.Explanation / Answer
Seems like some part of it is already done. You need to remove comments, declare variable at one place, and other things
here is fixed code
#include <stdio.h>
#include <math.h>
int main()
{
int i=1, j=1, k=1, sum1=0, sum3=0, n;
float sum2 = 0;
printf("Enter n: ");
scanf("%d", &n);
for(;k<=n; k++)
sum1 += k*k*k;
printf("For loop ");
printf(" Loop Result = %d ",sum1);
printf(" Formula = %d ", n*n*(n+1)*(n+1)/4);
while(i<=n)
{
sum2+= 1.0/(pow(2.0,i));
i++;
}
printf("While Loop ");
printf(" Loop Result = %d ", sum2);
printf(" Formula = %d ", 1-1.0/pow(2,n));
do
{
sum3 += j*(j+1);
j++;
} while(j<=n);
printf("Do while Loop ");
printf(" Loop Result = %d ",sum3);
printf(" Forumla = %d ", n*(n+1)*(n+2)/3);
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.