C++读入一个参数

题目内容:已知正方形的边长,试编程求出其面积。

输入描述:输入不超过50个正整数的数据n(1<=n<=10000),每个正整数间以空格隔开。

输出描述:每次读入一个正整数,便输出其正方形的面积,输出每个面积后再回车。

输入样例:1 3 5 7

输出样例:1 9 25 49

参考答案:

#include "stdafx.h"
#include <vector>
#include <fstream>
#include <iostream>
using namespace std;

int  main(int argc, char * argv[])
{
    vector<int> length(50);
    int num=0;
    int l;
    while(num<=49)
    {
        scanf("%d",&l);
        if(l>=1&&l<=10000)
        {
            length[num]=l;
            cout<<l*l<<endl;
            num++;
        }
        else if(l<1||l>10000)
        {
            cout<<"The length should be greater than 1 and less than 10000";
        }
    }
    return 0;
}
原文地址:https://www.cnblogs.com/cysolo/p/3377187.html