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$J$5$$!#(B
$B%U%!%$%k$NCf$N?t$N:GBgCM$r=PNO$9$k%W%m%0%i%`$r=q$-$J$5$$!#(B
$BNc(B
sort[Enter]
3[Enter]
1[Enter]
2[Enter]
[Ctrl-Z][Enter]
$B$=$NB>(B
$BNc(B
echo abc > file1
echo def >> file1
$BNc(B
dir | sort
dir | more
dir | sort | more
10-2. C $B8@8l$NFHFC$N5-K!(B
$B<0$NCM(B
i=j=0
if(x!=0){}
if(x){}
$B1i=,(B10-2
$BBeF~1i;;;R!"%$%s%/%j%a%s%H!"%G%/%j%a%s%H(B
$B1i=,(B10-3
#include <stdio.h>
main(){
int i,j;
printf("i=0 $B$G(B i $B$K(B 1 $B$rA}$d$9(B\n");
i=0;j=(i=i+1);printf("i $B$NCM(B %d, $B<0$NCM(B %d\n",i,j);
i=0;j=(i+=1);printf("i $B$NCM(B %d, $B<0$NCM(B %d\n",i,j);
i=0;j=(++i);printf("i $B$NCM(B %d, $B<0$NCM(B %d\n",i,j);
i=0;j=(i++);printf("i $B$NCM(B %d, $B<0$NCM(B %d\n",i,j);
}
#include <stdio.h>
main(){
char x[]="abcdefg";
char y[]="hijklmn";
char z[50];
int i,j;
i=0;
j=0;
while(x[j]!='\0'){
z[i++]=x[j++];
}
j=0;
while(y[j]!='\0'){
z[i++]=y[j++];
}
z[i]='\0';
printf("%s\n",z);
}
$B1i=,(B10-4
#include <stdio.h>
main(){
float x[]={3.1, 2.5, 6.3, 0};
float s=0;
int i=0;
while(x[i]!=0){
/* $B$3$3$KBeF~1i;;;R$H%$%s%/%j%a%s%H$r;H$C$?J8$r0l$D$@$1=q$/(B */
}
printf("$B9g7W(B %f\n",s);
}
$B%R%s%H(B
s=s+x[i];
i=i+1;
for $BJ8(B
for($B0lHV$O$8$a$K$@$1
for(i=0;i<10;++i){
printf("%d\n",i);
}
i=0;
while(i<10){
printf("%d\n",i);
++i;
}
$B1i=,(B10-5
#include <stdio.h>
#define N 3
main(){
int i;
float x[N]={3.2, 1.2, 5.4};
for(i=0; i<N; ++i){
printf("x[%d]=%f\n",i,x[i]);
}
}
$B1i=,(B10-6
#include <stdio.h>
main(){
int i;
char x[]="abcdefg";
i=0;
while(x[i]!='\0'){
printf("%c\n",x[i]);
++i;
}
}
10-3. $BO@M}1i;;(B
if(A){
if(B){
X;
}
}
if(A){
X;
}else{
if(B){
X;
}
}
A NOT A
[email protected])(B [email protected])(B
[email protected])(B [email protected])(B
if((A)&&(B)){ X; }
while((A)&&(B)){ X; }
if((A)||(B)){ X; }
while((A)||(B)){ X; }
$B1i=,(B10-7
#include <stdio.h>
main(){
float a[]={2,1};
float x;
printf("%fx+%f=0 $B$N2r$O(B",a[1],a[0]);
if(/* a[1] $B$b(B a[0] $B$b(B 0 */){
printf("$BG$0U$NCM(B\n");
}
if(/* a[1] $B$O(B 0 $B$@$,!"(B a[0] $B$O(B 0 $B$G$J$$(B*/){
printf("$B$J$7(B\n");
}
if(/* a[1] $B$O(B 0 $B$G$J$$(B */){
/* x $B$N7W;;(B */
printf("%f\n",x);
}
}
10-4. $BF~NO(B
getchar
while($B0lJ8;zFI$_!"FI$_9~$s$@J8;z$,(B EOF $B$G$J$$$H$-(B){
$BFI$s$@J8;z$r=hM}$9$k(B
}
while((c=getchar())!=EOF){
$BFI$_9~$s$@J8;z$NF~$C$F$$$kJQ?t(B c $B$KBP$9$k=hM}(B
}
#include <stdio.h>
main(){
char c;
while((c=getchar())!=EOF){
printf("%c",c);
}
}
$B1i=,(B10-8
#include <stdio.h>
main(){
char c;
int n=0;
while((c=getchar())!=EOF){
/* $B0lJ8;z
$B1i=,(B10-9
$B%R%s%H(B
$B1i=,(B10-10
$B1i=,(B10-11
$B1i=,(B10-12
abc
def
ghi
1: abc
2: def
3: ghi
scanf
scanf("%d",&i);
#include <stdio.h>
main(){
float x;
int c;
while((c=scanf("%f",&x))!=EOF){
if(c==1){ /* x $B$KCM$,BeF~$5$l$?;~$@$1(B */
printf("\t%f\n",2*x);
}
}
}
$B1i=,(B10-13
$B1i=,(B10-14
$B1i=,(B10-15
$B:dK\D>;V(B <[email protected]>
$BEl5~EE5!Bg3X9)3XIt>pJsDL?.9)3X2J(B