C++ question

Last Edited By Krjb Donovan
Last Updated: Mar 11, 2014 07:51 PM GMT

QuestionEdit

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

AnswerEdit

Hi Dear Ac,

Sorry for the delay in responding you , please find the simple programme that meets your requirement.
  1. 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

Advertisement

©2024 eLuminary LLC. All rights reserved.