当前位置:首页 » 编程语言 » c语言版本a星算法
扩展阅读
webinf下怎么引入js 2023-08-31 21:54:13
堡垒机怎么打开web 2023-08-31 21:54:11

c语言版本a星算法

发布时间: 2023-01-11 07:09:41

c语言关于星星的程序题

没有说明什么方法

#include<stdio.h>
main()
{
printf("aaa*aaa\n");
printf("aa***aa\n");
printf("a*****a\n");
printf("*******\n");
}
这个就最简单!!

/*循环控制这样*/
#include<stdio.h>
main()
{
int i,j,k;

for(i=0,k=3; i<4; i++,k--)
{
for(j=0;j<7;j++)
if(j>=k && j<=6-k)
printf("*");
else
printf("a");
printf("\n");
}

}

㈡ C语言基础知识求解

数组a是二维数组
*(a+0)+1等效于&a[0][1],自然仍然是地址

㈢ c语言中如何把字母转化为星号

假如字符串a[7]="ababab",如下所示:

  • #include "stdio.h"

  • #include "string.h"

  • void main()

  • {

    • char a[7]="ababab";

    • int i;

    • printf("转化前:%s ",a);

    • for(i=0;i<strlen(a);i++)

    • {

    • if(a[i]=='a')a[i]='*';

    • }

    • printf("转化后:%s ",a);

  • }

主要就是一个循环,寻找需要转化的字母a,然后写入*。

㈣ C语言用数组编北斗七星

用c语言的话你的意思就是只用控制台输出了吧。
如果是这样思路我可以瞬间给你一个,代码就免了
北斗七星实质就是7个坐标。先定义一个坐标当做第一颗星,星之间线段长度a,前4颗角度118,第5颗反向角度62.角度是相对于前一线段的指向为标准的。后两颗星角度0就可以
这样就生成了7个北斗七星的坐标。需要定义的只有第一星坐标和星之间的距离

㈤ c语言设计一个递归算法,输出2n行星号。第1行输出1个星号,第2行输出2

#include<stdio.h>
voidfunc(inta,intn)
{
inti;

for(i=0;i<a;i++)
printf("*");
printf(" ");
if(a<=n)func(a+1,n);
for(i=0;i<a;i++)
printf("*");
printf(" ");

}

intmain()
{
intn;
scanf("%d",&n);
func(1,n);

return0;
}

㈥ c语言输出星号是什么意思

#include<stdio.h>
main()
{ int N,a;
scanf("%d",&N);
for(a=0;a<N;a++)
printf("*");
getch();
}
这么写就行了,你前面有很多没用的还有些是程序布恩那个运行的

㈦ 急啊,用c语言编程一个星号组成的沙漏图形,行数为n,如n=5是*****就要代码,快!!! *** * *** *****

1、打开visual C++ 6.0-文件-新建-文件-C++ Source File。

㈧ c语言中的星号“*”

这意味着我要定义一个指针,*未定义时,获取以下地址的内容,输入方法。

1.打开visualc++6.0-File-新建的-File-c++源文件,如下图所示:

㈨ 急~关于C语言课程设计用星号构成A~Z字母输出~~~!!!

/* 第一题 */

#include <stdio.h>
#include <string.h>

#define SCREEN_COLS 80 /* how many columns does terminal have */
#define HORIZONTAL_DISTANCE 4 /* horizontal distance between two characters (列距) */
#define VERTICAL_DISTANCE 1 /* vertical distance between two rows of characters (行距) */
#define BRUSH_CHAR ('*')
#define BLANK_CHAR (' ')

/* ASCII_TAB字模中字体的高度和宽度 */
#define FONT_ROWS 7
#define FONT_COLS 5

/* 屏幕每行最多可以显示的字符个数 */
#define CHAR_PER_LINE (SCREEN_COLS/(FONT_COLS + HORIZONTAL_DISTANCE))
// ASCII_TAB[] contains all ASCII characters from sp (32) to z (122)
static const unsigned char ASCII_TAB[][5]= //5*7
{
{ 0x00, 0x00, 0x00, 0x00, 0x00 }, // sp
{ 0x00, 0x00, 0x2f, 0x00, 0x00 }, // !
{ 0x00, 0x07, 0x00, 0x07, 0x00 }, // "
{ 0x14, 0x7f, 0x14, 0x7f, 0x14 }, // #
{ 0x24, 0x2a, 0x7f, 0x2a, 0x12 }, // $
{ 0xc4, 0xc8, 0x10, 0x26, 0x46 }, // %
{ 0x36, 0x49, 0x55, 0x22, 0x50 }, // &
{ 0x00, 0x05, 0x03, 0x00, 0x00 }, // '
{ 0x00, 0x1c, 0x22, 0x41, 0x00 }, // (
{ 0x00, 0x41, 0x22, 0x1c, 0x00 }, // )
{ 0x14, 0x08, 0x3E, 0x08, 0x14 }, // *
{ 0x08, 0x08, 0x3E, 0x08, 0x08 }, // +
{ 0x00, 0x00, 0x50, 0x30, 0x00 }, // ,
{ 0x10, 0x10, 0x10, 0x10, 0x10 }, // -
{ 0x00, 0x60, 0x60, 0x00, 0x00 }, // .
{ 0x20, 0x10, 0x08, 0x04, 0x02 }, // /

{ 0x3E, 0x51, 0x49, 0x45, 0x3E }, // 0
{ 0x00, 0x42, 0x7F, 0x40, 0x00 }, // 1
{ 0x42, 0x61, 0x51, 0x49, 0x46 }, // 2
{ 0x21, 0x41, 0x45, 0x4B, 0x31 }, // 3
{ 0x18, 0x14, 0x12, 0x7F, 0x10 }, // 4
{ 0x27, 0x45, 0x45, 0x45, 0x39 }, // 5
{ 0x3C, 0x4A, 0x49, 0x49, 0x30 }, // 6
{ 0x01, 0x71, 0x09, 0x05, 0x03 }, // 7
{ 0x36, 0x49, 0x49, 0x49, 0x36 }, // 8
{ 0x06, 0x49, 0x49, 0x29, 0x1E }, // 9

{ 0x00, 0x36, 0x36, 0x00, 0x00 }, // :
{ 0x00, 0x56, 0x36, 0x00, 0x00 }, // ;
{ 0x08, 0x14, 0x22, 0x41, 0x00 }, // <
{ 0x14, 0x14, 0x14, 0x14, 0x14 }, // =
{ 0x00, 0x41, 0x22, 0x14, 0x08 }, // >
{ 0x02, 0x01, 0x51, 0x09, 0x06 }, // ?
{ 0x32, 0x49, 0x59, 0x51, 0x3E }, // @

{ 0x7E, 0x11, 0x11, 0x11, 0x7E }, // A
{ 0x7F, 0x49, 0x49, 0x49, 0x36 }, // B
{ 0x3E, 0x41, 0x41, 0x41, 0x22 }, // C
{ 0x7F, 0x41, 0x41, 0x22, 0x1C }, // D
{ 0x7F, 0x49, 0x49, 0x49, 0x41 }, // E
{ 0x7F, 0x09, 0x09, 0x09, 0x01 }, // F
{ 0x3E, 0x41, 0x49, 0x49, 0x7A }, // G
{ 0x7F, 0x08, 0x08, 0x08, 0x7F }, // H
{ 0x00, 0x41, 0x7F, 0x41, 0x00 }, // I
{ 0x20, 0x40, 0x41, 0x3F, 0x01 }, // J
{ 0x7F, 0x08, 0x14, 0x22, 0x41 }, // K
{ 0x7F, 0x40, 0x40, 0x40, 0x40 }, // L
{ 0x7F, 0x02, 0x0C, 0x02, 0x7F }, // M
{ 0x7F, 0x04, 0x08, 0x10, 0x7F }, // N
{ 0x3E, 0x41, 0x41, 0x41, 0x3E }, // O
{ 0x7F, 0x09, 0x09, 0x09, 0x06 }, // P
{ 0x3E, 0x41, 0x51, 0x21, 0x5E }, // Q
{ 0x7F, 0x09, 0x19, 0x29, 0x46 }, // R
{ 0x46, 0x49, 0x49, 0x49, 0x31 }, // S
{ 0x01, 0x01, 0x7F, 0x01, 0x01 }, // T
{ 0x3F, 0x40, 0x40, 0x40, 0x3F }, // U
{ 0x1F, 0x20, 0x40, 0x20, 0x1F }, // V
{ 0x3F, 0x40, 0x38, 0x40, 0x3F }, // W
{ 0x63, 0x14, 0x08, 0x14, 0x63 }, // X
{ 0x07, 0x08, 0x70, 0x08, 0x07 }, // Y
{ 0x61, 0x51, 0x49, 0x45, 0x43 }, // Z

{ 0x00, 0x7F, 0x41, 0x41, 0x00 }, // [
{ 0x55, 0x2A, 0x55, 0x2A, 0x55 }, // '\'
{ 0x00, 0x41, 0x41, 0x7F, 0x00 }, // ]
{ 0x04, 0x02, 0x01, 0x02, 0x04 }, // ^
{ 0x40, 0x40, 0x40, 0x40, 0x40 }, // _
{ 0x00, 0x01, 0x02, 0x04, 0x00 }, // '

{ 0x20, 0x54, 0x54, 0x54, 0x78 }, // a
{ 0x7F, 0x48, 0x44, 0x44, 0x38 }, // b
{ 0x38, 0x44, 0x44, 0x44, 0x20 }, // c
{ 0x38, 0x44, 0x44, 0x48, 0x7F }, // d
{ 0x38, 0x54, 0x54, 0x54, 0x18 }, // e
{ 0x08, 0x7E, 0x09, 0x01, 0x02 }, // f
{ 0x0C, 0x52, 0x52, 0x52, 0x3E }, // g
{ 0x7F, 0x08, 0x04, 0x04, 0x78 }, // h
{ 0x00, 0x44, 0x7D, 0x40, 0x00 }, // i
{ 0x20, 0x40, 0x44, 0x3D, 0x00 }, // j
{ 0x7F, 0x10, 0x28, 0x44, 0x00 }, // k
{ 0x00, 0x41, 0x7F, 0x40, 0x00 }, // l
{ 0x7C, 0x04, 0x18, 0x04, 0x78 }, // m
{ 0x7C, 0x08, 0x04, 0x04, 0x78 }, // n
{ 0x38, 0x44, 0x44, 0x44, 0x38 }, // o
{ 0x7C, 0x14, 0x14, 0x14, 0x08 }, // p
{ 0x08, 0x14, 0x14, 0x18, 0x7C }, // q
{ 0x7C, 0x08, 0x04, 0x04, 0x08 }, // r
{ 0x48, 0x54, 0x54, 0x54, 0x20 }, // s
{ 0x04, 0x3F, 0x44, 0x40, 0x20 }, // t
{ 0x3C, 0x40, 0x40, 0x20, 0x7C }, // u
{ 0x1C, 0x20, 0x40, 0x20, 0x1C }, // v
{ 0x3C, 0x40, 0x30, 0x40, 0x3C }, // w
{ 0x44, 0x28, 0x10, 0x28, 0x44 }, // x
{ 0x0C, 0x50, 0x50, 0x50, 0x3C }, // y
{ 0x44, 0x64, 0x54, 0x4C, 0x44 } // z
};

static char get_char_xy(char ch, int x, int y)
{
if (ch < ' ' || ch > 'z')
ch = ' ';
ch -= ' ';
return (ASCII_TAB[ch][x] & (1<<y)) ? BRUSH_CHAR : BLANK_CHAR;
}

static void print_row(char ch, int row)
{
int i;
for (i = 0; i < FONT_COLS; i++) {
printf("%c", get_char_xy(ch, i, row));
}
}

int main(int argc, char *argv[])
{
char str[80] = { '\0' };
int i, j, k, len, index = 0;
printf("Please input a string:\n");
scanf("%s", str);
len = strlen(str);
while (index < len) {
for (i = 0; i < FONT_ROWS; i++) {
for (j = 0; j < CHAR_PER_LINE && j + index < len; j++) {
print_row(str[index + j], i);
for (k = 0; k < HORIZONTAL_DISTANCE; k++) {
printf("%c", BLANK_CHAR);
}
}
printf("\n");
}
index += CHAR_PER_LINE;
for (k = 0; k < VERTICAL_DISTANCE; k++) {
printf("\n");
}
}
return 0;
}

/* 第二题 */

#include <math.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>

#define MIN_POINT_NUMBER 3
#define MAX_POINT_NUMBER 100
#define MAX_POINT_COORD 1000.0

typedef struct Point_ {
float x;
float y;
} Point;

typedef struct Circle_ {
Point o; /* centre */
Point p1;
Point p2;
float r; /* radius */
} Circle;

typedef struct {
Point p;
int included;
} Element;

/* return squared distance of points a & b */
#define SQUARE(a) ((a)*(a))
#define SQUARED_DISTANCE(a,b) (SQUARE((a).x-(b).x) + SQUARE((a).y-(b).y))
#define DISTANCE(a,b) (sqrt(SQUARED_DISTANCE((a),(b))))
#define MAX(a,b) ((a) > (b) ? (a) : (b))
#define MIN(a,b) ((a) < (b) ? (a) : (b))
#define EQUAL_FLOAT(a,b) (fabs((a)-(b)) < 0.00001)

/* get the circumcircle of a triangle */
static Circle
get_circumcircle(Point a, Point b, Point c)
{
Circle result;
float dx1 = a.x - b.x;
float dx2 = b.x - c.x;
float dy1 = a.y - b.y;
float dy2 = b.y - c.y;
float x1 = (a.x + b.x) / 2.0;
float x2 = (b.x + c.x) / 2.0;
float y1 = (a.y + b.y) / 2.0;
float y2 = (b.y + c.y) / 2.0;

result.o.x = ((dy1*dy2*(y2-y1) + x2*dx2*dy1 - x1*dx1*dy2)) / \
(dx2*dy1 - dx1*dy2);
result.o.y = ((dx1*dx2*(x2-x1) + y2*dy2*dx1 - y1*dy1*dx2)) / \
(dy2*dx1 - dy1*dx2);

result.r = DISTANCE(result.o, a);
result.p1 = a;
result.p2 = c;

return result;
}

/* get the mininal circle that includes three given points
* Note:
* 1) the tree points may be in one line
* or
* 2) the tree points make up a triangle
*/
static Circle
get_min_circle(Point a, Point b, Point c)
{
Circle result;
float ab,bc,ac, max;
ab = DISTANCE(a,b);
bc = DISTANCE(b,c);
ac = DISTANCE(a,c);
max = MAX(ab, MAX(bc,ac));
printf("[%f, %f]\n[%f, %f]\n[%f, %f]\n",a.x,a.y,b.x,b.y,c.x,c.y);
if (EQUAL_FLOAT(max*2, ab+bc+ac)) { /* in the same line */
printf("line\n");
if (EQUAL_FLOAT(max, ab)) {
/* ab is the diameter */
result.o.x = (a.x + b.x) / 2.0;
result.o.y = (a.y + b.y) / 2.0;
result.r = max / 2.0;
result.p1 = a;
result.p2 = b;
} else if (EQUAL_FLOAT(max, bc)) {
/* bc is the diameter */
result.o.x = (b.x + c.x) / 2.0;
result.o.y = (b.y + c.y) / 2.0;
result.r = max / 2.0;
result.p1 = b;
result.p2 = c;
} else {
/* ac is the diameter */
result.o.x = (a.x + c.x) / 2.0;
result.o.y = (a.y + c.y) / 2.0;
result.r = max / 2.0;
result.p1 = a;
result.p2 = c;
}
} else { /* triangle */
/* get the circumcircle of the triangle */
printf("triangle\n");
result = get_circumcircle(a, b, c);
}
printf("The circle's center is [%f, %f], radius is %f\n",
result.o.x, result.o.y, result.r);
return result;
}

int
main(int argc, char *argv[])
{
Circle circle;
Element *elements;
int n = 0, i;

while (n < MIN_POINT_NUMBER || n > MAX_POINT_NUMBER) {
printf("Please input point number (3-100):\n");
scanf("%d", &n);
}
elements = (Element*)malloc(sizeof(Element)*n);
memset(elements, 0, sizeof(Element)*n);
for (i = 0; i < n; i++) {
printf("Please input point (%d in %d):\n", i+1, n);
scanf("%f %f", &elements[i].p.x, &elements[i].p.y);
}

elements[0].included = 1;
elements[1].included = 1;
elements[2].included = 1;
circle = get_min_circle(elements[0].p, elements[1].p, elements[2].p);
for (i = 0; i < n; i++) {
if (elements[i].included)
continue;
if (DISTANCE(elements[i].p, circle.o) - circle.r > 0.00001) {
circle = get_min_circle(circle.p1, circle.p2, elements[i].p);
}
elements[i].included = 1;
}

return 0;
}