重新學習C語言的第五天

一、靜態局部變量的說明
①輸出1到5的階乘值

#include<stdio.h>
int fac(int n)
{
	static int f=1;
	f=f*n;
	return f;
}
int main()
{
	int i;
	for(i=1;i<=5;i++)
	{
		printf("%d!=%d\n",i,fac(i)); 
	}
}

程序結束纔會消失

②有一個字符串,內有若干個字符,要求輸入一個字符,程序便將字符串中該字符刪去。

#include<stdio.h>
 
int main()
 {
     char str[80],ch;
     int i,j;
 
     printf("Input the string:\n");
     gets(str);
     printf("Input the char to be deleted:\n");
     scanf("%c",&ch);
 
     j=0;
     for(i=j=0;str[i]!='\0';i++)
         if(str[i] != ch)
         {
             str[j] = str[i];
             j++;
         }
     str[j]='\0';
 
     printf("The string is changed to:\n");
     printf("%s\n",str);
 }
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章