codepad
[
create a new paste
]
login
|
about
Language:
C
C++
D
Haskell
Lua
OCaml
PHP
Perl
Plain Text
Python
Ruby
Scheme
Tcl
/**************************************/ /* Lukasz Koziol Assignment #3 */ /* CIS 1.5 MW9 03-07-10 */ /* */ /**************************************/ #include <iostream> #include <math.h> #include <iomanip> using namespace std; int SumOfSquares(int a); int SumOfCubes(int b); int SumOfSqroots(int c); int Prime(int d); int main() { cout.setf(ios::fixed,ios::floatfield); int numb=5,avg=0, avgsqr=0, avgcub=0, numbprime=0, primenumb=0,numb5=0,numb110=0; cout << "NUMBERS" << "\t" << "SUMSQ" << "\t" << "SUMCB" <<"\t" << "SUMSQRT" << "\t" << "PRIME" << endl; while (numb<=49) { cout << numb; cout <<"\t" << setprecision(2) << SumOfSquares(numb); cout <<"\t" << setprecision(2) << SumOfCubes(numb); cout <<"\t" << setprecision(2) << SumOfSqroots(numb); if (Prime(numb)){ cout << "\t" <<"*"; } else { cout << "\t" <<" "; } numb = numb + 2; avg=(numb/23); avgsqr=(SumOfSquares(numb)/23); avgcub=(SumOfCubes(numb)/23); //numbprime= cout<<endl; } cout <<endl; cout << "The average of the number is " << "'" << avg <<"'" << endl; cout << "The average of the sum of squares is " << "'" << avgsqr <<"'" << endl; cout << "The average of the sum of cubes is " << "'" << avgcub <<"'" << endl; cout << "The number of prime numbers is " << "'" << primenumb <<"'" << endl; cout << "The number of numbers for which the sum of cubes is more than 5 times the sum of squares is " << "'" << numb5 <<"'" << endl; cout << "The number of numbers for which the sum of the suare roots is greater than 1/10 of the number is " << "'" << numb110 <<"'" << endl; system ("pause"); return 0; } // Sum Of Squares int SumOfSquares(int a) { int sum=0; for (int i = 1; i <= a; i++){ sum+=i*i; } return sum; } // Divisible by 5 int SumOfCubes(int b) { int sum=0; for (int i = 1; i <= b; i++){ sum+=i*i*i; } return sum; } int SumOfSqroots(int c) { int sum=0; for (int i = 1; i <= c; i++){ sum+=i^2; } return sum; } int Prime(int d) { for (int i =2; i<(d/2); i++){ if(d%i==0) return false; } return true; }
Private
[
?
]
Run code