[ create a new paste ] login | about

Link: http://codepad.org/g3fafqCY    [ raw code | output | fork ]

C++, pasted on Mar 15:
             /**************************************/
             /* 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;
}


Output:
NUMBERS	SUMSQ	SUMCB	SUMSQRT	PRIME
5	55	225	17	*
7	140	784	26	*
9	285	2025	47	 
11	506	4356	64	*
13	819	8281	93	*
15	1240	14400	118	 
17	1785	23409	155	*
19	2470	36100	188	*
21	3311	53361	233	 
23	4324	76176	274	*
25	5525	105625	327	 
27	6930	142884	376	 
29	8555	189225	437	*
31	10416	246016	494	*
33	12529	314721	563	 
35	14910	396900	628	 
37	17575	494209	705	*
39	20540	608400	778	 
41	23821	741321	863	*
43	27434	894916	944	*
45	31395	1071225	1037	 
47	35720	1272384	1126	*
49	40425	1500625	1227	 

The average of the number is '2'
The average of the sum of squares is '1979'
The average of the sum of cubes is '76446'
The number of prime numbers is '0'
The number of numbers for which the sum of cubes is more than 5 times the sum of squares is '0'
The number of numbers for which the sum of the suare roots is greater than 1/10 of the number is '0'

Disallowed system call: SYS_fork


Create a new paste based on this one


Comments: