Question
3.4 Write a C statement to accomplish each of the following tasks. a) Define variables sum and x to be of type int. b) Set
3.4 Write a C statement to accomplish each of the following tasks. a) Define variables sum and x to be of type int. b) Set variable x to 1. c) Set variable sum to 0. d) Add variable x to variable sum and assign the result to variable sum. e) Print " The sum is: " followed by the value of variable sum. 3.10 (or 3.11 for 6th edition) Identify and correct the errors in each of the following. [ Note: There may be more than one error in each piece of code.] a) if ( age >= 65 ); puts( " Age is greater than or equal to 65" ); else puts( " Age is less than 65" ); b) int x = 1, total; while ( x <= 10 ) { total += x; ++ x; } c) While ( x <= 100 ) total += x; ++ x; d) while ( y > 0 ) { printf( "% d\ n", y ); ++ y; } Program: 3.5: Combine the statements that you wrote in Exercise 3.4 into a program that calculates the sum of the integers from 1 to 10. Use the while statement to loop through the calculation and in-crement statements. The loop should terminate when the value of x becomes 11.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started