c语言画球链
⑴ c语言 项链问题
你问的是 任意一串 左右去颜色 取出来的同颜色颜色相加的话 那不就是 原来的两种珠子的综合吗?这样的话无论从哪里断开 m 就是等于 任意给定的另个颜色珠子综合之差了。你的意思 不明白
⑵ 如何用C语言编程一个滚动的小球 最好是五彩的 滚动的
#include"graphics.h"
#include"stdlib.h"
main()
{
int i,gdriver,gmode,size,*buf;
gdriver=DETECT;
initgraph(&gdriver,&gmode," ");
setbkcolor(BLACK);
cleardevice();
setcolor(LIGHTRED);
setlinestyle(0,0,1);
setfillstyle(1,4);
circle(100,200,20);
floodfill(100,200,12);
size=imagesize(79,159,131,231);
buf=malloc(size);
getimage(79,159,131,231,buf);
putimage(530,269,buf,COPY_PUT);
getch();
for(i=0;i<200;i++)
{
putimage(75+i,160,buf,COPY_PUT);
putimage(515-i,160,buf,COPY_PUT);
}
for(i=0;i<200; i++)
{
putimage(270-i,160,buf,COPY_PUT);
putimage(320+i,160,buf,COPY_PUT);
}
getch();
closegraph();
}
⑶ 怎么用c语言画出一个随时间变化的圆形
circle函数是TURBO C提供的图形接口,用来画圆。不属于标准库函数,不具备可移植性。
函数名:circle
功 能: 在给定半径以(x, y)为圆心画圆
用 法:void far circle(int x, int y, int radius)随时间变化,可以用cleardevice函数清除屏幕,不断画半径不同的圆。看起来就像是一个随时间变化的圆形。
函数名: cleardevice
功 能: 清除图形屏幕
用 法: void far cleardevice(void);
例程:#include<graphics.h>
#include<stdlib.h>
#include<stdio.h>
#include<conio.h>
intmain(void)
{
/*requestautodetection*/
intgdriver=DETECT,gmode,errorcode;
intmidx,midy;
intradius=100;
/**/
initgraph(&gdriver,&gmode,"");
/*readresultofinitialization*/
errorcode=graphresult();
if(errorcode!=grOk)/*anerroroccurred*/
{
printf("Graphicserror:%s ",grapherrormsg(errorcode));
printf("Pressanykeytohalt:");
getch();
exit(1);/*terminatewithanerrorcode*/
}
midx=getmaxx()/2;
midy=getmaxy()/2;
setcolor(getmaxcolor());
for(i=0;i<1000000;i++)if(i%50000==0){
cleardevice();/*cleanthescreen*/
circle(midx,midy,radius--);/*drawthecircle*/
}
getch();
closegraph();
return0;
}
⑷ c语言中.用4种颜色画8个球,要求每个球的颜色随机选择的程序怎么写
4种颜色 的RGB 数值存放在 unsigned int color[4] 里。
用 rand()%4 定出 color[ ] 的下标 ( 0,1,2,3 之一)
#include <stdio.h>
#include <time.h>
main(){
unsigned int color[4]={0xff00a0,0x00ff80,0x8040ff,0xff8000};
int i;
srand(time(NULL)); // 随机种子
for (i=0;i<8;i++)
{
printf("draw Ball_%d in color %06x\n",i,color[rand()%4]);
}
return 0;
}
⑸ 如何用C语言编写一个链表
#include "stdio.h"
#include "stdlib.h"
#include "malloc.h"
struct Node
{
int data;//数据域
struct Node * next;//指针域
};
/*************************************************************************************
*函数名称:Create
*函数功能:创建链表.
*输入:各节点的data
*返回值:指针head
*************************************************************************************/
struct Node * Create()
{
struct Node *head,*p1,*p2;
head = NULL;
p1 = p2 = (struct Node *)malloc(sizeof(struct Node));
printf("Input the linklist (Input 0 to stop):\n");
scanf("%d",&p1->data);
while(p1->data!=0)
{
if(head == NULL){
head = p1;
}else{
p2->next = p1;
p2 =p1;
}
p1 = (struct Node *)malloc(sizeof(struct Node));
scanf("%d",&p1->data);
}
p2->next = NULL;
return head;
}
/*************************************************************************************
*函数名称:insert
*函数功能:在链表中插入元素.
*输入:head 链表头指针,p新元素插入位置,x 新元素中的数据域内容
*返回值:无
*************************************************************************************/
void insert(struct Node * head,int p,int x)
{
struct Node * tmp = head;
struct Node * tmp2 ;
int i ;
for(i = 0;i<p;i++)
{
if(tmp == NULL)
return ;
if(i<p-1)
tmp = tmp->next;
}
tmp2 = (struct Node *)malloc(sizeof(struct Node));
tmp2->data = x;
tmp2->next = tmp->next;
tmp->next = tmp2;
}
/**************************************************************************************
*函数名称:del
*函数功能:删除链表中的元素
*输入:head 链表头指针,p 被删除元素位置
*返回值:被删除元素中的数据域.如果删除失败返回-1
**************************************************************************************/
int del(struct Node * head,int p)
{
struct Node * tmp = head;
int ret , i;
for(i = 0;i<p;i++)
{
if(tmp == NULL)
return -1;
if(i<p-1)
tmp = tmp->next;
}
ret = tmp->next->data;
tmp->next = tmp->next->next;
return ret;
}
/**************************************************************************************
*函数名称:print
*函数功能:打印链表中的元素
*输入:head 链表头指针
*返回值:无
**************************************************************************************/
void print(struct Node *head)
{
struct Node *tmp;
for(tmp = head; tmp!=NULL; tmp = tmp->next)
printf("%d ",tmp->data);
printf("\n");
}
/**************************************************************************************
*函数名称:main
*函数功能:主函数创建链表并打印链表。
**************************************************************************************/
int main(){
struct Node * head = Create();
print(head);
return 0;
}
⑹ 用c语言应该怎样写小球沿着任意一条直线运动求详解
想绘制一个沿直线运动的小球吗?
绘制图形可以用GDI,按照执行运动直接用直线公式就好了,然后x取值从0到屏幕宽度,然后一个循环,记得要Sleep啊。
⑺ C语言球类问题
这就是个找第K小值的问题吧,因为质量相同碰撞后只是交换速度而已,所以你可以理解为它们是互相穿过了(量子态超相干的2333),找到初始数据中第K小的,然后加上at就行了吧
⑻ c语言 链表流程图 怎么画呀
你一步步往下分,流程图不就出来了,比如你的例子:
首先就是p1->number,即p1指向的结点
分不等于0,小于0,等于0 三种情况,
然后再往下分,比如p1->number!=0时
=>n=n+1
判断n
如果为真怎么样,为假又怎么样(继续走)。。。。
就是麻烦点,一步步来流程图就出来。不过。。。这种东西用流程图表示,太麻烦了吧。。。
