全部评论 5

  • #include<bits/stdc++.h>
    using namespace std;
    int main() {
    	int n;
        cin>>n;
    	for(int i=0;i<n;i++){
    	    for(int j=0;j<n;j++){
    	            cout<<"*";
    	    }
            cout<<endl;
    	}
    }
    

    正解是这样的

    4天前 来自 黑龙江

    2
  • 谢谢各位大佬

    2026-01-17 来自 北京

    1
  • 事实上,题目为 n×nn \times n 的正方形矩阵,你应该使用双重循环解决这一问题

    2026-01-16 来自 浙江

    1
  • https://www.acgo.cn/application/2011082499115569152

    2026-01-16 来自 浙江

    1
  • 正解

    #include<iostream>
    using namespace std;
    int main(){
        int n;
        cin>>n;
        for(int i;i<=n;i++){
        //外层循环
            for(int j;j<n;j++){
            //内层循环,只用记录次数并输出("*")就行
                cout<<"*";
            }
            cout<<""<<endl;//换行,不然输出就会连在一起
        }
    }
    

    你的错误点在于
    这里的题目描述是:

    题目描述
    打印字符图形。输出n行n列"*"

    而你是只考虑行数,如果
    按照你的代码:

    输入
    5

    输出

    for(int i;i<5;i++){
        cout<<"**"<<endl;
    }
    

    自己去运行,这里无法打"*"

    所以,去好好看题是最重要的

    2026-01-16 来自 上海

    1
暂无数据

提交答案之后,这里将显示提交结果~

首页