国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學(xué)院 > 開發(fā)設(shè)計(jì) > 正文

編程練習(xí)三

2019-11-11 04:40:07
字體:
供稿:網(wǎng)友


程序一、編寫函數(shù)void count(char a[],char w[][10],int n,int b[])。功能是:統(tǒng)計(jì)w指向的數(shù)組中的n個(gè)單詞在a指向的字符串中各自出現(xiàn)的次數(shù)(將非字母字符看作單詞分割符),擰將統(tǒng)計(jì)結(jié)果依次保存在b指向的數(shù)組中。

#include <stdio.h>

#include <string.h>

#include <ctype.h>

 

void count(char a[], char w[][10], int n, int b[]);

 

int main()

{

    char a[100], w[10][10];

int b[100];

int n,i;

 

PRintf("Please inpu a string:/n");

scanf("%s", a);

printf("Please input the number of the Words:/n");

scanf("%d", &n);

    printf("Please input the words:/n");

for(i = 0; i < n; i++)

{

        scanf("%s", w[i]);

}

count(a, w,n,b);

 

    return 0;

}

 

void count(char a[], char w[][10], int n, int b[])

{

    int i, t;

int j = 0;

int k = 0;

int num = 0;

    int len_word;

int len_str = 0;

    

    for(i = 0; i < n; i++)

{

k = 0;

num = 0;

len_word = strlen(w[i]);

while(a[k] != '/0')

{

    len_str = 0;

j = 0;

if(isalpha(a[k]))

{   

while(a[k] == w[i][j] && a[k] != '/0')

{

len_str++;

k++;

j++;

}

}

if(len_word == len_str && !isalpha(a[k]))

{

num++;

}

            

k++;

}

b[i] = num;

}

 

for(i = 0; i < n; i++)

{

printf("%s=%d  ", w[i], b[i]);

}

printf("/n");

}

 

 

程序二、編寫函數(shù)int stat(int a[],int n,int c[][2])。a指向的數(shù)組中保存了由n個(gè)1位整數(shù)組成的數(shù)列(n為偶數(shù))。函數(shù)從前至后依次將a數(shù)組中每兩個(gè)相鄰元素拼成一個(gè)不超過2位的整數(shù),從而生成有n/2個(gè)元素組成的整數(shù)數(shù)列;統(tǒng)計(jì)該數(shù)列中不同整數(shù)各自出現(xiàn)的次數(shù),并將統(tǒng)計(jì)結(jié)果保存到c指向的二維數(shù)組中。函數(shù)返回不同整數(shù)的個(gè)數(shù)。

#include <stdio.h>

 

int start(int a[], int n, int c[][2]);

 

int main()

{

int a[100];

int c[100][2];

int n, i;

 

printf("Please input a number:");

scanf("%d", &n);

 

if(n % 2 != 0)

{

printf("Please input a new number:");

scanf("%d", &n);

}

printf("Please input the numbers:/n");

for(i = 0; i < n; i++)

{

scanf("%d", &a[i]);

}

 

    start(a, n, c);

    

    return 0;

}

 

int start(int a[], int n, int c[][2])

{

int i;

int j = 0;

int num = 0;

 

for(i = 0; i < n; i +=2)  //組成n/2個(gè)數(shù)

{

          c[j++][0] = a[i] * 10 + a[i+1];

}

 

for(i = 0; i < n/2; i++)      //統(tǒng)計(jì)出現(xiàn)的次數(shù)

{

        for(j = 0; j < n/2; j++)

{

if(c[i][0] == c[j][0])

{

num++;

}

}

c[i][1] = num;

num = 0;

}

 

for(i = 0; i < n/2; i++)   

{

printf("%5d", c[i][0]);

printf("%5d", c[i][1]);

printf("/n");

}

printf("/n");

    

}


發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 东辽县| 义乌市| 陵川县| 舒兰市| 珲春市| 清原| 宣汉县| 昌邑市| 泾川县| 建瓯市| 垣曲县| 兖州市| 象州县| 中卫市| 乌什县| 正宁县| 贵港市| 道孚县| 论坛| 翁牛特旗| 黄骅市| 沭阳县| 芮城县| 区。| 鄄城县| 蒙山县| 凤翔县| 黄浦区| 潮州市| 天镇县| 连州市| 万盛区| 特克斯县| 奈曼旗| 兰溪市| 平乡县| 青冈县| 嫩江县| 乳山市| 许昌县| 北碚区|