#include#includeintmain(){char str[100];char c;scanf("%s", str);int letter =0, space =0, figure =0, character =0, i;for(i =0;(c = str[i])!='#'; i++){if(c >='a'&& c <='z'|| c >='A'&& c <='Z'){
letter = letter +1;}elseif(c ==' '){
space = space +1;}elseif(c >='0'&& c <='9'){
figure = figure +1;}else{
character = character +1;}}printf("字母数:%d,空格数:%d,数字数:%d,其它字符:%d", letter, space, figure, character);return0;}
#include#include#include#includeintmain(){int i, k;char ch[100];
FILE* fp;
fp =fopen("C:\\C\\a.txt","r");if(fp !=NULL){fscanf(fp,"%s",&ch);}for(i =0; i <=strlen(ch); i++){if(ch[i]>='0'&& ch[i]<='9'){printf("%c ", ch[i]);}}fclose(fp);return0;}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
编程序求100以内的素数,分别将它输出到显示器和x.txt文件中,要求每行5个数。
#include#include#include#includeintjudge(int n){int i;int t =1;for(i =2; i < n; i++){if(n % i ==0){
t =0;break;}}return t;}intmain(){int i, t =1;
FILE* fp;
fp =fopen("a.txt","w");if(fp !=NULL){for(i =2; i <100; i++){if(t ==6){printf("\n");fprintf(fp,"\n");
t =1;}if(judge(i)==1){printf("%d ", i);fprintf(fp,"%d ", i);
t++;}}fclose(fp);}else{exit(0);}return0;}
#include#include#include#includevoidxuanshoudefen(float(* p)[7],float defen[],int n);intmain(){int i, k;float a[2][7];float(*p)[7];
p = a;float defen[2];for(i =0; i <=1; i++){for(k =0; k <=6; k++){scanf("%f",&a[i][k]);}printf("\n");}xuanshoudefen(p, defen,2);for(i =0; i <=1; i++){printf("%5.2f\n", defen[i]);}return0;}voidxuanshoudefen(float(* p)[7],float defen[],int n){int i, k, sum, max, min;float avg;for(k =0; k <= n -1; k++){
sum =0;for(i =0; i <=6; i++){
sum = sum +*(*(p + k)+ i);}
max =*(*(p + k)+0);
min =*(*(p + k)+0);for(i =0; i <=5; i++){if(*(*(p + k)+ i +1)> max)
max =*(*(p + k)+ i +1);if(*(*(p + k)+ i +1)< min)
min =*(*(p + k)+ i +1);}
avg =(sum - min - max)*1.0/5;
defen[k]= avg;}}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
用指针的方式实现,3×3矩阵转置。
#include#include#include#includeintmain(){int a[3][3];int* pa[3];int i, j;for(i =0; i <=2; i++){
pa[i]= a[i];}for(i =0; i <=2; i++){for(j =0; j <=2; j++){scanf("%d",&a[i][j]);}}for(j =0; j <=2; j++){for(i =0; i <=2; i++){printf("%d",*(pa[i]+ j));}printf("\n");}}