用C语言编写一完整源程序,从键盘输入一个字符串Str1,在新的一行输入一个待检测字符Char 请c语言大神解惑 编写一程序,实现从键盘输入两个字符串str...
\u5229\u7528\u51fd\u6570\u548c\u6307\u9488\u7f16\u5199\u7a0b\u5e8f\uff0c\u4ece\u952e\u76d8\u8f93\u5165\u4e00\u4e2a\u5b57\u7b26\u4e32\uff0c\u7136\u540e\u8f93\u51fa\u4e00\u4e2a\u65b0\u7684\u5b57\u7b26\u4e32\u3002\u65b0\u4e32\u5728\u539f\u4e32\u4e2d\uff0c\u6bcf\u4e24\u4e2a\u5b57\u7b26\u4e4b\u95f4#include
void mf(char *s,char *t) { while ( *s ) { (*t++)=(*s++); (*t++)=' '; } *t=0; }
void main()
{ char str[256],str1[256];
scanf("%s",str); mf(str,str1);
printf("%s\n",str1);
}
#include #include int repeated(char* str)/*\u68c0\u67e5\u5b57\u7b26\u4e32\u5185\u662f\u5426\u6709\u91cd\u590d\u7684\u5b57\u7b26\uff0c\u6709\u5c31\u8fd4\u56de1\uff0c\u65e0\u5c31\u8fd4\u56de0*/{ int i=0, len=strlen(str)-1;//\u8c03\u7528strlen\u5f97\u5230\u5b57\u7b26\u4e32\u7684\u957f\u5ea6 for(i=0; i0) printf("\u4ea4\u96c6\u4e3a[%s]\n", s3); else printf("\u4ea4\u96c6\u4e3a\u7a7a\n"); return 0;}\u6211\u628a\u6ce8\u91ca\u90fd\u5b8c\u6574\u4e86\uff0c\u5c11\u5e74\u8fd8\u6709\u4e0d\u89e3\u4e4b\u5904\uff0c\u8ffd\u95ee\u4fbf\u662f\uff01
\u5e0c\u671b\u8fd9\u4e9b\u80fd\u7ed9\u4f60\u63d0\u4f9b\u4e00\u70b9\u5e2e\u52a9\uff0c\u4eb2\uff01
#include "stdio.h"
#include "string.h"
void deleteChar(char *a,char c)//从特定字符串中删除特定字符{
int i; char *d=NULL;
if((d=strchr(a,c))!=NULL)//找到这个字符,从后一位向前移位,将其覆盖,达到删除的目的
{
for(i=0;*(d+i)!=0;i++)
*(d+i)=*(d+i+1);
}
}
int main()
{
char Str1[100]={0};
char Char_Check;
int i;
gets(Str1);
scanf("%c",&Char_Check);
for(i=0;i<strlen(Str1);i++)//一次只能删除一个特定字符,循环删除,最多循环字符串最大长度
deleteChar(Str1,Char_Check);
puts(Str1);
}
运行结果:
#include<stdio.h>
int main(){
char str[1000],c;//定义字符串str和字符c
int i=0,j;//定义循环变量
printf("请输入字符串Str1:");
gets(str);//输入字符串str
printf("请输入字符Char_Check:");
scanf("%c",&c);//输入字符c
for(i=0;str[i]!='\0';i++)
if(str[i]==c)//判断字符串str中的字符是否与c相同
for(j=i;str[j]!='\0';j++)
str[j]=str[j+1];//如果相同,字符依次向前移动覆盖(相当于删除)
printf("删除后的字符串为:");
puts(str);
}
运行结果如图:
#include <stdio.h>
void del_str( char *str , char ch)
{
char *tmp,*p;
tmp=p=str ;
while( *tmp )
{
if ( *tmp != ch )
*p++=*tmp ;
tmp++ ;
}
*p=0x00;
}
int main()
{
char Str1[128],Char_Check;
gets( Str1 );
Char_Check=getchar();
del_str(Str1,Char_Check) ;
printf("%s\n" , Str1 );
return 0;
}
#include <stdio.h>
#include <string.h>
#include <assert.h>
int RemoveChar(char *pstr, char ch)
{
int len = strlen(pstr);
assert(pstr != NULL);
while (len-- > 0) {
if (*pstr == ch){
strncpy(pstr, pstr+1, len);
continue;
}
pstr++;
}
*pstr = '\0';
return 1;
}
#define MAXLEN 128
int main(void)
{
char pstr[MAXLEN] = {0};
char ch;
printf("Please enter the string: ");
gets(pstr);
printf("
Please enter the char: ");scanf("%c", &ch);
RemoveChar(pstr, ch);
printf("
After: %s
", pstr);return 0;
}
绛旓細C璇█:缂栧啓涓涓绋嬪簭,浠閿洏杈撳叆10涓鐢熸垚缁,姹傚钩鍧囨垚缁┿1銆佽櫧鐒秏ain鍑芥暟鍙互浣滀负缁撴瀯浣撴垨鑰呯被鐨勬垚鍛樺嚱鏁帮紝浣嗙浉搴斿湴浼氬け鍘讳綔涓虹▼搴忓嚭鍏ュ彛鐨勫姛鑳姐侰++涓叏灞main鍑芥暟鐨勪功鍐欐牸寮忎笌C璇█瀹屽叏鐩稿悓锛屽姛鑳戒篃瀹屽叏鐩稿悓锛屼笖鍚屼竴C++绋嬪簭鍚屾牱鍙兘鏈変竴涓叏灞main鍑芥暟銆2銆佸惊鐜鍙ヤ腑杩涜10涓暟鐨勭疮鍔犲湪sum閲岄潰锛岀劧鍚庡湪...
绛旓細include "stdio.h"#include "string.h"void deleteChar(char *a,char c)//浠庣壒瀹氬瓧绗︿覆涓垹闄ょ壒瀹氬瓧绗 int i; char *d=NULL;if((d=strchr(a,c))!=NULL)//鎵惧埌杩欎釜瀛楃锛屼粠鍚庝竴浣嶅悜鍓嶇Щ浣嶏紝灏嗗叾瑕嗙洊锛岃揪鍒板垹闄ょ殑鐩殑 { for(i=0;*(d+i)!=0;i++)(d+i)=*(d+i+1);} }in...
绛旓細婧愮▼搴濡備笅锛歩nclude <stdio.h> int main(){ int n,i,j,sum=1,t;scanf("%d", &n);for(i=1;i<=n;i++){ t=1;for(j=1;j<=i;j++){ t *= 2; //姣忔璁$畻2 ^ i 鍑烘潵 } sum += t; //sum鍔犱笂绠楀嚭鏉ョ殑2 ^ i } printf("%d\n", sum);return 0;} ...
绛旓細1銆佽櫧鐒秏ain鍑芥暟鍙互浣滀负缁撴瀯浣撴垨鑰呯被鐨勬垚鍛樺嚱鏁帮紝浣嗙浉搴斿湴浼氬け鍘讳綔涓绋嬪簭鍑哄叆鍙g殑鍔熻兘銆侰++涓叏灞main鍑芥暟鐨勪功鍐欐牸寮忎笌C璇█瀹屽叏鐩稿悓锛屽姛鑳戒篃瀹屽叏鐩稿悓锛屼笖鍚屼竴C++绋嬪簭鍚屾牱鍙兘鏈変竴涓叏灞main鍑芥暟銆2銆佸惊鐜鍙ヤ腑杩涜10涓暟鐨勭疮鍔犲湪sum閲岄潰锛岀劧鍚庡湪寰幆璇彞澶栦娇鐢紙average=sum/10锛夋潵璁$畻10涓鐢熺殑骞冲潎鎴愮哗...
绛旓細include<iostream> intmain(){ usingnamespacestd;inta,b;cout<<"Pleaseenterthetwonumber:\n";cin>>a>>b;doublesum=((double)(a+b)/2*(b-a+1));cout<<sum<<endl;return0;}
绛旓細绋嬪簭锛歩nclude<stdio.h> intmain(){ intarr[10]={0};inti=0;intmax=0;intmin=0;printf("璇疯緭鍏10涓暣鏁帮細");for(i=0;i<sizeof(arr)/sizeof(arr[0]);i++){ scanf("%d",&arr[i]);} max=arr[0];for(i=0;i<sizeof(arr)/sizeof(arr[0]);i++){ if(max<arr[i]){ ma...
绛旓細浠ヤ笅鏄浣跨敤C璇█缂栧啓涓涓绋嬪簭锛屼粠閿洏杈撳叆鐞冪殑鍗婂緞锛屽苟璁$畻鐞冪殑闈㈢Н锛屾渶鍚庡湪灞忓箷涓婅緭鍑虹粨鏋滐細```c include <stdio.h> define PI 3.14159 int main(){ float radius;float area;printf("璇疯緭鍏ョ悆鐨勫崐寰勶細");scanf("%f", &radius);area = 4 * PI * radius * radius;printf("鐞冪殑闈㈢Н涓猴細...
绛旓細绋嬪簭濡備笅锛歩nclude <stdio.h> int main(){ char ch;scanf("%c",&ch);printf("%c",ch-'a'+'A');return(0);} 绀轰緥涓锛歩nclude<stdio.h> int main(){ char ch;scanf("%c",&ch);printf("Letter %c converted into a letter %c!",ch,ch-32)锛//澶у啓瀛楁瘝ASCII鐮佹瘮灏忓啓瀛楁瘝灏32 ...
绛旓細婧愮▼搴濡備笅锛歩nclude "pch.h"define _CRT_SECURE_NO_WARNINGS include <iostream> using namespace std;int main(){ int s[2][13] = { 0,31,28,31,30,31,30,31,31,30,31,30,31,0,31,29,31,30,31,30,31,31,30,31,30,31, };int year = 0;int month = 0;int day = 0;...
绛旓細鏈汉涔熸槸瀛C璇█鐨勶紝浠ヤ笅鐨绋嬪簭鏄寜鐓т綘鐨勮姹缂栧啓鐨勶細#include <stdio.h> //姹傝緭鍏ユ暟鍚勪綅鏁扮殑绔嬫柟鍜 void main(){ int x,sum=0,j;printf("璇疯緭鍏ヤ竴涓鏁存暟锛");scanf("%d",&x); //杈撳叆涓涓暟 while(x!=0) //鍒ゆ柇X鏄惁涓洪浂 { j=x%10; //鍙栦釜浣嶆暟瀛 sum+=j*j*...