Friday, 3 October 2014

Write a C++ statements

Leave a Comment

Write a C++ statement to accomplish each of the following task:
  1. Declare variables sum and x to be of type int.
  2. Initialize variable x to 1.
  3. Initialize variable sum to 0
  4. Add variable x to variable sum and assign the result to variable sum.
  5. Print "The sum is: " followed by the value of variable sum .

Solution

  1. int sum, x;
  2. x = 1;
  3. sum = 0;
  4. sum += x;
  5. cout << "The sum is: " << sum << endl;
If You Enjoyed This, Take 5 Seconds To Share It

0 Questions: