#include<stdio.h> #include<string.h> #include<stdlib.h> #define N 100 int main(){ char str1[N],str2[N]; double s1,s2; int a,b,flag; FILE *fp,*fp2; fp=fopen("1.in","r"); fp2=fopen("1.out","w"); fscanf(fp,"%s",str1); fscanf(fp,"%s",str2); if(strchr(str1,'.')||strchr(str2,'.')){//重點函數,次函數查詢是否包含一個字符並且返回該字符的指針 s1=atof(str1); s2=atof(str2);//注atof函數可以把科學計數法也轉化成浮點數,功能是如此的強大。。。。 flag=1; }else{ a=atoi(str1); b=atoi(str2); flag=0; } int count=0; if(flag){ s1+=s2; while(s1>=1){ s1/=10; count++; } count--; s1*=10; fprintf(fp2,"%fe%d",s1,count); } else fprintf(fp2,"%d",a+b); return 0; }