1.求一个1球从100米掉下,十次以后的长度
#include<stdio.h>
int main()
{
int i;
float sum = 0,n=100;
for (i = 1; i <= 10; i++)
{
sum = sum + n;
n = n / 2;
}
printf("the sum=%f", sum);
printf("the n=%f", n);
getchar();
getchar();
return 0;
}
int main()
{
int i;
float sum = 0,n=100;
for (i = 1; i <= 10; i++)
{
sum = sum + n;
n = n / 2;
}
printf("the sum=%f", sum);
printf("the n=%f", n);
getchar();
getchar();
return 0;
}
2.一猴子吃桃子,每次都吃一半加一个,十天以后只剩一个,求总共多少个
#include<stdio.h>
int main()
{
int i, n=1;
for (i = 1; i < 10; i++)
{
n = 2* (n+ 1);
#include<stdio.h>
int main()
{
int i, n=1;
for (i = 1; i < 10; i++)
{
n = 2* (n+ 1);
}
printf("the whole :%d", n);
getchar();
getchar();
return 0;
}
printf("the whole :%d", n);
getchar();
getchar();
return 0;
}
3.倒三角图形的打印
#include<stdio.h>
int main()
{
int i, j;
for (i = 0; i < 5; i++)
{
for (j = 0; j <= i; j++)
{
printf("*");
}
printf("\n");
}
for (i = 3; i >= 0; i--)
{
for (j = 0; j <= i; j++)
{
printf("*");
}
printf("\n");
}
getchar();
getchar();
return 0;
}
#include<stdio.h>
int main()
{
int i, j;
for (i = 0; i < 5; i++)
{
for (j = 0; j <= i; j++)
{
printf("*");
}
printf("\n");
}
for (i = 3; i >= 0; i--)
{
for (j = 0; j <= i; j++)
{
printf("*");
}
printf("\n");
}
getchar();
getchar();
return 0;
}
4.1到20的阶乘之和
#include<stdio.h>
int main()
{
int i, k=1, sum=0;
for (i = 1; i <=20; i++)
{
k = k * i;
sum = sum + k;
}
printf("sum=%d", sum);
getchar();
getchar();
return 0;
}
#include<stdio.h>
int main()
{
int i, k=1, sum=0;
for (i = 1; i <=20; i++)
{
k = k * i;
sum = sum + k;
}
printf("sum=%d", sum);
getchar();
getchar();
return 0;
}
5.求一个大的字符串中有几个小的字符串
#include<stdio.h>
int main()
{
int i,n=0;
char str[80];
char c = ' ';
printf("the string:\n");
gets_s(str);
for (i = 0; str[i] != '\0'; i++)
{
if (str[i] ==' ')
n++;
}
printf("n=%d", n+1);
getchar();
getchar();
return 0;
}
#include<stdio.h>
int main()
{
int i,n=0;
char str[80];
char c = ' ';
printf("the string:\n");
gets_s(str);
for (i = 0; str[i] != '\0'; i++)
{
if (str[i] ==' ')
n++;
}
printf("n=%d", n+1);
getchar();
getchar();
return 0;
}