POJ C + + programming Problem # #: Calculating sum of squares of integers

Source: Internet
Author: User

Programming Question # #: Computes the sum of squares of integers

Source: Peking University Online Program evaluation system POJ (Coursera statement: The exercises completed on POJ will not count to the final results of Coursera. )

Total time limit: 1000ms memory limit: 1024kB

Describe

The following program reads an integer n each time, and exits if n is 0, otherwise outputs N and N squared.

#include <iostream>using namespace std;//here to supplement your code int main (int argc, char* argv[]) {        CType obj;        int n;        cin>>n;        while (n) {                obj.setvalue (n);                cout<<obj++<< "" <<obj<<endl;                cin>>n;        }        return 0;}

Input

A k integer. Except for the last data, none of the other data is 0.

Output

K-1 line. Line I outputs the number I input and its square.

Sample input
1 5 8) 9 0
Sample output
1 15 258) 649 81
1#include <iostream>2 using namespacestd;3 //Add your code here4 classCType {5  Public:6     intvalue;7CType (): Value (0) {};8     voidSetValueintN) {9Value =N;Ten     } One     //You must use the static variable ACType &operator++(int) { -         StaticCType tmp =CType (); -Tmp.value =value; theValue *=value; -         returntmp; -     } -  +Friend Ostream &operator<< (Ostream &o, CType &CType) { -o<<Ctype.value; +         returno; A     } at  - }; - intMainintargcChar*argv[]) { - CType obj; -     intN; -Cin>>N; in      while(n) { - obj.setvalue (n); tocout<<obj++<<" "<<obj<<Endl; +Cin>>N; -     } the     return 0; *}

POJ C + + programming Problem # #: Calculating sum of squares of integers

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.