C语言编程能不能编个显示是I LOVE YOU的图案啊,高手帮帮忙~~

如题所述

    采用数组,

    初始化是一个你想要的图案

    进行遍历输出

    代码如下:

    #include<stdio.h>
    void main()
    {
    char name[30];
    gets(name);                  //输入对方姓名。
    char heart[][11]={{' ',' ',' ','*','*'},{' ',' ','*',' ',' ','*'},{' ','*',' ',' ',' ',' ','*'},
    {' ','*',' ',' ',' ',' ',' ','*'},{' ',' ','*',' ',' ',' ',' ',' ','*'},{' ',' ',' ','*',' ',' ',' ',' ',' ','*'},
    {' ',' ','*',' ',' ',' ',' ',' ','*'},{' ','*',' ',' ',' ',' ',' ','*'},{' ','*',' ',' ',' ',' ','*'},
    {' ',' ','*',' ',' ','*'},{' ',' ',' ','*','*'}};
    int i,j;
    for(i=0;i<11;i++)
    {
     for(j=0;j<11;j++)
     printf("%c",heart[j][i]);
     printf("\n");
    }
     printf("I Love You,%s.\n",name);
    }

温馨提示:答案为网友推荐,仅供参考
第1个回答  推荐于2017-09-27
#include<stdio.h>
void main()
{
char name[30];
gets(name); //输入对方姓名。
char heart[][11]={{' ',' ',' ','*','*'},{' ',' ','*',' ',' ','*'},{' ','*',' ',' ',' ',' ','*'},
{' ','*',' ',' ',' ',' ',' ','*'},{' ',' ','*',' ',' ',' ',' ',' ','*'},{' ',' ',' ','*',' ',' ',' ',' ',' ','*'},
{' ',' ','*',' ',' ',' ',' ',' ','*'},{' ','*',' ',' ',' ',' ',' ','*'},{' ','*',' ',' ',' ',' ','*'},
{' ',' ','*',' ',' ','*'},{' ',' ',' ','*','*'}};
int i,j;
for(i=0;i<11;i++)
{
for(j=0;j<11;j++)
printf("%c",heart[j][i]);
printf("\n");
}
printf("I Love You,%s.\n",name);
}追问

出现一个错误啊,我初学C语言编程,很多还不会~~前辈指点下,谢!!!

追答

项目类型不对,程序是测试过的。

本回答被提问者采纳
第2个回答  2015-10-29

1、用字符串输出i love you:

main()
{
  char st2[] ={73,32,76,79,86,69,32,89,79,85,0};
  printf("%s", st2);
}


2、用井号拼出来:

#include "stdio.h"
main()

  int str[10][8] = {
   0x3c,0x18,0x18,0x18,0x18,0x18,0x18,0x3c,
   0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
   0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x7e,
   0x3c,0x42,0x42,0x42,0x42,0x42,0x42,0x3c,
   0x42,0x42,0x42,0x24,0x24,0x24,0x18,0x18,
   0x7e,0x02,0x02,0x3e,0x02,0x02,0x02,0x7e,
   0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
   0x42,0x42,0x24,0x24,0x18,0x18,0x18,0x18,
   0x3c,0x42,0x42,0x42,0x42,0x42,0x42,0x3c,
   0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x3c};
   int loop, loop2,loop3,tmp;
   for(loop = 0;loop<8;loop++)
   {
    for(loop2 =0; loop2 < 10; loop2++ )
    {
     if (str[loop2][0]==0)
     {
      printf("   ");
     }
     else
     {
      tmp = str[loop2][loop];
      for(loop3=0; loop3 <8; loop3++)
      {
       if(tmp%2 !=0)
       {putchar('#');}
       else
       {putchar(' ');}
       tmp/=2;
           
      }
     }
    }
    putchar('\n');
   }
   printf("end");
   getchar();
}

第3个回答  2015-12-04
#include "stdio.h"
char z(char zuu[20][70])
{
int i,j;
for(i=0;i<20;i++)
for(j=0;j<70;j++)
if((j<27)||(j>47)||((i>3&&j<34)&&
(i<16&&j<34))||((i>3&&j>40)
&&(i<16&&j>40)))
zuu[i][j]=' ';
else
zuu[i][j]=003;
for(i=0;i<20;i++)
{for(j=0;j<70;j++)
printf("%c",zuu[i][j]);
printf("\n");
}
return 0;
}
char l(char lii[20][76])
{
int i,j;
for(i=0;i<20;i++)
for(j=0;j<76;j++)
if((j>3&&i<10)||(j>3&&i<17&&j<18)||(j==18)
||(j>22&&i<17&&j<30&&i>12)||(j==19&&i==10)
||(j==56)||(j==57&&i==10)||(j==75&&i==10)
||(i>11&&j>61&&i<14&&j<71)||(j==75&&i==15)
||(j>61&&i>15&&i<18)||(j>75)
||(j==35&&i>12)||(j==33&&i==19)
||(j==36&&i>13)||(j==37&&i>14)
||(j==38&&i>15)||(j==33&&i==10)
||(j==39&&i>16)||(j==40&&i>17)
||(j==41&&i>18)||(j==19&&i==19)
||(j==55&&i>12)||(j==54&&i>13)
||(j==53&&i>14)||(j==34)
||(j==52&&i>15)||(j==51&&i>16)
||(j==50&&i>17)
||(j==49&&i>18)||(j==48&&i>19)
||(j>39&&j<52&&i==10)
||(j>40&&j<51&&i==11)
||(j>41&&j<50&&i==12)
||(j>42&&j<49&&i==13)
||(j>43&&j<48&&i==14)
||(j>44&&j<47&&i==15))
lii[i][j]=' ';
else
lii[i][j]=003;
for(i=0;i<20;i++)
{for(j=0;j<76;j++)
printf("%c",lii[i][j]);
printf("\n");
}
return 0;
}
char y(char ynn[20][70])
{ int i,j;
for(i=0;i<20;i++)
for(j=0;j<70;j++)
if((j<7)||(j>67)||(j==7&&i>2)
||(j==8&&i>3)||(j==9&&i>4)
||(j==10&&i>5)||(j==27&&i==10)
||(j==11&&i>6)||(j==12&&i>7)
||(j==13&&i>8)||(j==25&&i>2)
||(j==24&&i>3)||(j==23&&i>4)
||(j==22&&i>5)||(j==21&&i>6)
||(j==20&&i>7)||(j==19&&i>8)
||(j==26)||(j==27&&i==19)
||(j>10&&j<22&&i==0)
||(j>11&&j<21&&i==1)
||(j>12&&j<20&&i==2)
||(j>13&&j<19&&i==3)
||(j>14&&j<18&&i==4)||(j==45&&i==10)
||(j>15&&j<17&&i==5)||(j==48&&i==19)
||(j>26&&i<10)||(j==47)
||(j==46)||(j==45&&i==19)
||(j>30&&i<17&&i>12&&j<42)
||(j>52&&j<63&&i<17))
ynn[i][j]=' ';
else
ynn[i][j]=003;
for(i=0;i<20;i++)
{for(j=0;j<70;j++)
printf("%c",ynn[i][j]);
printf("\n");
}
return 0;
}
main()
{ char yes;
char zuu[20][70],lii[20][76],ynn[20][70];
printf("Are you ready?([Y]or[N])\n");
scanf("%s",&yes);
z(zuu);printf("\n\n");
l(lii);printf("\n\n");
y(ynn);
printf("Please have a look up again.\n");
scanf("%s",&yes);
}
第4个回答  2011-11-30
来自牛人贴。不错的程序,
心字符图案,中间加上 I love you!
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
#define I 20 //爱心的上半部分两个小半圆的半径
#define R 340 //爱心的下半部分圆弧曲线半径
int main()
{
int i,j,e;
int a;
//爱心的上半部分 为两个实心半圆
for(i=1,a=I;i<I/2;i++,a--)
{
for(j=(int) ( I-sqrt((double)(I*I-(a-i)*(a-i))) );j>0;j--)
printf(" ");
for(e=1;e<=2*sqrt((double)(I*I-(a-i)*(a-i)));e++)
printf("\3");
for(j=(int) ( 2*( I-sqrt((double)(I*I-(a-i)*(a-i))) ) );j>0;j--)
printf(" ");
for(e=1;e<=2*sqrt( (double) (I*I-(a-i)*(a-i)) );e++)
printf("\3");
printf("\n");
}
//爱心的中间一行 可以打印一些标记
for(i=1;i<80;i++)
{
if(i==25)
{
printf(" I LOVE YOU!O(∩_∩)O~ ");
i+=30;
}
printf("\3");
}
printf("\n");

//爱心的下半部分 以R为半径的左右两条圆弧曲线 R设置为比较大
for(i=1;i<=R/2;i++)
{
if(i%2||i%3)continue;//因为R很大 两条曲线应该删去中间的一些点 这样就会更像爱心
for(j=(int) ( R-sqrt( (double) (R*R-i*i) ) );j>0;j--)
printf(" ");
for(e=1;e<=2*( sqrt( (double)(R*R-i*i) ) - (R-2*I) );e++)
printf("\3");
printf("\n");
}
//以下是以time做时间变量来控制变色
//懒得查时间变量函数 故用这种超耗cpu的算法代替
//最好不要这么写 以下代码仅供娱乐
long time;
for(; ;)
{
system("color a");
for(time=0;time<99999999;time++);
system("color b");
for(time=0;time<99999999;time++);
system("color c");
for(time=0;time<99999999;time++);
system("color d");
for(time=0;time<99999999;time++);
system("color e");
for(time=0;time<99999999;time++);
system("color f");
for(time=0;time<99999999;time++);
system("color 0");
for(time=0;time<99999999;time++);
system("color 1");
for(time=0;time<99999999;time++);
system("color 2");
for(time=0;time<99999999;time++);
system("color 3");
for(time=0;time<99999999;time++);
system("color 4");
for(time=0;time<99999999;time++);
system("color 5");
for(time=0;time<99999999;time++);
system("color 6");
for(time=0;time<99999999;time++);
system("color 7");
for(time=0;time<99999999;time++);
system("color 8");
for(time=0;time<99999999;time++);
system("color 9");
for(time=0;time<99999999;time++);
system("color ab");
for(time=0;time<99999999;time++);
system("color ac");
for(time=0;time<99999999;time++);
system("color ad");
for(time=0;time<99999999;time++);
system("color ae");
for(time=0;time<99999999;time++);
system("color af");
for(time=0;time<99999999;time++);
}
return 0;
}
相似回答