第一个
#include
#include
double cal(double e)
{
int c=1;
double ret = 0;
double cur = 1;
double t = 1;
while(cur > e)
{
ret += cur;
c ++;
t *= c;
cur = 1.0/c;
}
return ret;
}
int main()
{
int n, i;
double e;
printf("input n:");
scanf("%d", &n);
for(i = 1; i <= n; i ++)
{
e = pow(10, -i);
printf("e=%lg result = %lg\n", e, cal(e));
}
return 0;
}
第二个
#include
int count(char *s, char c)
{
int ret = 0;
int i;
for(i = 0; s[i]; i ++)
if(s[i] == c) ret ++;
return ret;
}
void delete(char *s, char c)
{
int i,j;
for(i = j = 0; s[i]; i ++)
if(s[i] != c) s[j++] = s[i];
s[j] = 0;
}
int main()
{
char str[1024];
char c;
printf("input str:");
gets(str);
printf("input char:");
c = getchar();
printf("count = %d\n", count(str,c));
delete(str,c);
printf("after delete:%s\n", str);
return 0;
}
供参考 望采纳