當前位置:編程學習大全網 - 編程語言 - 急!c語言中,編寫程序,輸入字母A,就可以在屏幕上的適當位置,用適當的大小,輸出壹個用*構成的字母

急!c語言中,編寫程序,輸入字母A,就可以在屏幕上的適當位置,用適當的大小,輸出壹個用*構成的字母

#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;

}

  • 上一篇:web後端是做什麽的
  • 下一篇:平凡之路***橙長---記iCourt
  • copyright 2024編程學習大全網