Share Pastebin
Guest
Public paste!

ashraf

By: a guest | Feb 9th, 2010 | Syntax: C++ | Size: 0.55 KB | Hits: 29 | Expires: Never
Copy text to clipboard
  1. #include "stdafx.h"
  2. #include <iostream>
  3. #include <stdlib.h>
  4. #include <stdio.h>
  5. using namespace std;
  6.  
  7. int squares(int num);
  8.  
  9. int main()
  10. {
  11.         int num;
  12.   int sqsum;
  13.  
  14. do
  15. {
  16.   cout << "Enter an integer larger than 1: " <<endl;
  17.   cin >> num;
  18.  
  19.   sqsum=squares(num);
  20.  
  21.   cout << "The input value is: " << num << endl;
  22.   cout << "The sum of the squares for " << num << " is " << sqsum << endl;
  23.   cout << endl;
  24.  
  25. }
  26.  while (num != 1);
  27. }
  28.  
  29.  
  30. int squares(int num)
  31. {
  32.         int sum = 0;
  33.         sum = num*num;
  34.         if (num != 0)
  35.                 return (squares(num-1) + sum);
  36.  
  37. }