Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please use C language. Also, if you can add head notes to explain what is being

ID: 3824568 • Letter: P

Question

Please use C language. Also, if you can add head notes to explain what is being done. Thank you in advance!

CS 1713 Introduction to Computer Programming II Bonus Assignment Due Wednesday April 26 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 Submit your program electronically using the blackboard system The program you submit should be your oum work. Cheating will be reported to office of academic integrity. Both the copier and copiee will be held responsible.

Explanation / Answer

Below is the program now. I have removed variable j,k,sum3 as i reused i and sum1 instead.

Declared all variables in a single line.

Also modified 3 printf statements into one.

removed sum1 = sum1 + i*(i+1) to sum += i*(i+1).

I have added comments sections in the program what i have done. you can remove that comments section once you understand.

---------------------------------------------------------------

#include <stdio.h>
#include <math.h>

int main()
{
//I have declared variables in single line you can delete this comment section
//removed variable j,k,sum3 bec i will reuse i and sum1 instead
int i,sum1,n;
float sum2;
    
printf("Enter n: ");
scanf("%d",&n);


sum1 = 0;
for (i=1;i<=n;i++)
      sum1 += i*i*i;    //reduced assignement = to +=

printf("For Loop Loop Result = %d Formula = %d ",sum1,n*n*(n+1)*(n+1)/4); //added 3 printf lines to one

sum2 = 0;
i = 1;
while (i<=n)
    {
      sum2 += 1.0/(pow(2.0,i));
      i = i+1;
    }

printf("While Loop Loop Result = %f Formula = %f ",sum2,1-1.0/pow(2,n)); //added 3 printf lines to one
sum1 = 0;
i = 1;
do
    {
      sum1 += i*(i+1); //removed assignment to +=
      i = i+1;
    } while (i<=n);

printf("Do while Loop Loop Result = %d Formula = %d ",sum1,n*(n+1)*(n+2)/3); //added 3 printf lines to one
return 0;
}

If you have any questions. Please Comment.