循环
for(; test;) == while(test)
函数
```c
#include <stdio.h>
double power(int, int);
int main(void){
int num = power(2, 5);//函数返回值可以直接赋值
printf("(((%d\n",num);
return 0;
}
double power(int n, int p)
{
int pow = 1;
int i;
for(i = 1; i <= p; i++)
{
pow *= n;
printf("****%d\n", pow);
//return pow;
}
return pow;
}
字符串读取
```#include <stdio.h>
#define SPACE ' '
double power(int, int);
int main(void)
{
char ch = getchar();
while(ch != '\n'){
if (ch == SPACE){
putchar(ch);
}
else
putchar(ch + 1);
ch = getchar();
}
putchar(ch);
return 0;
}
else与if的匹配
if ( num > 7 )
if ( num < 13 )
printf (" ok “);
else //else与最近的 if 相匹配
printf (” sorry ");
输入:5 10 19
输出:None ok sorry
输入不是y,就会输出try again.
但是 while(getchar() != ‘\n’)
continue;
是为了避免输入多个字符 tft 这样就会输多行try again
#include <stdio.h>
int main(void)
{
while(getchar() != 'y')
{
printf("try aagin\n");
while(getchar() != '\n')
continue;
}
return 0;
}