當前位置:首頁 » 編程語言 » 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;

}