
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
C++ Program for Cube Sum of First N Natural Numbers
Positive integers 1, 2, 3, 4... are known as natural numbers.
This program takes a positive integer from the user ( suppose user-entered n ) then, this program displays the value of 13+23+33+....+n3.
Input: n = 3 Output: 36
Explanation
13+23+33 = 1 +8+27 = 36
This program takes a positive integer from user( suppose user entered n ) then, this program displays the value of 13+23+33+....+n3.
Example
#include <iostream> using namespace std; int main() { int n = 3; int sum = 0; for (int x=1; x<=n; x++) sum += x*x*x; cout << sum; return 0; }
Advertisements