zoukankan      html  css  js  c++  java
  • C语言成长学习题(十三)

    五十六、编写求字符串长度的程序。

     1 #include <stdio.h>
     2 
     3 void main(void)
     4 {
     5     char a[80];
     6     int i = 0, count = 0;
     7 
     8     gets(a);
     9     while (a[i] != '')
    10     {
    11         count++;
    12         i++;
    13     }
    14     printf("%s = %d
    ", a, count);
    15 }

    五十七、编写字符串复制的程序。

     1 #include <stdio.h>
     2 
     3 void main(void)
     4 {
     5     int i = 0;
     6     char a[50], b[50];
     7 
     8     gets(a);
     9     while (a[i] != '')
    10     {
    11         b[i] = a[i];
    12         i++;
    13     }
    14     b[i] = '';
    15     puts(b);
    16 }

    五十八、编写字符串连接的程序。

     1 #include <stdio.h>
     2 
     3 void main(void)
     4 {
     5     int i = 0, j = 0;
     6     char a[80], b[30];
     7     
     8     gets(a);
     9     gets(b);
    10     while (a[i] != '')
    11         i++;
    12     while (b[j] != '')
    13         a[i++] = b[j++];
    14     a[i] = '';
    15     puts(a);
    16 }

    五十九、编写字符串比较的程序。

     1 #include <stdio.h>
     2 
     3 void main(void)
     4 {
     5     int i = 0;
     6     char a[30], b[30];
     7 
     8     gets(a);
     9     gets(b);
    10     
    11     while (a[i] = b[i] && a[i] !='')
    12         i++;
    13     if (a[i] > b[i])
    14         printf("第一个字符串大于第二个字符串.
    ");
    15     else if (a[i] == b[i])
    16         printf("两个字符串相等.
    ");
    17     else
    18         printf("第一个字符串小于第二个字符串.
    ");
    19 }

    六十、打印杨辉三角形。

     1 #include <stdio.h>
     2 #include <math.h>
     3 
     4 #define N 6
     5 
     6 void main(void)
     7 {
     8     int a[N][N], i, j, k, spaces;
     9     for (i = 0; i < N; i++)
    10         a[i][0] = a[i][i] = 1;
    11     for (i = 2; i < N; i++)
    12         for (j = 1; j < i; j++)
    13             a[i][j] = a[i-1][j-1] + a[i-1][j];
    14     for (i = 0; i < N; i++)
    15     {
    16         spaces = (N-i-1) * 3;
    17         for (k = 0; k < spaces; k++)
    18             printf(" ");
    19         for (j = 0; j <= i; j++)
    20             printf("%6d", a[i][j]);
    21         printf("
    ");
    22     }
    23 }

    结果:

                           1

                    1     2     1

                1     3     3      1

             1     4     6     4     1

         1     5    10    10     5     1

  • 相关阅读:
    android flash air 打包工具
    MyEclipse 7.0快捷键大全
    android mp4 videoView
    位图处理
    myeclise10.0下载
    dropdown.js
    back track
    ANE 跨平台 as3 转 objectc android desktop
    jquery 例子
    android 屏蔽 home 2
  • 原文地址:https://www.cnblogs.com/zero-jh/p/5027392.html
Copyright © 2011-2022 走看看