You are on page 1of 202

C

C7
C++


QQ:77025077
:http://blog.csdn.net/yincheng01
:http://www.weibo.com/yincheng8848
Mail:yinc13@mails.tsinghua.edu.cn

:http://www.itcast.cn


http://www.itcast.cn

C

C7

1.

2.

3.

4.C

5.C

6.C/C++

www.itcast.cn

7.1
A.cB.h


C

www.itcast.cn

7.1.1

4 www.itcast.cn

7.1.2HelloWorld
HelloWorld
4
HelloWorld
C

www.itcast.cn

7.1.3


C

.c
.h

www.itcast.cn

7.1.4
#include#define
C


C
3

www.itcast.cn

7.1.5
c

DOS
Windows.objUnix
.o





www.itcast.cn

7.1.6



cA.cB.cc

A.objB.objA.cCCB.cA.obj
CB.obj
A.objresolve

B.cC

www.itcast.cn

7.1.7








www.itcast.cn

7.1.8

C






www.itcast.cn

7.1.9


1






2



warning


www.itcast.cn

7.1.10





unresolved

www.itcast.cn

7.1.11










0



www.itcast.cn

7.1.12









DEBUG

www.itcast.cn

7.1.13



#
C


C
3

www.itcast.cn

7.1.14

#define#define






www.itcast.cn

7.1.15

#define



#include <stdio.h> /*printf*/
#include <conio.h> #define SIDE 5
#define SQUARE SIDE*SIDE /**/
#define PI 3.14159265 #define OUTPUT printf("Hello,C\n");
void main(void /**/
{
int x=SQUARE;
printf("x is %d\n",x);
if(PI<4)
OUTPUT
printf("PI is %f",PI);
getchar();
/**/
}
www.itcast.cn

7.1.16#define
#defineconst
#defineconst
const
#define


#define num 10;
void disp()
{
int num;
cout<<num;
}
dispint num;
int 10const int num=10;
www.itcast.cn

7.1.17
1
2.C

#define N 3O
main( )
{
int i;
for(i=1;i<=N;i++)
printf("%d\n",i);
}

www.itcast.cn

7.1.18


#define PRICE 88 #define PRICE 88
#define PRICE 100
main( )

{

printf("PRICE IS %d",PRICE);
}

PRICE IS 88
88 IS 88PRICE 88
www.itcast.cn

7.1.19

7.4
#define PRICE 88
main( )
{
int BOOK_PTICE=10;
}
BOOK_PTICEPRICEBOOK_88

www.itcast.cn

7.1.20


#define M 10
#define N 2
#define X M+100
#define Y M*N
main( )
{ printf("M=%d\nN=%d\nX=%d\nY=%d\n",M,N,X,Y);}

M=10
N=2
X=110
Y=20
#define X M+100M

www.itcast.cn

7.1.21

# undef
#define N 100
main()
{

}
#undef N
max()
{

}
Nmainmax

www.itcast.cn

7.1.22


#define ()
#define ADD(x) x*10

/**/
()

a =ADD (3);
/**/
3
x

a =3*10
www.itcast.cn

7.1.23
#define CUBE(x) ((x)* (x)* (x))
main( )
{
y= CUBE (z);z
double y;
((x)* (x)* (x))x, i=
float z=10; CUBE (j);j((x)* (x)*
int i; (x))x,CUBE
int j=2; yi
y= CUBE (z);
i= CUBE (j);
printf("y=%8.1f\ni=%d\n",y,i);
}

y=1000.0
i=8

www.itcast.cn

7.1.24

#include "stdio.h"
#define exchange(a,b) { int t; t=a;a=b;b=t;}
void main()
{
int x=10;
int y=20;
printf("x=%d; y=%d\n",x,y);
exchange(x,y);
printf("after exchange:x=%d; y=%d\n",x,y);
}

x=10; y=20
after exchange:x=20; y=10

www.itcast.cn

7.1.25
C#include


#include <>

#include




#include
#include D:\A\B\C.h
#include ..\X.h /*X.h
*/
include
include
#include <stdio.h, conio.h>
www.itcast.cn

7.1.26
include
include
include
#include m1.h,m2.h #include m1.h,m2.h

#include m1.h #include m2.h

.h

.c

www.itcast.cn

7.1.27




#if
1
#else
2
ifdef
#endif
ifndef
#define1
#ifndef 2
1
#else
2
#endif

www.itcast.cn

7.1.28

#if
1
#else
2
#endif

(0)
1 2
www.itcast.cn

7.1.29
CC









www.itcast.cn

7.1.30
C
for1+2+3+n





1 2 3 4


unicode

www.itcast.cn
7.2C




head 1249 1356 1475 1021
A B C D
1249
1356 1475 1021 \0


www.itcast.cn

7.2.1C




www.itcast.cn

7.2.2C
struct Student
{ int num;
float score;
struct Student *next;
}a,b,c;
a b c
num 10101 10103 10107
score 89.5 90 85
next

a.next=&b; b.next=&c;
www.itcast.cn

7.2.3C

a b c
num 10101 10103 10107
score 89.5 90 85
next

www.itcast.cn

7.2.4 C


head=&a; a.next=&b;
b.next=&c; c.next=NULL;
head a b c
num 10101 10103 10107
score 89.5 90 85
next NULL
www.itcast.cn

7.2.5 C
#include <stdio.h>
struct Student
{ int num;
float score;
struct Student *next;
};

www.itcast.cn

7.2.6C
int main()
{ struct Student a,b,c,*head,*p;
a. num=10101; a.score=89.5;
b. num=10103; b.score=90;
c. num=10107; c.score=85;
head=&a; a.next=&b;
b.next=&c; c.next=NULL;
p=head;
do
{printf(%ld%5.1f\n,p->num,p->score);
p=p->next;
}while(p!=NULL);
return 0;
}

www.itcast.cn

7.2.7C
head a b c
10101 10103 10107 num
p score
89.5 90 85
NULL next
p=head;
do
{printf(%ld%5.1f\n,p->num,p->score);
p=p->next; p=&b;
}while(p!=NULL);
return 0;
}
www.itcast.cn

7.2.8C

head a p b c
10101 10103 10107 num
89.5 90 85 score
NULL next

p=head;
do
{printf(%ld%5.1f\n,p->num,p->score);
p=&b;
p=p->next;
}while(p!=NULL);
return 0; www.itcast.cn

7.2.9C
head a b p c
10101 10103 10107 num
89.5 90 85 score
NULL next
p=head;
do
{printf(%ld%5.1f\n,p->num,p->score);
p=p->next; p=&c;
}while(p!=NULL);
return 0;
} www.itcast.cn

7.2.10C



www.itcast.cn

7.2.11C

3head,p1p2
struct Student
mallocp1p2

p1=p2=(struct Student*)malloc(LEN);

p1
p2

www.itcast.cn

7.2.12C

p1

scanf("%ld,%f",&p1->num,&p1->score);

p1
10101
p2 89.5

www.itcast.cn

7.2.13C

p1
scanf("%ld,%f",&p1->num,&p1->score);
head

head
p1
10101
p2 89.5

www.itcast.cn

7.2.14C

p1

head
p1
10101
p2 89.5

www.itcast.cn

7.2.15C

p1

p1=(struct Student*)malloc(LEN);
scanf("%ld,%f",&p1->num,&p1->score);

head p1
10101 10103
p2 89.5 90

www.itcast.cn

7.2.16C

next

p2->next=p1;
p2

head p1
10101 10103
p2 89.5 90

www.itcast.cn

7.2.17C

next

p2->next=p1;
p2
p2=p1;

head p1 p2

10101 10103
89.5 90

www.itcast.cn

7.2.18C

p1

head p1 p2

10101 10103
89.5 90

www.itcast.cn

7.2.19C

p1

p1=(struct Student*)malloc(LEN);
scanf("%ld,%f",&p1->num,&p1->score);

head p2 p1
10101 10103 10107
89.5 90 85

www.itcast.cn

7.2.20C

next

p2->next=p1;
p2

head p2 p1
10101 10103 10107
89.5 90 85

www.itcast.cn

7.2.21C

next

p2->next=p1;
p2
p2=p1;

head p1 p2

10101 10103 10107


89.5 90 85

www.itcast.cn

7.2.22C

p1

head p1 p2

10101 10103 10107 0


89.5 90 85

www.itcast.cn

7.2.23C

p1

p1=(struct Student*)malloc(LEN);
scanf("%ld,%f",&p1->num,&p1->score);

head p2 p1
10101 10103 10107 0
89.5 90 85

www.itcast.cn

7.2.24C

0

p2->next=NULL;

head p2 p1
10101 10103 10107 0
89.5 90 85
NULL
www.itcast.cn

7.2.25C
#include <stdio.h>
#include <stdlib.h>
#define LEN sizeof(struct Student)
struct Student
{ long num;
float score;
struct Student *next;
};
int n;

www.itcast.cn

7.2.26C
struct Student *creat(void)
{ struct Student *head,*p1,*p2; n=0;
p1=p2=( struct Student*) malloc(LEN);
scanf(%ld,%f,&p1->num,&p1->score);
head=NULL; p1
while(p1->num!=0)
p2
{n=n+1;
p2p1
if(n==1) head=p1;
else p2->next=p1;
p2=p1;
p1=(struct Student*)malloc(LEN);
scanf(%ld,%f,&p1->num,&p1->score);
}
p2->next=NULL; return(head); www.itcast.cn

7.2.27C
int main()
{ struct Student *pt;
pt=creat();
printf(\nnum:%ld\nscore:%5.1f\n,
pt->num,pt->score);
return 0;
}

www.itcast.cn
7.2.28C

print

p 1001 1003 1005


67.5 87 99
NULL
www.itcast.cn

7.2.29C

p
printf("%ld %5.1f\n",p->num,p->score);
p

p 1001 1003 1005


67.5 87 99
NULL
www.itcast.cn

7.2.30C

p
printf("%ld %5.1f\n",p->num,p->score);

p
p=p->next;
p
1001 1003 1005
67.5 87 99
NULL
www.itcast.cn

7.2.31 C

p
printf("%ld %5.1f\n",p->num,p->score);
p
p=p->next;
p
1001 1003 1005
67.5 87 99
NULL
www.itcast.cn

7.2.32 C

p
printf("%ld %5.1f\n",p->num,p->score);
p
p=p->next; p=NULL;
p
1001 1003 1005
67.5 87 99
NULL
www.itcast.cn

7.2.33C
void print(struct Student *p)
{
printf("\nThese %d records are:\n",n);
if(p!=NULL)
do
{ printf("%ld %5.1f\n",
p->num,p->score);
p=p->next;
}while(p!=NULL);
}
www.itcast.cn

7.2.34C









www.itcast.cn

7.2.35







HEAD
A1
1AB



www.itcast.cn

7.2.36

www.itcast.cn

7.2.37


www.itcast.cn

7.2.38


1
headE1Einsert

E2-
>nextEinsert->next
Einsert
E1->next
NULLEinsert
www.itcast.cn

7.2.39

ABCD
DCBA

www.itcast.cn

7.2.40

1

1


void freeAll(STU* head)
{
STU* p=NULL,*q=NULL;
p=head;
while(p->next!=NULL)
{
q=p->next;
p->next=q->next; /**/
free(q); /**/
}
free(head); /*1*/
}
www.itcast.cn

7.2.41
.

www.itcast.cn

7.2.42

1 2 3 4

www.itcast.cn

7.3

www.itcast.cn

7.3.1


1


1
1
NULL
2
1
NULL
www.itcast.cn

7.3.2



student
struct student
/*student*/
{
int num;
/**/
int score;
/**/
struct student* next;
/**/
struct student* prev;
/**/
};

www.itcast.cn

7.3.3



FILOFirst In
Last Out


www.itcast.cn

7.3.4

1
top
C

2
top
top

www.itcast.cn

7.3.5







topNULL

www.itcast.cn

7.3.6
C


ABAB
B
B
B
B
B
B
B
A
www.itcast.cn

7.3.7



FIFOFirst In First Out

www.itcast.cn

7.3.8





1 2 3 4

www.itcast.cn

7.4C

www.itcast.cn

7.4.1C

www.itcast.cn

7.4.2

www.itcast.cn

7.4.3C

www.itcast.cn

7.4.4
America Europe Asia





www.itcast.cn

7.4.5


3D

C
C
--Windows

www.itcast.cn

7.5 100C

C100

www.itcast.cn

100C

(1-4)
(5-28)
(29-54)
(55-75)
(76-100)

100C
1 bool , float,
if
0, 0.0 , FALSE
int n
if
if ( n == 0 )
if ( n != 0 )


100C
1 bool flag
if
if ( flag ) if ( !flag )

100C
2 float x if

const float EPSINON =
0.00001; if ((x >= -
EPSINON) && (x <= EPSINON)
===
>=<=

100C
3 char *p if

if (p == NULL) if (p !=
NULL)

100C
2 Linux 32 C
sizeof
char str[] = Hello ;
char *p = str ;
int n = 10;

1sizeof (str ) =
2sizeof ( p ) = 3
sizeof ( n ) =
162434

100C
4void Func ( char str[100])
{
;
}
sizeof( str ) =
5void *p = malloc( 100 );
sizeof ( p ) =
4454

100C
3 long a=0x801010;
a+5=?
0x801010
1000 0000 0001 0000 0001 0000
83927205
8392725

100C
4a
e) 10;
f) 10 ;
g)
;
h) 10
;
e)int * a[10]; f)int (*a)[10]
g)int (*a)(int); h) int (*a[10])(int)

100C
5
typedef union {long i; int k[5]; char c;} DATE;
struct data { int cat; DATE cow; double dog;} too;
DATE max;
printf("%d",sizeof(struct date)+sizeof(max));
_____
DATEunion, .
int[5], 20. 20
datastruct, . int4 +
DATE20 + double8 = 32.
20 + 32 = 52.
...16, int2,
int2 + DATE10 + double8 = 20

100C
6
int main()
{
char a;
char *str=&a;
strcpy(str,"hello");
printf(str);
return 0;
}
str




100C
7
char* s="AAA";
printf("%s",s);
s[0]='B';
printf("%s",s);

"AAA"s
s
cosnt char* s="AAA";
s[0]

100C
8 int (*s[10])(int)
int (*s[10])(int)
int func(int param)


100C
9 cc++struct
cc++struct
cstruct
c++structc++struct
class
structpublicclass
private

100C
10void getmemory(char *p)
{
p=(char *) malloc(100);
strcpy(p,hello world);
}
int main( )
{
char *str=NULL;
getmemory(str);
printf(%s/n,str);
free(str);
return 0;
}
getmemorymalloc
freestr

100C
11 char szstr[10];
strcpy(szstr,"0123456789");



100C
12





100C
13 void main()
{
char aa[10];
printf(%d,strlen(aa));
}

sizeof()
strlen()


100C
14struct A
{
char t:4;
char k:4;
unsigned short i:8;
unsigned long m;
};sizeof(A) = ?
8

100C
15 struct name1{
char str;
short x;
int num;
}sizeof(name1)?
8

100C
16 struct name2{
char str;
int num;
short x;
};sizeof(name2)
12

100C
17
wap( int* p1,int* p2 )
{
int *p;
*p = *p1;
*p1 = *p2;
*p2 = *p;
}
p

100C
18 cc++struct
cc++struct
cstruct
c++structc++struct
class
structpublicclass
private

100C
19 (void *)ptr (*(void**))ptr
ptr
(void *)ptr (*(void**))ptr


100C
200x100000
(unsigned int*)0x100000 = 1234;
0x100000

*((void (*)( ))0x100000 ) ( );
0x100000,:
(void (*)())0x100000
:
*((void (*)())0x100000)();

100C
21 int a,b,c c=a+b ,
,clong int,


bool add (int a, int b,int *c)
{
*c=a+b;
return (a>0 && b>0 &&(*c<a || *c<b) || (a<0
&& b<0&&(*c>a || *c>b)));
}
100C

221


100C
232


100C
253


100C
264


100C
27 volatile?
volatile



volatile
1).
2). (Non-
automatic variables)
3).

100C
28

0x67a90xaa66
ANSI

typecast


int *ptr;
ptr = (int *)0x67a9;
*ptr = 0xaa55;

100C
29 ifndef/define/endif



100C
30#include <filename.h>
#include filename.h
#include
<filename.h>
filename.h ;
#include filename.h
filename.h

100C
31const

1 const
2const
const



100C
32 static


1.static
2.static

100C
33


100C
34

extern


extern



100C
35.C

C
static
C
C


100C
36


100C
37 Heapstack
Heapstack
Stack/
Heap/
StackHeap
Cmalloc
,C++new

,


100C
38swapxy


#define swap(x, y) (x)=(x)+(y);(y)=(x)
(y);(x)=(x)(y);

100C
39

#define Min(X, Y)
((X)>(Y)?(Y):(X))//;

100C
40(5
)








100C
41volatile



100C
42 int main()
{
int x=3;
printf("%d",x);
return 1;
}

1
mianc0
0

100C
43table


#define NTBL(table)
(sizeof(table)/sizeof(table[0]))

100C
44 A.c B.cc
static,?
static
?
static




extern

100C
45 static

static
;

100C
46 static

static


100C
47 static
static


100C
45-47
()static










static
(static)



100C
48___
_______
(stack)

heap

100C
49






100C
50

2A,B, .
:
pushA;
:
(1)B
(2)A
poppushB
(3)Bpop

100C
51,C
,C++?

cc++inline

100C
52 1. #define
1
#define SECONDS_PER_YEAR
(60 * 60 * 24 * 365)UL

100C
53 Typedef C

#define dPS struct s *
typedef struct s * tPS;
dPS tPS s


typedef
dPS p1,p2;
tPS p3,p4;

struct s * p1, p2;
p1p2
p3 p4

100C
54 C++ C
extern C
C++C
C++
C
void foo(int x, int y);
C _foo
C++_foo_int_int
C++ C
externC

100C
55 for

100C

100C
56for( 1 )

while(1)

100C
57 dowhilewhiledo




100C
58
#include <stdio.h>
int main()
{
int a,b,c,d;
a=10;
b=a++;
c=++a;
d=10*a++;
printf("bcd%d%d%d"bcd;
return 0;
}
1012120

100C
59 unsigned char *p1;
unsigned long *p2;
p1=(unsigned char *)0x801000;
p2=(unsigned long *)0x810000;
p1+5= ;
p2+5= ;
0x8010050x810020

100C
60 main()
{
int a[5]={1,2,3,4,5};
int *ptr=(int *)(&a+1);
printf(%d%d,*(a+1),*(ptr-1));
}

2,5

100C
61?
int a[60][250][1000],i,j,k;
for(k=0;k<=1000;k++)
for(j=0;j<250;j++)
for(i=0;i<60;i++)
a[i][j][k]=0;


100C
62,
:
#define SQUARE(a)((a)*(a))
int a=5;
int b;
b=SQUARE(a++);


++ --

2536

100C
63#define Max_CB 500
void LmiQueryCSmd(Struct MSgCB * pmsg)
{
unsigned char ucCmdNum;
......
for(ucCmdNum=0;ucCmdNum<Max_CB;ucCmdN
um++)
{
......;
}
}

unsigned char // 0~255
char // -128~127

100C
64
C
while(1){}for(;;)

100C
65

100C
66

100C
67 int modifyvalue()
{
return(x+=10);
}
int changevalue(int x)
{
return(x+=1);
}
void main()
{
int x=10;
x++;
changevalue(x);
x++;
modifyvalue();
printf("First output:%dn",x);
x++;
changevalue(x);
printf("Second output:%dn",x);
modifyvalue();
printf("Third output:%dn",x);
}?
121313

100C
68switch()
switch

100C
69
i nclude<stdio.h>
main()
{
int a,b,c,d;
a=10;
b=a++;
c=++a;
d=10*a++;
printf("bcd%d%d%d"bcd;
return 0;
}
1012120

100C
70

100C
71x2

void main()
{
int a;
scanf(%d,&a);
printf(%c,(a)&(a-1)?n:y); //
yn
}

100C
72
C
__interrupt__interrupt
(ISR)
__interrupt double compute_area (double radius)
{
double area = PI * radius * radius;
printf(" Area = %f", area);
return area;
}

1). ISR
2). ISR

3). //
/ISR
ISRISR

4). printf()



100C
73
void foo(void)
{
unsigned int a = 6;
int b = -20;
(a+b > 6)? puts("> 6") : puts("<= 6");
}

C

>6
-20
6



100C
74
unsigned int zero = 0;
unsigned int compzero = 0xFFFF;
/*1s complement of zero */
int16

unsigned int compzero = ~0;

PC







100C
75

char *ptr;
if ((ptr = (char *)malloc(0)) == NULL)
puts("Got a null pointer");
else
puts("Got a valid pointer");

~~

100C

C


100C
76 strcpy
strcpy char *strcpy(char *strDest,
const char *strSrc); strDest strSrc
1
C++/C strcpy

2strcpy strSrc strDest


char *

100C
77
int binary_search(int* arr, int key, int n)
{
int low = 0;
int high = n - 1;
int mid;
while (low <= high)
{
mid = (high + low) / 2;
if (arr[mid] > k)
high = mid - 1;
else if (arr[mid] < k)
low = mid + 1;
else
return mid;
}
return -1;
}

100C
78 C
1
unsigned int TestAsOne0(char log)
{
int i;
unsigned int num=0, val;
for(i=0; i<8; i++)
{
val = log >> i; //
val &= 0x01; //1
if(val)
num++;
}
return num;
}

100C
79 C

int Invert(char *str)
{
int num=0;
while(*str!='\0')
{
int digital=*str-48;
num=num*10+digital;
str=str+1;
}
return num;
}
100C

80 C
void IntToCharChange(int num, char* pval)
{
char strval[100];
int i, j;
int val0 = 0;
int val1 = 0;
val0 = num;
for(i=0; i<100; i++)
{
val1 = val0 % 10; //
val0 = val0 / 10; //
strval[i] = val1 + 48; //
if(val0 < 10)
{
i++;
strval[i] = val0 + 48;
break;
}
}
for(j=0; j<=i; j++) //
pval[j] = strval[i-j];
pval[j] = '\0';

100C
81strcmp
int mystrcmp(const char* str1, const char* str2)
{
assert((str1 != NULL) && (str2 != NULL));
int ret = 0;
while (!(ret = *(unsigned char*)str1 - *(unsigned char*)str2) && *str2)
{
str1++;
str2++;
}
if (ret > 0)
ret = 1;
else if (ret < 0)
ret = -1;
return ret;
}

100C
82 C

void AntitoneValue(char* father, char* child)
{
int i;
char source[100];
int j = 0;
while(father[j]) //source[j]
{
source[j] = father[j];
j++;
if(j > 99)
return;
}
source[j] = '\0';
for(i=0; i<j; i++)
child[i] = source[j-i-1]; //
child[i] = '\0';
}

100C
83 C

int search(char *cpSource, int n, char ch) //



{
int i;
for(i=0; i<n && *(cpSource+i) != ch; ++i);
return i;
}

100C
84 C

int ChildString(char*p) //
{
char *q=p;
int stringlen=0, i=0,j=1,len=0,maxlen=1;
while(*q!=\0) //strlen,stringlen
{
Stringlen++;
q++;
}
while( i< Stringlen )
{
if(*(p+i)==*(p+j)&&j< Stringlen)
{
len++; //
i++;
j++;
}
else
{
if(len>maxlen) //
{
maxlen=len+1;
len=0;
}
else
len=0;
i++;
j++;

100C
85
p1
p2 p2 p1

int testLinkRing(Link *head)


{
Link *t1=head,*t2=head;
while( t1->next && t2->next)
{
t1 = t1->next;
if (NULL == (t2 = t2->next->next))
return 0; //
if (t1 == t2)
return 1;
}
return 0;
}

100C
86A,CA,
,A.()
void BubbleSort(double arr[], int n)
{
int ij
int exchange = 1 //
for(i=1;i<n;i++)
{ //n-1
exchange=0 //
for(j=n-1;j>=ij--) //R[i..n]
if(arr[j+1] > arr[j])
{//
arr[0]=arr[j+1] //R[0]
arr[j+1]=arr[j]
arr[j]=arr[0]
exchange=1 //
}
if(!exchange) //
return
} //endfor()
}

100C
87PP

// //
Status ListDelete_DuL(DuLinkList &L,int i,ElemType Status ListInsert_DuL(DuLinkList &L,int i,ElemType &e)
&e) {
{ if(!(p=GetElemP_DuL(L,i)))
return ERROR;
if(!(p=GetElemP_DuL(L,i))) return ERRO if(!(s=(DuLinkList)malloc(sizeof(DuLNode))))
R;
return ERROR;
e=p->data;
s->data=e;
p->prior->next=p->next;
s->prior=p;
p->next->prior=p->pror;
p-> next -> prior =s;
free(p);
p->next=s;
return OK;
} s->next=p->next->next;
return OK;
}

100C
88

void reverse(test* head)


{
test* pe = head;
test* ps = head->next;
while(ps)
{
pe->next = ps->next;
ps->next = head;
head = ps;
ps = pe->next;
}
}

100C
89

#include <stdio.h>
main()
{ int
a[2][3]={{1,2,3},{4,5,6}};
printf("array b:\n");
int b[3][2],i,j;
for(i=0;i<=2;i++)
printf("array a:\n");
{ for(j=0;j<=1;j++)
for(i=0;i<=1;i++)
printf("%5d",b[i][j]);
{ for(j=0;j<=2;j++)
printf("\n");
{ printf("%5d",a[
i][j]); }
b[j][i]=a[i][j]; }
}
printf("\n");
}

100C
90
main()
#include <stdio.h>

{
char string[81];
int i,num=0,word=0;
char c;
gets(string);
for(i=0;(c=string[i])!='\0';i++)
if(c==' ')
word=0;
else if(word==0)
{
word=1; num++; }
printf("There are %d words in the line\n",num);
}

100C
91,.

void* memcpy(void* pvTo, const void* pvFrom, size_t
size)
{
assert((pvTo != NULL) && (pvFrom != NULL));
byte* pbTo = pvTo;
byte* pbFrom = pbFrom;
while (size-- > 0)
{
*pbTo++ = *pbFrom++;
}
return pvTo;
}

100C
921234

#include "stdio.h"
#include "conio.h"
main()
{
int i,j,k;
printf("\n");
for(i=1;i<5;i++) /**/
for(j=1;j<5;j++)
for (k=1;k<5;k++)
{
if (i!=k&&i!=j&&j!=k) /*ijk
*/
printf("%d,%d,%d\n",i,j,k);
}
getch();
}

100C
93a47

main()
{
unsigned a,b,c,d;
scanf("%o",&a);
b=a>>4;
c=~(~0<<4);
d=b&c;
printf("%o\n%o\n",a,d);
}

100C
9410
main()
{
int i,j;
int a[10][10];
printf("\n");
for(i=0;i<10;i++)
{
a[i][0]=1;
a[i][i]=1;
}
for(i=2;i<10;i++)
for(j=1;j<i;j++)
a[i][j]=a[i-1][j-1]+a[i-1][j];
for(i=0;i<10;i++)
{
for(j=0;j<=i;j++)
printf("%5d",a[i][j]);
printf("\n");
}
getch();
}

100C
95strcmp

100C
96
main
main()
{
int len;
char *str[20];
printf("please input a string:\n");
scanf("%s",str);
len=length(str);
printf("the string has %d characters.",len);
getch();
}
length(p)
char *p;
{
int n;
n=0;
while(*p!='\0')
{
n++;
p++;
}
return n;
}

100C
97809*??=800*??+9*??+1 ??,8*??
9*??3??809*??

output(long b,long i)
{
printf("\n%ld/%ld=809*%ld+%ld",b,i,i,b%i);
}
main()
{
long int a,b,i;
a=809;
for(i=10;i<100;i++)
{
b=i*a+1;
if(b>=1000&&b<=10000&&8*i<100&&9*i>=100)
output(b,i);
}
getch();
}

100C
98

main()
{
5,10
int a,i,aa[4],t;
scanf("%d",&a);
aa[0]=a%10;

aa[1]=a%100/10;
aa[2]=a%1000/100;
aa[3]=a/1000;
for(i=0;i<=3;i++)
{
aa[i]+=5;
aa[i]%=10;
}
for(i=0;i<=3/2;i++)
{
t=aa[i];
aa[i]=aa[3-i];
aa[3-i]=t;
}
for(i=3;i>=0;i--)
printf("%d",aa[i]);
getch();
}

100C
99
main()
{
char str1[20],str2[20],*p1,*p2;
int sum=0;
printf("please input two strings\n");
scanf("%s%s",str1,str2);
p1=str1;p2=str2;
while(*p1!='\0')
{
if(*p1==*p2)
{
while(*p1==*p2&&*p2!='\0')
{
p1++;
p2++;
}
}
else
p1++;
if(*p2=='\0')
sum++;
p2=str2;
}
printf("%d",sum);
getch();
}

100C
100AB,


C


100C
main()
{
FILE *fp;
int i,j,n,ni;
char c[160],t,ch;
if((fp=fopen("A","r"))==NULL)
{
printf("file A cannot be opened\n");exit(0);
}
printf("\n A contents are :\n");
for(i=0;(ch=fgetc(fp))!=EOF;i++)
{
c[i]=ch;putchar(c[i]);
}
fclose(fp);
ni=i;
if((fp=fopen("B","r"))==NULL)
{
printf("file B cannot be opened\n");exit(0);
}
printf("\n B contents are :\n");
for(i=0;(ch=fgetc(fp))!=EOF;i++)
{
c[i]=ch;putchar(c[i]);
}
fclose(fp);
n=i;
for(i=0;i<n;i++)
for(j=i+1;j<n;j++)
if(c[i]>c[j]){t=c[i];c[i]=c[j];c[j]=t;}
printf("\n C file is:\n");
fp=fopen("C","w");
for(i=0;i<n;i++){putc(c[i],fp);putchar(c[i]);}
fclose(fp);
getch();
}


C C++



C/C++

www.itcast.cn
C

C++


http://www.itcast.cn

You might also like