当前位置:首页 » 编程语言 » c语言显示姓名动画代码
扩展阅读
webinf下怎么引入js 2023-08-31 21:54:13
堡垒机怎么打开web 2023-08-31 21:54:11

c语言显示姓名动画代码

发布时间: 2023-07-09 06:53:38

Ⅰ 求一简单的c语言动画程序。

#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#include<conio.h>

typedef struct snake
{
int a;
int b;
struct snake *u;
struct snake *n;
}snake,*snake1;
typedef struct food
{
int a;
int b;
}food;
void main()
{
char c,c0 = 'd';
int i,j,k,n=1,t,at;
snake p,q;
snake *dd,*dd0,*dd1,*dd2;
food f;
srand(time(NULL));
p.u = NULL;
p.n = &q;
p.a = 5;p.b = 6;q.a = 5;q.b = 5;
q.u = &p;q.n = NULL;
dd=dd2= &q;
f.a=(rand()%15+1);
f.b=(rand()%15+1);
while(1)
{
srand(time(NULL));
system("cls");
for(i = 0;i < 17;i ++)
{
for(j = 0; j < 17;j++)
{

if(i == 0 )
printf("▁");
else if(i == 16)
printf("▔");
else if(j == 0)
printf("▕");
else if(j == 16)
printf("▏");
else if(i == p.a && j == p.b)
printf("■");
else if(i == f.a && j == f.b)
printf("★");
else
{
t = 0;
dd = dd2;
for(k = 0; k < n ;k++)
{
if(i == dd->a && j == dd->b)
{
printf("□");
t = 1;
break;
}

dd = dd->u;
}
if(t == 0)
printf(" ");
}

}printf("\n");
}
at = 0;
dd =dd2;
for(i=0;i<n;i++)
{
if(p.a == dd->a && p.b == dd->b)
{
printf("game over!!\n");
exit(0);
}
dd = dd->u;
}
if(p.a == f.a && p.b == f.b)
{
dd = dd2;
at =1;
f.a = (rand()%15+1);
f.b = (rand()%15+1);
for(i=0;i<n;i++)
{
if(f.a == dd->a && f.b == dd->b)
{
f.a = dd2->a;
f.b = dd2->b;
break;
}
}
n++;
}
if(kbhit())
{
c = getch();
dd = dd2;
if(c == 'w' && c0 != 's')
{
if(at == 1)
{
dd0 =(snake1)malloc(sizeof(snake));
dd0->a = dd2->a;dd0->b = dd2->b;
dd0->n = NULL;dd0->u = dd2;
dd2=dd0;
}
dd = dd2;
for(i = 0; i<n ; i++)
{
dd1 = dd->u;
dd->b = dd1->b;
dd->a = dd1->a;
dd = dd->u;
}
if(p.a == 1)
p.a = 15;
else
p.a = (p.a-1)%15;
}
else if(c == 's' && c0 != 'w')
{
if(at == 1)
{
dd0 =(snake1)malloc(sizeof(snake));
dd0->a = dd2->a;dd0->b = dd2->b;
dd0->n = NULL;dd0->u = dd2;
dd2=dd0;
}
dd = dd2;
for(i = 0; i<n ; i++)
{
dd1 = dd->u;
dd->b = dd1->b;
dd->a = dd1->a;
dd = dd->u;
}
p.a = (p.a%15)+1;
}
else if(c == 'a' && c0 != 'd')
{
if(at == 1)
{
dd0 =(snake1)malloc(sizeof(snake));
dd0->a = dd2->a;dd0->b = dd2->b;
dd0->n = NULL;dd0->u = dd2;
dd2=dd0;
}
dd = dd2;
for(i = 0; i<n ; i++)
{
dd1 = dd->u;
dd->b = dd1->b;
dd->a = dd1->a;
dd = dd->u;
}
if(p.b == 1)
p.b = 15;
else
p.b = (p.b-1)%15;
}
else if(c == 'd' && c0 != 'a')
{
if(at == 1)
{
dd0 =(snake1)malloc(sizeof(snake));
dd0->a = dd2->a;dd0->b = dd2->b;
dd0->n = NULL;dd0->u = dd2;
dd2=dd0;
}
dd = dd2;
for(i = 0; i<n ; i++)
{
dd1 = dd->u;
dd->b = dd1->b;
dd->a = dd1->a;
dd = dd->u;
}
p.b = (p.b%15)+1;
}
else
{
goto qq;
}
c0 = c;
}
else
{
qq: if(c0 == 'w')
{
if(at == 1)
{
dd0 =(snake1)malloc(sizeof(snake));
dd0->a = dd2->a;dd0->b = dd2->b;
dd0->n = NULL;dd0->u = dd2;
dd2=dd0;
}
dd = dd2;
for(i = 0; i<n ; i++)
{
dd1 = dd->u;
dd->b = dd1->b;
dd->a = dd1->a;
dd = dd->u;
}
if(p.a == 1)
p.a = 15;
else
p.a=(p.a-1)%15;
}
else if(c0 == 's')
{
if(at == 1)
{
dd0 =(snake1)malloc(sizeof(snake));
dd0->a = dd2->a;dd0->b = dd2->b;
dd0->n = NULL;dd0->u = dd2;
dd2=dd0;
}
dd = dd2;
for(i = 0; i<n ; i++)
{
dd1 = dd->u;
dd->b = dd1->b;
dd->a = dd1->a;
dd = dd->u;
}
p.a=(p.a%15)+1;
}
else if(c0 == 'a')
{

if(at == 1)
{
dd0 =(snake1)malloc(sizeof(snake));
dd0->a = dd2->a;dd0->b = dd2->b;
dd0->n = NULL;dd0->u = dd2;
dd2=dd0;
}
dd = dd2;
for(i = 0; i<n ; i++)
{
dd1 = dd->u;
dd->b = dd1->b;
dd->a = dd1->a;
dd = dd->u;
}
if(p.b == 1)
p.b = 15;
else
p.b=(p.b-1)%15;
}
else if(c0 == 'd')
{
if(at == 1)
{
dd0 =(snake1)malloc(sizeof(snake));
dd0->a = dd2->a;dd0->b = dd2->b;
dd0->n = NULL;dd0->u = dd2;
dd2=dd0;
}
dd = dd2;
for(i = 0; i<n ; i++)
{
dd1 = dd->u;
dd->b = dd1->b;
dd->a = dd1->a;
dd = dd->u;
}
p.b=(p.b%15)+1;

}
}
fflush(stdin);
dd = &q;
_sleep(200);
}
}

Ⅱ 如何编写C语言程序使得输入编号就可以显示其他的个人信息

1、写一个结构体数组用来记录信息

这里我写了一个可以存储一个人的姓名、电话、邮箱的结构体。

structnote{
charname[100];
charphone[100];
charmail[100];
}people[1000];

2、用文件储存更加方便

p=fopen("list.txt","r");
if(p==NULL)
{
fclose(p);
p=fopen("list.txt","w");
fclose(p);
}

3、写一个简单的界面(可以用死循环)

while(1)
{
n=0;
p=fopen("list.txt","r");
while(fscanf(p,"%s%s%s",people[n].name,people[n].phone,people[n].mail)!=EOF)
n++;
fclose(p);
///--------一次循环更新一次数据

4、写一个简单的查找程序

intk;
cout<<"输入1读取,输入2输入"<<endl;
cin>>k;
if(k==1)
{
cout<<"输入信息"<<endl;
chars[100];
cin>>s;
boolok=0;
for(i=0;i<strlen(s);i++)
if(s[i]>='0'&&s[i]<='9')
ok=1;
//自动识别输入的是姓名还是电话号码
if(ok==0)
{
//cout<<"通过姓名找到联系人"<<endl;
//system("pause");
boolyou=0;
for(i=0;i<n;i++)
if(strcmp(s,people[i].name)==0)
{
you=1;
cout<<"姓名"<<people[i].name<<endl;
cout<<"电话号码"<<people[i].phone<<endl;
cout<<"邮箱"<<people[i].mail<<endl;
}
if(you==0)
cout<<"没有通过姓名找到联系人"<<endl;
}
if(ok==1)
{
//cout<<"通过电话找联系人"<<endl;
//system("pause");
boolyou=0;
for(i=0;i<n;i++)
if(strcmp(s,people[i].phone)==0)
{
you=1;
cout<<"姓名"<<people[i].name<<endl;
cout<<"电话号码"<<people[i].phone<<endl;
cout<<"邮箱"<<people[i].mail<<endl;
}
if(you==0)
cout<<"没有通过电话找到联系人"<<endl;
}

5、添加信息的代码

if(k==2)
{
p1=fopen("list.txt","a+");
charss[1000];
cout<<"请输入姓名"<<endl;
cin>>ss;
fprintf(p1,"%s ",ss);
cout<<"请输入电话"<<endl;
cin>>ss;
fprintf(p1,"%s ",ss);
cout<<"请输入邮箱"<<endl;
cin>>ss;
fprintf(p1,"%s ",ss);
fclose(p1);
}
}

最终的程序

#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cmath>
usingnamespacestd;
FILE*p,*p1;
structnote{
charname[100];
charphone[100];
charmail[100];
}people[1000];
intmain()
{
intn=0,i,j;
p=fopen("list.txt","r");
if(p==NULL)
{
fclose(p);
p=fopen("list.txt","w");
fclose(p);
}
while(1)
{
n=0;
p=fopen("list.txt","r");
while(fscanf(p,"%s%s%s",people[n].name,people[n].phone,people[n].mail)!=EOF)
n++;
fclose(p);
///---------------
intk;
cout<<"输入1读取,输入2输入"<<endl;
cin>>k;
if(k==1)
{
cout<<"输入信息"<<endl;
chars[100];
cin>>s;
boolok=0;
for(i=0;i<strlen(s);i++)
if(s[i]>='0'&&s[i]<='9')
ok=1;
if(ok==0)
{
//cout<<"通过姓名找到联系人"<<endl;
//system("pause");
boolyou=0;
for(i=0;i<n;i++)
if(strcmp(s,people[i].name)==0)
{
you=1;
cout<<"姓名"<<people[i].name<<endl;
cout<<"电话号码"<<people[i].phone<<endl;
cout<<"邮箱"<<people[i].mail<<endl;
}
if(you==0)
cout<<"没有通过姓名找到联系人"<<endl;
}
if(ok==1)
{
//cout<<"通过电话找联系人"<<endl;
//system("pause");
boolyou=0;
for(i=0;i<n;i++)
if(strcmp(s,people[i].phone)==0)
{
you=1;
cout<<"姓名"<<people[i].name<<endl;
cout<<"电话号码"<<people[i].phone<<endl;
cout<<"邮箱"<<people[i].mail<<endl;
}
if(you==0)
cout<<"没有通过电话找到联系人"<<endl;
}

}
if(k==2)
{
p1=fopen("list.txt","a+");
charss[1000];
cout<<"请输入姓名"<<endl;
cin>>ss;
fprintf(p1,"%s ",ss);
cout<<"请输入电话"<<endl;
cin>>ss;
fprintf(p1,"%s ",ss);
cout<<"请输入邮箱"<<endl;
cin>>ss;
fprintf(p1,"%s ",ss);
fclose(p1);
}
}
return0;
}

Ⅲ 请用c语言编程实现在计算机屏幕上分两行输出你的班级学号和姓名.

#include<stdio.h>
void
main(){
printf("班级:2015级计算机应用1班\n");
printf("学号:123456789
\t姓名:张三");
}
很简单,就两个输出语句,\n意思就是换行,\t是空8个字符的位置

Ⅳ 请写出一个能显示自己班级和姓名的c语言程序,要求有完整的程序代码

#include<stdio.h>
int main()
{
printf("你所需要写的学号,姓名,班级\n");
return 0;

}