ASCII的转换
n[i]是个字符比如'5',字符也是ASCII码数,'5'-'0'就是5了哈,就变成数字了
#include<iostream>
#include<sstream>
using namespace std;
int main()
{
string str1,str2;
char *p1,*p2;
int min;
cout<<"请输入两个字符串:";
cin>>str1>>str2;
p1=&str1[0];
p2=&str2[0];
if(str1.size()<str2.size()) ///求出str1、str2中长度最短的长度值min
min=str1.size();
else
min=str2.size();
for(int i=0;i<min;++i)
{
if(*(p1+i)-*(p2+i)!=0)
break;
}
if(i==min-1&&min!=1)
{
if(str1.size()==str1.size())
cout<<"0"<<endl;
else /////判断例如abcd与abc比较的情况
if(str1.size()<str2.size())
cout<<-1*int(*(p2+min+1));
else
cout<<int(*(p1+min+1));
}
else
{
cout<<*(p1+i)-*(p2+i)<<endl;
}
return 1;
}
//-----------------------\
#include<iostream>
#include<cmath>
#include<iomanip>
using namespace std;
void sin(double *a,double *b);
void cos(double *a,double *b);
void exp(double *a,double *b);
//=======================================================
int main()
{
double a,b;
int temp;
cout<<"请输入要求定积分的范围a~b:";
cin>>a>>b;
cout<<"请输入要积分的函数类型(1为sin型,2为cos型,3为exp型):";
cin>>temp;
switch (temp) {
case 1:sin(&a,&b); break;
case 2:cos(&a,&b); break;
case 3:exp(&a,&b); break;
}
return 1;
} //===============================================================
void sin(double *a,double *b)
{
double s=0,h;
for(double i=*a;i<*b;i=i+0.01)
{
h=sin(i);
s=s+h*0.01;
}
cout<<"a~b范围内sin(x)的定积分为:"<<setprecision(3)<<s<<endl;
} //===============================================================
void cos(double *a,double *b)
{
double s=0,h;
for(double i=*a;i<*b;i=i+0.01)
{
h=cos(i);
s=s+h*0.01;
}
cout<<"a~b范围内cos(x)的定积分为:"<<setprecision(3)<<s<<endl;
} //================================================================
void exp(double *a,double *b)
{
double s=0,h;
for(double i=*a;i<*b;i=i+0.01)
{
h=exp(i);
s=s+h*0.01;
}
cout<<"a~b范围内exp(x)的定积分为:"<<setprecision(3)<<s<<endl;
} //=================================================================