用c语言编写程序,输入任意一串字符,再输入一个字符和一个位置,将此字符插入到此串字符的这个位置上。 C语言编写一个程序输入两个字符串1和字符串2(两个字符串长度...
\u7528c\u8bed\u8a00\u7f16\u5199\u7a0b\u5e8f\uff1a\u8f93\u5165\u4efb\u610f\u4e00\u4e32\u5b57\u7b26\uff0c\u5b57\u7b26\u82e5\u8fde\u7eed\u51fa\u73b0\u591a\u6b21\uff0c\u5219\u53ea\u4fdd\u7559\u4e00\u4e2a\u5b57\u7b26\u5220\u9664\u591a\u4f59\u7684\u5b57\u7b26#include#includevoid main(){char a[100],b[100];int j=0,n,len,flag,s=0;printf("\u8bf7\u8f93\u5165\u4e00\u4e2a\u5b57\u7b26\u4e32\uff1a\n");scanf("%s",a);printf("\u5220\u9664\u524d\u7684\u5b57\u7b26\u4e32\uff1a\n");printf("%s\n",a);n=strlen(a); // \u83b7\u53d6\u8f93\u5165\u5b57\u7b26\u4e32\u7684\u957f\u5ea6b[0] = a[0]; // \u5c06 a \u5b57\u7b26\u4e32\u7684\u7b2c\u4e00\u4e2a\u503c\u7ed9 b \u5b57\u7b26\u4e32len = 1; // \u521d\u59cb\u5316 b \u5b57\u7b26\u4e32\u7684\u957f\u5ea6for(int i=1;i<n;i++) {flag = 0; // \u6dfb\u52a0\u6807\u8bc6\uff08\u4e3a0\u5219\u8868\u793a\u503c\u4e0d\u540c\uff0c\u4e3a1\u5219\u8868\u793a\u503c\u76f8\u540c\uff09for(int j=0;j<len;j++) {if(a[i] == b[j]) // \u5f53\u524d a \u5b57\u7b26\u4e32\u4e2d\u4e0e b \u5b57\u7b26\u4e32\u4e2d\u76f8\u540c\u65f6\u8df3\u51fa\u5faa\u73af\u5e76\u4e14 flag \u8bbe\u7f6e\u4e3a 1{flag = 1;s++; // \u8ba1\u7b97\u51fa\u76f8\u540c\u7684\u503c\u7684\u6570\u91cfbreak;}}if (!flag) // \u5f53\u524d a[i] \u5b57\u7b26\u4e32\u4e2d\u4e0e b \u5b57\u7b26\u4e32\u65e0\u76f8\u7b49\u65f6\uff0c\u5c06\u5176\u52a0\u5165\u5230 b \u5b57\u7b26\u4e32\u4e2d{b[len++] = a[i];}}b[len]='\0'; // \u7ed9 b \u5b57\u7b26\u4e32\u6dfb\u52a0\u7ed3\u675f\u7b26printf("\n\u5220\u9664\u540e\u7684\u5b57\u7b26\u4e32\uff1a");printf("%s\n",b);printf("\u88ab\u5220\u9664\u7684\u4e2a\u6570\u6709%d\n",s);}\u770b\u5230\u4e0b\u9762\u8bc4\u8bba\u6709\u5144\u5f1f\u8bf4\uff0c\u4e4b\u524d\u7684\u9519\u8bef\uff0c\u4eca\u5929\u4e00\u770b\u786e\u5b9e\u662f\u6709\u95ee\u9898\uff0c\u4e4b\u524d\u6ca1\u6709\u8003\u8651\u5468\u5230\uff0c\u53ea\u662f\u5220\u9664\u4e86\u524d\u540e\u91cd\u590d\u7684\u5e76\u6ca1\u6709\u5230\u8fbe\u9898\u76ee\u7684\u8981\u6c42\uff0c\u73b0\u5982\u4eca\u66f4\u65b0\u6700\u65b0\u7684\u4ee3\u7801\u5e76\u6dfb\u52a0\u4e86\u5907\u6ce8\u3002\u9644\u4e0a\u4e00\u5f20\u622a\u56fe
\u3000\u8bf4\u767d\u4e86\u5c31\u662fstrcat
char *strcat(char *strDest, const char *strSrc) //\u5c06\u6e90\u5b57\u7b26\u4e32\u52a0const\uff0c\u8868\u660e\u5176\u4e3a\u8f93\u5165\u53c2\u6570
\u3000\u3000{
\u3000\u3000char *address = strDest; //\u8be5\u8bed\u53e5\u82e5\u653e\u5728assert\u4e4b\u540e\uff0c\u7f16\u8bd1\u51fa\u9519
\u3000\u3000assert((strDest != NULL) && (strSrc != NULL)); //\u5bf9\u6e90\u5730\u5740\u548c\u76ee\u7684\u5730\u5740\u52a0\u975e0\u65ad\u8a00
\u3000\u3000while(*strDest) //\u662fwhile(*strDest!=\u2019\0\u2019)\u7684\u7b80\u5316\u5f62\u5f0f
\u3000\u3000{ //\u82e5\u4f7f\u7528while(*strDest++)\uff0c\u5219\u4f1a\u51fa\u9519\uff0c\u56e0\u4e3a\u5faa\u73af\u7ed3\u675f\u540estrDest\u8fd8\u4f1a\u6267\u884c\u4e00\u6b21++,\u90a3\u4e48strDest
\u3000\u3000strDest++; //\u5c06\u6307\u5411'\0'\u7684\u4e0b\u4e00\u4e2a\u4f4d\u7f6e\u3002/\u6240\u4ee5\u8981\u5728\u5faa\u73af\u4f53\u5185++\uff1b\u56e0\u4e3a\u8981\u662f*strDest\u6700\u540e\u6307
\u3000\u3000} //\u5411\u8be5\u5b57\u7b26\u4e32\u7684\u7ed3\u675f\u6807\u5fd7\u2019\0\u2019\u3002
\u3000\u3000while(*strDest++ = *strSrc++)
\u3000\u3000{\u3000\u3000
*p++\u7b49\u4ef7\u4e8e*(p++)\u3002\u81f3\u4e8e\u4e3a\u4ec0\u4e48\u4f1a\u7b49\u4ef7\u5462\uff1f\u6839\u636ec\u8bed\u8a00\u7684\u4f18\u5148\u7ea7\u3002*\u4e0e++\u7684\u4f18\u5148\u7ea7\u540c\u5904\u5728\u7b2c\u4e8c\u7ea7\u522b\u4e0a\u3002\u4ed6\u4eec\u7684\u4f18\u5148\u7ea7\u662f\u4e00\u6837\u7684\uff0c\u53c8\u56e0\u4e3a\u5904\u5728\u7b2c\u4e8c\u7ea7\u522b\u7684\u4f18\u5148\u7ea7\u8fd0\u7b97\u7b26\u662f\u7ed3\u5408\u65b9\u5411\u662f\u4ece\u53f3\u5230\u5de6\uff0c\u6240\u4ee5\u5f53\u51fa\u73b0*p++\u8fd9\u6837\u7684\u8868\u8fbe\u5f0f\u7684\u65f6\u5019\uff0c\u6839\u636e\u4f18\u5148\u7ea7\u522b\u76f8\u540c\uff0c\u5e76\u4e14\u7ed3\u5408\u65b9\u5411\u662f\u4ece\u53f3\u5230\u5de6\uff0c\u6240\u4ee5\u5c31\u7b49\u4ef7\u4e8e*(p++)\u4e86\u3002\u90a3\u4e48\u4e5f\u5c31\u662f\uff0c\u5148\u5c06p\u6307\u9488\u79fb\u52a8\u5230\u4e0b\u4e2ap\u6307\u9488\u6240\u6307\u5411\u5143\u7d20\u7684\u5730\u5740\u7684\u4e0b\u4e00\u4e2a\u5730\u5740\uff0c\u7136\u540e\u518d\u5bf9\u90a3\u4e2a\u5730\u5740\u53d6\u503c\u3002\uff08*p)++\u662f\u53d6p\u6240\u6307\u5411\u5730\u5740\u7684\u503c\uff0c\u7136\u540e\u518d\u5c06\u8fd9\u4e2a\u503c+1
\u3000\u3000NULL; //\u8be5\u5faa\u73af\u6761\u4ef6\u5185\u53ef\u4ee5\u7528++\uff0c
\u3000\u3000} //\u6b64\u5904\u53ef\u4ee5\u52a0\u8bed\u53e5*strDest=\u2019\0\u2019;\u65e0\u5fc5\u8981
#include<stdio.h>
#include<string.h>
void main()
{
char ch[40],ch2[20],ch3[20],i,j,temp,x;
printf("请输入第一串字符:");
gets(ch);
printf("请输入第二串字符:");
gets(ch2);
printf("请输入插入的位置:");
scanf("%d",&i);
temp = i;
for(j=0;ch[temp] != '\0';j++,temp++)
ch3[j] = ch[temp];
ch3[j]='\0';
for(j=0;j<strlen(ch);j++,i++)
ch[i] = ch2[j];
strcat(ch,ch3);
ch[i] = '\0';
puts(ch);
}
#include<stdio.h>
#include "string.h"
void main()
{
int i,j;
char ch,s[100];
printf("输入一字符串:");
gets(s);
printf("输入一个字符:");
scanf("%c",&ch);
printf("输入位置:");
scanf("%d",&i);
if(i>strlen(s))
{
printf("位置过大\n");
return;
}
for(j=strlen(s)+1;j>i;j--)
s[j]=s[j-1];
s[i]=ch;
puts(s);}
绛旓細include<stdio.h>#include<string.h>int main(){ int len, i; char s[1000]; while(scanf("%s", s) != EOF) { len = strlen(s); while(len--) { printf("%c",s[len]); } printf("\n"); } return 0;} 鏈涢噰绾 ...
绛旓細鎻掑叆鎺掑簭娉曪細include <stdio.h> void print(int* a, int n){ for(int i=0; i<n; i++){ printf("%d ",a[i]);} printf("\n");} void sort(int* a, int n){ for(int i=1; i<n; i++){ int t= a[i];//瑕佹彃鍏ョ殑鏁版嵁 int j;//瑕佹彃鍏ョ殑浣嶇疆 for(j=i; j>0 && ...
绛旓細杈撳叆浠绘剰闀垮害瀛楃涓诧紝骞惰緭鍑烘墦鍗板瓧绗︿覆鍙婂叾闀垮害銆俰nclude<stdio.h>#include<malloc.h>#include<conio.h>char *input();//杈撳叆浠绘剰闀垮害瀛楃涓诧紙鍙寘鍚┖鏍硷級锛屽洖杞︾‘璁わ紝杩斿洖杈撳叆鐨勫瓧绗︿覆int getLen(char *str);//閫氳繃鎸囬拡鑾峰彇瀛楃涓查暱搴oid meError(void *p);//鍐呭瓨鐢宠澶辫触int main(){ char ...
绛旓細include <stdio.h>#include <string.h>char* DelCharFromString(char *str, int len, int pos);void main(){char str[100]; int pos; //鍒犻櫎浣嶇疆int len; //瀛楃涓查暱搴rintf("璇杈撳叆涓涓瓧绗︿覆锛歕n");scanf("%s", str);len = strlen(str);printf("璇疯緭鍏ヨ鍒犻櫎瀛楃鐨勪綅缃細(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*...
绛旓細杩欐牱锛燂紵锛焛nclude <stdio.h> void main (){ char s[80],c;int i=0;while((c=getchar())!='\n')s[i++]=c;s[i]='\0';puts(s);}
绛旓細include<stdio.h>#include<ctype.h>int main(){int a,b,c,d; char ch; a=b=c=d=0; scanf("%c",&ch); while(ch!='\n') {if(isalpha(ch))a++; else if(isdigit(ch))b++; else if(ch==' ')c++; else d++; if(isupper(ch))ch+=32; else if(islower(ch...
绛旓細绋嬪簭濡備笅锛歩nclude<stdio.h> void main(){ int a,b;char oper;scanf("%d%c%d",&a,&oper,&b);switch(oper){ case '+':printf("%d+%d=%d\n",a,b,a+b);break;case '-':printf("%d-%d=%d\n",a,b,a-b);break;case '*':printf("%d*%d=%d\n",a,b,a*b);break;case '...
绛旓細浣犲ソ锛佷互涓嬫槸涓涓C璇█绋嬪簭锛屼娇鐢do-while寰幆璇彞浠庨敭鐩浠绘剰杈撳叆n涓疄鏁帮紝骞惰绠楀嚭鍏朵腑鐨勬渶澶у煎拰鏈灏忓硷細include <stdio.h> int main() { int n, i = 0;float num, max, min;printf("璇疯緭鍏ヨ杈撳叆鐨勫疄鏁颁釜鏁皀: ");scanf("%d", &n);do { printf("璇疯緭鍏ュ疄鏁: ");scanf("%f", ...
绛旓細1銆侀鍏堟槸榧犳爣閫夋嫨鍗曞嚮C璇█缂栫▼杞欢鍒涘缓涓涓┖鐨凜璇█鏂囦欢銆2銆佸畾涔夊洓涓暣鏁板彉閲廰锛宐锛宑锛宮ax銆備笁涓彉閲廰锛宐鍜宑鐢ㄤ簬瀛樺偍杈撳叆鐨勪笁涓暟瀛楋紝max鐢ㄤ簬瀛樺偍涓変釜鏁板瓧鐨勬渶澶у笺3銆佷娇鐢╯canf璇彞浠庨敭鐩樿緭鍏ヤ笁涓暟瀛椼傚湪娉ㄦ剰涔嬪墠涓嶈蹇樿浣跨敤鍙橀噺銆4銆佷娇鐢╩ax鍙互閫愪釜姣旇緝涓変釜鏁板瓧锛屽苟灏嗘渶澶ф暟閲忓瓨鍌ㄥ湪鏈澶...