You are here:

C++/C++ question

Advertisement


Question
I need a tip on how to add multiple numbers from only one entry.
Example, if I have the user enter the number 10, I want it to get the sum of all numbers(1+2+3+4+5+6+7+8+9+10 = 55).

Thanks,
AC

Answer
Hi Dear Ac,

Sorry for the delay in responding you , please find the simple programme that meets your requirement.

#include<iostream.h>

int main()
{
  int no;
  int sum = 0;
  cout<<"Enter a no :";
  cin>>no;

  for ( int i = 1 ; i<=no ; i++)
     sum+= i;
  cout<<"Generated sum = "<<sum;
  return 0;
}

please do observe the working of for loop and and customize the code as you wish.

Get back to me if you require more support

Thanks and Regards
Prince M. Premnath

C++

All Answers


Answers by Expert:


Ask Experts

Volunteer


Prince M. Premnath

Expertise

Years of research in C/C++ Will bring you all facts regarding , OOPS , SVGA , MOUSE , BIOS , IVT , Feel free to query me :-)

Experience

More than 5 years

Education/Credentials
MCA

©2012 About.com, a part of The New York Times Company. All rights reserved.