cplusplus
.com
TUTORIALS
REFERENCE
ARTICLES
FORUM
C++
Tutorials
Reference
Articles
Forum
Forum
Beginners
Windows Programming
UNIX/Linux Programming
General C++ Programming
Lounge
Jobs
Forum
General C++ Programming
need help about math c++
need help about math c++
Apr 17, 2020 at 12:09pm UTC
kianarahma
(2)
hello, i am currently new in programming. So I made a program to basically calculate 2^n (n user input)
#include <iostream>
#include <math.h>
using namespace std;
int main(){
int i, n;
cout << "Enter a number : ";
cin >> n;
for(i=1; i<=n; i++){
cout <<pow(2,i) << " " << endl;
}
}
for example, if I input 4, it will shows 2 4 8 16, my questions is
what syntax do I need to add in order to calculate all those numbers?
(2 + 4 + 8 + 16 = ? )
thank you
Apr 17, 2020 at 12:12pm UTC
salem c
(3700)
Maybe
sum += pow(2,i);
Topic archived. No new replies allowed.