一:
5.求自然对数e的近似值
// 223.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
using namespace std;
int main()
{
long double e=1.0;
long double f=1;
for(int i=1;1.0/f>=1e-6;i++);
{
f=f*i;
e=e+1.0/f;
}
cout<<"自然对数 e 的近似值为:"<<e<<endl;
return 0;
}
6.求圆周率的近似值
// 223.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
using namespace std;
int main()
{
long double pi=1.0;
double flag =-1.0;
for(int i=3;1.0/i>=1e-6;i+=2)
{
pi+=flag/i;
flag=-flag;
}
cout<<"圆周率pi的近似值为:"<<4*pi<<endl;
return 0;
}
7,编一程序,,,分类并显示
// 223.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
using namespace std;
int main()
{
int number;
cout<<"请输入一个整数:"<<endl;
cin>>number;
if(number<10)
cout<<number<<"is less than 10.";
else if(number<=99)
cout<<number<<"is 10 to 99.";
else if(number<=999)
cout<<number<<"is 100 to 999.";
else
cout<<number<<"is more than 1000.";
cout<<endl;
return 0;
}
8.编一程序,输出图形
#include <iostream>
using namespace std;
int main()
{
int i,j,k;
for(i=0;i<=3;i++)
{
for(j=0;j<6-2*i;j++)
cout<<" ";
for(k=0;k<2*i+1;k++)
cout<<" *";
cout<<endl;
}
for(i=0;i<=2;i++)
{
for(j=0;j<2+2*i;j++)
cout<<" ";
for(k=0;k<5-2*i;k++)
cout<<" *";
cout<<endl;
}
return 0;
}