c语言 如下 输出一个心形,然后想在心形内部加入汉字,如何修改? #includ 如何用C语言先输出一段文字如何再输出心形图案?

\u600e\u4e48\u5728C\u8bed\u8a00\u6253\u51fa\u7231\u5fc3\u56fe\u5f62\u540e\u5728\u4e2d\u95f4\u8f93\u5165\u6c49\u5b57\uff1f\u6c42\u5404\u4f4d\u5927\u795e\u6307\u6559 \u8981\u6309\u539f\u4ee3\u7801\u4fee\u6539

\u8d85\u51falong int\u7684\u8303\u56f4\u4e86

\u5efa\u8bae\u7528\u5b57\u7b26\u4e32\u505a

\u8bf7\u8f93\u5165\u4e00\u6b63\u6574\u6570\uff1a12345678901234567890

\u4f60\u8f93\u5165\u7684\u662f20\u4f4d\u6570Press any key to continue
#include
#include "string.h"
void main()
{
char a[100];
int nLen;
printf("\u8bf7\u8f93\u5165\u4e00\u6b63\u6574\u6570\uff1a");
gets(a);
nLen=strlen(a);
printf("\n\u4f60\u8f93\u5165\u7684\u662f%d\u4f4d\u6570",nLen);
}

\u6709\u7591\u95ee\u8bf7\u8ffd\u95ee \u6ee1\u610f\u8bb0\u5f97\u91c7\u7eb3

#include void heart() {printf(" ** ** \n");printf(" * * * * \n");printf(" * * * \n");printf(" * * \n");printf(" * * \n");printf(" * * \n");printf(" * * \n");printf(" * * \n");printf(" * * \n");printf(" * * \n");printf(" * * \n");printf(" * * \n");printf(" * * \n");printf(" * * \n");printf(" * \n");}int main() {heart();return 0; }

##C++
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
    double x, y,
    size=10;
    char ch='*';
    string message("fateland");
    int print_line = 4;
    if(message.length() % 2 != 0) message += " ";
    for(x = 0; x < size -4; x++)
    {
        for(y = 0; y < 4 * size; y++)
        {
            double dist1 = sqrt( pow(x - size,2) + pow(y - size,2) ) -0.5;
            double dist2 = sqrt( pow(x - size,2) + pow(y - 3 * size,2) ) -0.5;
            if (dist1 < size + 0.5 || dist2 < size + 0.5 ) {
                cout << ch;
            }
            else cout << " ";
        }
        cout << endl;
    }
    //cout << "ddddddd" << endl;
    for(x = 1; x < 2 * size; x++)
    {
        for(y = 0; y < x; y++)
        {
            cout << " ";
        }
        for(y = 0; y < 4 * size - 2 * x; y++)
        {
            if (x >= print_line - 1 && x <= print_line + 1){
                int idx = y - (4 * size - 2 * x - message.length()) / 2;
                if(idx < message.length() && idx >= 0) {
                    if (x == print_line)
                    {
                        cout<<message[idx];
                    }
                    else
                    {
                        cout << " ";
                    }
                }
                else
                {
                    cout << ch;
                }
            }
            else cout << ch;
        }
        cout<<endl;
    }
    return 0;
}



扩展阅读:c语言用for循环打印心形 ... c语言中&的使用 ... c语言编爱心图形 ... c语言心形代码高级感 ... 心形编程代码简洁版 ... c语言输出镂空心形 ... c语言编程好看的图案 ... 用c语言编程心形图案 ... c语言如何输出爱心形状 ...

本站交流只代表网友个人观点,与本站立场无关
欢迎反馈与建议,请联系电邮
2024© 车视网