C:一维数组的简单读写;
#include <stdio.h>
main(){
int i,a[10];
for(i=0;i<10;i++){
scanf("%d",&a[i]);
}
for(i=0;i<10;i++){
printf("a[%d]=%dn",i,a[i]);
}
}
#include <stdio.h>
main(){
int i,a[10];
for(i=0;i<10;i++){
scanf("%d",&a[i]);
}
for(i=0;i<10;i++){
printf("a[%d]=%dn",i,a[i]);
}
}
#include <stdio.h>
main(){
int i,a[10];
for(i=0;i<10;i++){
a[i]=i;
}
for(i=0;i<10;i++){
printf("a[%d]=%dn",i,a[i]);
}
printf("nn");
for(i=9;i>=0;i--){
printf("a[%d]=%dn",i,a[i]);
}
}
#include <iostream>
using namespace std;
int main(){
int m, i;
cin >> m;
for(i=2;i<=m;i++)
if(m%i==0)
break;
if(i>m/2&&m!=1)
cout << m << "is a prime number!n";
else
cout << "No n";
return 0;
}
#include <stdio.h>
int main(){
int c,i,nwhite,nother;
int ndigit[10];
nwhite=nother=0;
for(i=0;i<10;i++)
ndigit[i]=0;
while((c=getchar())!=EOF)
if(c>='0'&&c<='9')
++ndigit[c-'0'];
else if(c==' '||c=='n'||c=='t')
++nwhite;
else
++nother;
printf("digit=");
for(i=0;i<10;i++)
printf(" %d",ndigit[i]);
printf(",white space =%d,other=%dn",nwhite,nother);
}
#include <stdio.h>
#define IN 1 /在单词内/
#defint OUT 0 /在单词外/
main(){
int c, n1, nw, nc, state;
state = OUT;
n1=nw=nc=0;
while((c=getchar())!=EOF){
++nc;
if(c=='n')
++n1;
if(c==' '||c=='n'||c=='t')
state=OUT;
else if(state==out){
state=IN;
++nw;
}
}
printf("%d %d %d n",n1,nw,nc);
}