1 solutions

  • 0
    @ 2024-12-4 19:37:02

    C :

    #include<stdio.h>
    #include<math.h>
    double total(double m,int n)
    {
    	if(n==1)  return m;
    	else return total(m,n-1)+m/pow(2,n-2);
    } 
    int main()
    {
    	int i,j;
    	int n;
    	double m;
    	scanf("%lf%d",&m,&n);
    	double gaodu=m/pow(2,n);
    	double zong=total(m,n);
    	printf("%.2lf %.2lf",gaodu,zong);
     } 
    

    C++ :

    #include<iostream>
    #include<cstdio>
    using namespace std;
    int main()
    {
    	double n,sum;
    	int m;
    	cin>>n>>m;
    	sum=-n;
    	for (int i=1; i<=m; i++)
    	{
    		sum+=2*n;
    		n/=2;
    	}
    	printf("%.2lf %.2lf\n",n,sum);
    	return 0;
    }
    
    • 1

    C语言程序设计教程(第三版)课后习题6.9

    Information

    ID
    2196
    Time
    1000ms
    Memory
    128MiB
    Difficulty
    (None)
    Tags
    # Submissions
    0
    Accepted
    0
    Uploaded By