在指定位置插入字符或字符串
#include<stdio.h>
#include<string.h>
int main()
{
int i,j,n,l;
char a[20]="abnhsdkh";
char b[20]="ssdfhvgdha",c[5]="abc",d,t;
l=sizeof(a)/sizeof(a[0]);
scanf("%c %d",&d,&n); //输入插入的字符和位置
printf("%s\t%s\t%s\n",a,b,c);
for(i = 0; i < l; i++)
{
if(i == n-1) //插入字符
{
t=a[i];
a[i]=d;
}
else
if(i >= n) //后移
{
d = a[i];
a[i] = t;
t = d;
}
}
printf("%s\t",a);
i=0;
for(j = 0; j < l + 3; j++) //向b中插入字符串
{
if(j >= n-1 && i < 3)
{
t = b[j];
b[j] = c[i];
c[i] = t;
i++;
if(i ==3)
i = 0;
}
}
printf("%s\n",b);
return 0;
}
通过编程实现,统计1~n有多少个9 提示:n通过参数传入
#include<stdio.h>
int jiu(int a)
{
int l=0,k=9,t;
while( k <= a)
{
t=k;
while(t > 0)
{
if(t%10 == 9)
l++;
t = t/10;
}
k++;
}
return l;
}
int main()
{
int n,m=0;
scanf("%d", &n);
m=jiu(n);
printf("%d\n", m);
return 0;
}
准备看一看结构体和链表,然后写通讯录。