to calculate square and cube form given input using arrays..

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Dec 2007
Posts: 113
Reputation: abhi_elementx is an unknown quantity at this point 
Solved Threads: 6
abhi_elementx's Avatar
abhi_elementx abhi_elementx is offline Offline
Junior Poster
 
0
  #11
Nov 10th, 2009
This should work now. You gotta learn arrays, passing arrays to functions, returning arrays, etc. profoundly in order to master arrays.

  1. #include <cstdlib>
  2. #include <iostream>
  3. #include <iomanip>
  4. #include <cmath>
  5.  
  6.  
  7. using namespace std;
  8. const int size = 10;
  9. void square_store (int [], int []);
  10. void read_numbers (int []);
  11. void cube_store (int [], int []);
  12.  
  13. int main(int argc, char *argv[]){
  14. const int size = 10;
  15. static int values[size], square_array [size], cube_array[size];
  16. int i [size];
  17.  
  18. read_numbers (values);
  19. square_store (square_array, values);
  20. cube_store (cube_array, values);
  21.  
  22. cout << "\n\n";
  23. system("PAUSE");
  24. return EXIT_SUCCESS;
  25. }//main() ends
  26.  
  27. void read_numbers (int values[]){
  28. int index;
  29. cout << "Enter 10 numbers:\n";
  30. for (index = 0; index < size; index++)
  31. cin >> values [index];
  32. }//read_numbers() ends
  33.  
  34. void square_store (int square_array[], int values[]){
  35.  
  36. int index;
  37. cout << "\nThe square of your input numbers are:\n";
  38. for (index = 0; index < size; index++){
  39. square_array [index] = values [index] * values [index];
  40. cout << "\n\n";
  41. cout << "Square is ---> " << square_array [index];
  42. }
  43. }//square_store() ends
  44.  
  45. void cube_store ( int cube_array[], int values[]){
  46. int i;
  47. cout << "\n\nThe cubes of the numbers are:\n";
  48. for (i = 0; i < size; i++){
  49. cube_array [i] = values [i] * values [i] * values [i];
  50. cout << "\n\n";
  51. cout << "Cube is ---> " << cube_array[i];
  52. }
  53. }//cube_store() ends

As pointed by jonsca, there are many tuts/ebboks on the 'firehose of information'(the Internet).

Cheers
PEACE !
Reply With Quote Quick reply to this message  
Reply

Message:




Views: 451 | Replies: 10
Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC