level 8
我用的 dev c++
#include <stdio.h>
int main()
{
system("pause");
return 0;
}
这个是模板
2012年11月18日 15点11分
2
level 8
#include <stdio.h>
union {
float c;
char a[8];
}b={3.1415926};
int main()
{ int i;
for(i=0;i<8;i=i+1)
printf("%c\n",b.a[i]);
system("pause");
return 0;
}
这个是共用体的练习
2012年11月18日 15点11分
3
![[冷]](/static/emoticons/u51b7.png)
这个输出好像没啥意义
2012年11月19日 00点11分
level 8
#include <stdio.h>
int main()
{
int x=10,y=5;
int *p,*q;
p=&x;
q=&y;
*p=*p+10;
printf("x=%d, y=%d\n",x,y);
printf("*p=%d, *q=%d\n",*p,*q);
printf("p=%x, q=%x\n",p,q);
printf("&x=%x, &y=%x\n",&x,&y);
y=*p;
q=p;
*q=*q+20;
printf("x=%d, y=%d\n",x,y);
printf("*p=%d, *q=%d\n",*p,*q);
printf("p=%x, q=%x\n",p,q);
printf("&x=%x, &y=%x\n",&x,&y);
system("pause");
return 0;
}
这个是简单指针的练习
2012年11月18日 15点11分
4
level 8
#include <stdio.h>
int main()
{
int *pa,*pb,*p,x,y;
scanf("%d,%d",&x,&y);
pa=&x;
pb=&y;
printf("\n");
printf("x=%d,y=%d\n",x,y);
printf("*pa=%d,*pb=%d\n",*pa,*pb);
printf("\n");
if(*pa>*pb)
{
p=pa;
pa=pb;
pb=p;
}
printf("x=%d,y=%d\n",x,y);
printf("*pa=%d,*pb=%d\n",*pa,*pb);
system("pause");
return 0;
}
也是指针
2012年11月18日 15点11分
5
level 8
#include <stdio.h>
struct st
{
int n;
char ch;
};
void fun( struct st ex2)
{
ex2.n = ex2.n
+3
;
ex2.ch = ex2.ch-1;
}
int main()
{ struct st ex1 = {5,'t'};
fun(ex1);
printf("%d,%c",ex1.n,ex1.ch);
system("pause");
return 0;
}
这个是结构体
2012年11月18日 15点11分
6
level 8
#include <stdio.h>
struct point
{
float x;
float y;
}p1,p2;
int distance1(struct point p1,struct point p2);
int main()
{ float distance;
printf("请输入一个点\n");
scanf("%f%f",&p1.x,&p1.y);
printf("请输入一个点\n");
scanf("%f%f",&p2.x,&p2.y);
distance = distance1( p1, p2);
printf("distance=%f\n",distance);
system("pause");
return 0;
}
int distance1(struct point p1,struct point p2)
{
float d;
d=p1.x*p1.x-p2.x*p2.x+p1.y*p1.y-p2.y*p2.y;
return d;
}
2012年11月18日 15点11分
7
level 8
#include <stdio.h>
int main()
{ int A=3,B=4,C=5;
float X=1.414,Y=1.732,Z=2.712;
printf("a=%d ",A);
printf("b=%d " ,B);
printf("c=%d ",C);
printf("\n");
printf("x=%4.3f ",X);
printf("y=%4.3f ",Y);
printf("z=%4.3f\n ",Z); system("pause");
return 0;
}
这个是输出格式
2012年11月18日 15点11分
8
printf("c=%d",C); printf("\n"); 改成这样 printf("c=%d\n",C);
2012年11月19日 02点11分
level 8
#include <stdio.h>
int main()
{ int i,n;
scanf("%d",&n);
n=n&1;
printf("%d",n);
system("pause");
return 0;
}
这个是 与运算
2012年11月18日 15点11分
9
请教下,定义i什么作用?后面都没用到
2012年11月19日 02点11分
level 8
#include <stdio.h>
#include <stdlib.h>
int main()
{ int a[3][4]={{1,3,5,7,},{2,4,6,8},{10,11,12,13}};
int (*p)[4],i,j;
p=a;
for(i=0;i<3;i++)
{
for(j=0;j<4;j++)
printf("%3d",*(*(p+i)+j));
printf("\n");
}
system("pause");
return 0;
}
这个是指针数组
2012年11月18日 16点11分
10
level 8
#include <stdio.h>
int main()
{ int i,j,t,a[10];
for(i=0;i<10;i++)
scanf("%d",&a[i]);
for(i=0;i<9;i++)
for(j=i;j<9;j++)
if(a[i]<a[j+1])
{
t=a[i];
a[i]=a[j+1];
a[j+1]=t;
}
for(i=0;i<10;i++)
printf("%d ",a[i]);
system("pause");
return 0;
}
这个好像是排序
2012年11月18日 16点11分
11
level 8
#include <stdio.h>
void Sort(int Score[],int N);
int Seek(int Score[],int N,int m);
int main()
{
int i,N,m,Score[50];
scanf("%d",&N);
for(i=0;i<N;i++)
scanf("%d",&Score[i]);
Sort(Score,N);
printf("\n");
scanf("%d",&m);
for(i=0;i<N;i++)
{
printf("%d ",Score[i]);
if((i+1)%10 == 0)
printf("\n");
}
m = Seek(Score,N,m);
if(m == 0)
printf("\nno this score!\n");
else
printf("\n%d\n",m);
system("pause");
return 0;
}
void Sort(int Score[],int N)
{
int i,j,k,t;
for(i=0;i<N-1;i++)
{
k = i;
for(j=i+1;j<N;j++)
{
if(Score[k] < Score[j])
k = j;
} t = Score[k];
Score[k] = Score[i];
Score[i] = t;
}
return ;
}
int Seek(int Score[],int N,int m)
{
int i;
for(i = 0;i < N;i++)
if(Score[i] == m)
return i+1;
return 0;
}
这个是 查找 排序吧
2012年11月18日 16点11分
13
level 8
#include <stdio.h>
void tongji(int a[] ,char b[] );
void find_tihuan(char b[] ,char c[] );
int main()
{ int i;
int a[26]={0};
char b[11],c[3];
scanf("%s",b);
tongji(a,b);
for(i=0;i<26;i++)
printf("%c %d\n",'A'+i,a[i]);
printf("%s",b);
putchar('\n');
scanf("%s",c);
find_tihuan(b,c);
printf("%s",b);
system("pause");
return 0;
}
void tongji(int a[],char b[])
{
char i,j;
for(i=0;i<11;i++)
for(j=0;j<26;j++)
if((b[i]-65==j)||(b[i]-97==j))
{
a[j]+=1;
break;
}
}
void find_tihuan(char b[], char c[])
{
int i,j,k;
for(i=0;i<10;i++)
{
k=0;
for(j=0;j<2;j++)
if(c[j]==b[i])
{
k++;
i++;
}
if(k==2)
break;
}
for(j=i-2;j<i+1;j++)
scanf("%c",&b[j]);
}
2012年11月18日 16点11分
14
level 8
#include <stdio.h>
void Sort(int Score[], int N ); Insert_Sort(int Score[],int N); int main()
{ int i,N,m,Score[50];
scanf("%d",&N);
for(i=0;i<N;i++)
scanf("%d",&Score[i]);
scanf("%d",&m);
Sort(Score,N);
printf("\n");
for(i=0;i<N;i++)
{
printf("%d ",Score[i]);
if((i+1)%10 == 0)
printf("\n");
}
m = Seek(Score,N,m);
if(m == 0)
printf("\nno this score!\n");
else
printf("\n%d\n",m);
system("pause");
return 0;
} void Sort(int Score[], int N )
{
int i,j,k,t;
for(i=0;i<N-1;i++)
{
k = i;
for(j=i+1;j<N;j++)
{
if(Score[k] < Score[j])
k = j;
} t = Score[k];
Score[k] = Score[i];
Score[i] = t;
}
return ;
}
int Seek(int Score[],int N,int m) {
int i; for(i = 0;i < N;i++) if(Score[i] == m) return i+1; return 0; }
Insert_Sort(int Score[],int N) {
int i,j,k,temp; for(i=0;i<N;i++) { temp=Score[i]; j=i-1; while (j>=0&&temp<Score[j]) { Score[j+1]=Score[j]; j--; } Score[j+1]=temp;
}
}
2012年11月18日 16点11分
15
level 8
#include <stdio.h>
struct student
{
int no;
char name[8];
struct student *next;
};
int insert(struct student *head,int i);
struct student *locate(struct student *head,int i);
void create(struct student *head);
void display(struct student *head);
int main()
{ struct student *head;
int i;
scanf("%d",&i);
putchar('\n');
head=malloc(sizeof(struct student));
head->next=NULL;
create(head);
display(head);
insert(head,i);
display(head);
system("pause");
return 0;
}
int insert(struct student *head,int i)
{
struct student *p,*q;
q=locate(head , i);
if(q==NULL)
return 0;
p=(struct stydent *) malloc(sizeof(struct student));
printf("Input NO: ");
scanf("%d",&p->no);
printf("Input Name: ");
scanf("%s",p->name);
p->next=q->next;
q->next=p;
return 1;
}
struct student *locate(struct student *head,int i)
{
int pos=0;
struct student *p=head;
while(p->next!=NULL && pos<i)
{
pos++;
p=p->next;
}
if(pos==i)
return p;
else
return NULL;
}
void create(struct student *head)
{
struct student *p,*q;
int temp_no;
char temp_name[8];
q=head;
while(1)
{
printf("Input no:");
scanf("%d",&temp_no);
if(temp_no==0)
break;
printf("Input name: ");
scanf("%s",temp_name);
p=(struct student*)malloc(sizeof(struct student));
p->no=temp_no;
strcpy(p->name,temp_name);
q->next=p;
q=p;
}
q->next=NULL;
}
void display(struct student *head)
{
struct student *p=head->next;
while(p!=NULL)
{
printf("No: %5d\tName:%8s\n",p->no,p->name);
p=p->next;
}
}
2012年11月18日 16点11分
16
这是什么程序
2012年11月19日 10点11分
回复 E_Q_Kiss :也是链表
2012年11月19日 10点11分
level 8
#include <stdio.h>
int main()
{ int a[10];
int i,j,t;
for(i=0;i<10;i++)
scanf("%d",&a[i]);
for(i=0;i<9;i++)
for(j=i+1;j<10;j++)
if(a[i]<a[j])
{
t=a[i];
a[i]=a[j];
a[j]=t;
}
for(i=0;i<10;i++)
printf("%d ",a[i]);
system("pause");
return 0;
}
2012年11月18日 16点11分
17
level 8
#include <stdio.h>
int main()
{ int i,j;
char a[10][10];
for(i=0;i<10;i++)
for(j=0;j<10;j++)
a[i][j]=' ';
for(i=0;i<10;i++)
{ for(j=0;j<40-4*i;j++)
putchar(' ');
a[i][0]=1;
printf("%-8d",a[i][0]);
if(i>1)
for(j=1;j<i;j++)
{
a[i][j]=a[i-1][j]+a[i-1][j-1];
printf("%-8d",a[i][j]);
}
if(i!=0)
{a[i][i]=1;
printf("%-8d",a[i][i]);}
putchar('\n');
}
system("pause");
return 0;
}
输出 杨辉三角
2012年11月18日 16点11分
18
level 8
#include <stdio.h>
void move(char a,char c);
void hanno(int n,char a,char b,char c);
int main()
{ hanno(3,'a','b','c');
system("pause");
return 0;
}
void hanno(int n,char a,char b,char c)
{
if(n==1)
move(a,c);
else
{
hanno(n-1,a,c,b);
move(a,c);
hanno(n-1,b,c,a);
}
}
void move(char a,char c)
{
printf("%c->%c\n",a,c);
}
经典的递归 汉诺塔
2012年11月18日 16点11分
19
level 8
#include <stdio.h>
int main()
{ int i,j;
for(i=1;i<7;i++)
{
for(j=0;j<7-i;j++)
putchar(' ');
for(j=0;j<2*i-1;j++)
printf("*");
putchar('\n');
}
system("pause");
return 0;
}
这个适合新手 输出 正三角形
2012年11月18日 16点11分
20
level 8
#include <stdio.h>
#include <math.h>
void qsort(int a[],int low,int high);
void quicksort(int a[],int n);
int partitions(int a[],int low,int high);
int main()
{
int i,a[11]={0,11,12,5,6,13,8,9,14,7,10};
for(i=0;i<11;printf("%3d",a[i]),++i)
;
printf("\n");
quicksort(a,10);
for(i=0;i<11;printf("%3d",a[i]),++i)
;
putchar('\n');
system("pause");
}
void qsort(int a[],int low,int high)
{
int pivottag;
if(low<high){
pivottag=partitions(a,low,high);
qsort(a,low,pivottag-1);
qsort(a,pivottag+1,high);}
}
void quicksort(int a[],int n)
{
qsort(a,0,n);
}
int partitions(int a[],int low,int high)
{
int pivotkey=a[low];
while(low<high)
{
while(low<high && a[high]>=pivotkey)
--high;
a[low]=a[high];
while(low<high && a[low]<=pivotkey)
++low;
a[high]=a[low];
}
a[low]=pivotkey;
return low;
}
快排序
2012年11月18日 16点11分
21