c primer plus 第七章

来源:互联网 发布:611zy资源网备用域名 编辑:程序博客网 时间:2024/04/30 07:06
  4.利用if else语句编写程序读取输入,直到#。用一个感叹号代替每个句号,将原有的每个感叹号用两个感叹号代替,最后报告进行了多少次替代。
#include <stdio.h>int main(void){char ch;int count1= 0,count2= 0;printf("Please type your words\n");while((ch=getchar())!= '#'){if(ch== '.'){putchar('!');  count1++;}else if(ch== '!'){putchar('!');putchar('!');  count2++;}elseputchar(ch);}printf("In total %d times replacement\n",count1+count2);}

 5.用switch重做练习3。