#include <stdio.h>
int main()
{
double sum_stranger=0;
double sum_rich_man=0;
double exchange_stranger=0.01;
double exchange_rich_man=100000;
int i;
for(i=1;i<=30;i++)
{
sum_stranger+=exchange_stranger;
sum_rich_man+=exchange_rich_man;
printf("exchange of stranger:%f exchange of richman :100000\n",exchange_stranger);
exchange_stranger*=2;
}
printf("summary exchange of stranger is %f summary exchange of rich man is %f",sum_stranger,sum_rich_man);
return 0;
}
#include <stdio.h>
int main()
{
double price=200;
int salary=40;
int i=1;
while(i<=90&&salary<price)
{
salary+=40;
price*=1.1;
i++;
}
printf("years %d salary %d price %f",i,salary,price);
return 0;
}
#include <stdio.h>
#include <math.h>
int main()
{
//main:calculate Bessel function
double x;
int n;
printf("insert x and n\n");
scanf("%lf %d",&x,&n);
double J0,J1,Jn;
J0=sin(x)/x;
J1=sin(x)/x*x-cos(x)/x;
int i;
for (i=2;i<=n;i++)
{
Jn=J1/x*(2*(i-1)+1)-J0;
J0=J1;
J1=Jn;
}
if(n==0)
{
printf("result is %f\n",J0);
}
else if(n==1)
{
printf("result is %f\n",J1);
}
else
{
printf("result is %f\n",Jn);
}
return 0;
}
<pre class="cpp" name="code">#include <stdio.h>
#include <math.h>
int main()
{
double sn=0,hn=100;
double a=-100;
int i;
for(i=1;i<=19;i++)
{
hn=hn+a;
sn=sn+fabs(a);
if(i%2!=0)
{
a=-a/2.0;
}
else
{
a=-a;
}
}
printf("%f %f",sn,fabs(a));
return 0;
}
#include <stdio.h>
int main( )
{
float sn=100.0,hn=sn/2;
int n;
for (n=2; n<=10 ; n++)
{
sn=sn+hn*2.0 ;
hn=hn/2.0 ;
}
printf("第10次落地时共经过%f米\n",sn);
printf("第10次反弹%f米\n",hn);
return 0;
}
#include <stdio.h>
int main( )
{
int a,n,count=1,Sn=0,Tn=0;
printf("请输入 a 和 n 的值:\n");
scanf("%d %d",&a,&n);
while (count<=n)
{
Tn=Tn*10+a;
Sn=Sn+Tn;
count++;
}
printf("a+aa+aaa+...=%d\n",Sn);
return 0;
}