注册 登录
编程论坛 C语言论坛

乘号*可以被定义为char类型或者其他类型吗?

jywu 发布于 2021-09-09 16:40, 1444 次点击
我想输出符号*组成一个图形,但是觉得写printf("*")有点麻烦,于是试着写类似于printf("%d",a)的语句进行输出,可是没有编译成功。请问可以对乘号*做这样的操作吗?

这是我在dev c++里面写的代码:
#include <stdio.h>
int main(void)
{
    signed char c;
   
    c=*;
   
    printf("%c",c);
   
    return 0;
}

然后编译器显示编译错误,在c=*那一行有错误警告:[Error] expected expression before ';' token
代码应该怎么写呢?求各位高手指点
3 回复
#2
diycai2021-09-09 16:44
#include <stdio.h>
int main(void)
{
    signed char c;
   
    c='*';
   
    printf("%c",c);
   
    return 0;
}
#3
diycai2021-09-09 16:51
void printStar(int starCount, int spaceCount)
{
    int i;

    for (i=0; i<spaceCount; i++)
    {
        printf(" ");
    }
    for (i=0; i<starCount; i++)
    {
        printf("*");
    }
    printf("\n");
}

int main(void)
{
    printStar(10, 5);
    printStar(20, 0);
    printStar(10, 5);
   
    return 0;
}
#4
自由而无用2021-09-09 17:08
//online parser: https://www.bccn.net/run/
//the following code is bccn sample
程序代码:
#include <stdio.h>

int main(int argc, char *argv[])
{
    int i;

    for (float y = 1.5f; y > -1.5f; y -= 0.1f) {
        for (float x = -1.5f; x < 1.5f; x += 0.05f) {
            float a = x * x + y * y - 1;
            putchar(a * a * a - x * x * y * y * y <= 0.0f ? '*' : ' ');
        }
        putchar('\n');
    }
   
    return 0;
}
                     
#5
jywu2021-09-09 17:21
回复 2楼 diycai
方法可行,谢谢你!
1