字串練習題

2021-07-31 21:54:49 字數 1200 閱讀 4260

1.請編寫乙個c函式,該函式可以實現將乙個整數轉為任意進製的字串輸出

#include

#include

char ch[16] = ;

//函式宣告:將整數轉換為任意進製的字串

charchar *int2sys(int num,int n,int move_bit);

int main()

else

if(n == 8)

else

charchar *result = int2sys(num,n,move_bit);

printf("%d的%d進製為%s\n",num,n,result);

return

0;

} charchar *int2sys(int num,int n,int move_bit)

; while(num != 0)

len = strlen(result);

for(i = 0; i < len / 2; i++)

return

result;

}

2.輸入乙個字串,計算字串中子串出現的次數

[objc] view plain copy print?在code上檢視**片派生到我的**片

#include

#include

#define max_size 1024

int count_child_str(char* p_str,charchar *c_str)

p_str++;

} return count;

} int main()

; char c_str[max_size] = ;

printf("please input parent str:");

scanf("%s",p_str);

printf("\nplease input child str:");

scanf("%s",c_str);

count = count_child_str(p_str,c_str);

printf("count = %d\n",count);

return

0;

}

字串練習題

變數名是否合法 1.變數名只能由字母 數字 下劃線組成 2.只能以字母或下劃線開頭 源 while true s input 變數名 if s exit print 歡迎下次使用 break if s 0 isalpha or s 0 for i in s 1 if not i.isalnum or...

字串練習題

輸入兩個字串,從第乙個字串中刪除第二個字串中所有的字元。例如,輸入 they are students.和 aeiou 則刪除之後的第乙個字串變成 thy r stdnts.s1 input 請輸入第乙個字串 s2 input 請輸入第二個字串 s3 方法一 for i in s1 print i,...

字串練習題

分析以下需求,並用 實現 1 定義如下方法public static string getpropertygetmethodname string property 2 該方法的引數為string型別,表示使用者給定的成員變數的名字,返回值型別為string型別,返回值為成員變數對應的get方法的名...