练习用五种不同的循环方式打印出一个字符串

#include<stdio.h>
int recursion(char *p)//递归方式打印出一个字符串
{
if (*p == '\0') { printf("\n"); return 0; }
else { printf("%c", *p); return  recursion(p + 1); }
}
void Wh(char *p)//while循环方式打印出一个字符串
{
while (*p!='\0')
 printf("%c",*p++);
putchar('\n');
}
void Dwh(char *p)//do while循环方式打印出一个字符串
{
do { printf("%c", *p++); }
while (*p!='\0');
}
void For(char *p)//for 循环方式打印一个字符串
{
for (; *p != '\0'; p++)
printf("%c",*p);
}
void Goto(char *p)
{
LOOP: printf("%c", *p++);
if (*p != '\0')goto LOOP;


}
int main()
{
char str[] = "tasklist";
//recursion(str);  //用递归方式打印 tasklist
//Wh(str);         //用while循环 方式打印 tasklist
//Dwh(str);        //用do while循环方式打印 tasklist  
//For(str);        // 用for循环打印 tasklist
Goto(str);         //用goto if方式打印出 tasklist
system("pause");
return 0;
}

你可能感兴趣的:(c,递归,C语言,recursion,五种循环)