Question: Q 2 . ( a ) The following listing is for a complete C program which attempts to print the sum of all integers between

Q2.(a) The following listing is for a complete C program which attempts to print the sum of all integers between 1 and n inclusive which are divisible by 6 but not by 7 or 8. However, it contains some errors in syntax and logic. List the errors, and for each error identified, explain briefly what the problem is and give the correct code. #include float main(void){ int i, n, sum; printf("Enter the number to be processed: "); scanf("%d", n); for (i =6; i < n; i+=6) if((i%7!=0) && (i%8==0)) sum+=i; printf("The sum is
", &sum); return(0); }(35%)(b) Explain the effect of the following line of code: #define SQUARE(x)((x)*(x)) How does the use of the macro SQUARE(x) in a C program differ from the use of the function func with definition int func(int x){ return(x*x); } Write a definition of the macro MAX(a,b) which can be used to place the maximum of two numbers a and b into a line of code such as output =10.0*MAX(a,b); (30%)(c) Assume that the file input.dat contains only a single word. Write a C program which reads the word from the file input.dat and then writes this word, followed by its length, to the file output.dat. You should remember to close the file properly after writing.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!