Question # 99
Comparing two numbers written in index form like 211 and 37
is not difficult, as any calculator would confirm that 211 = 2048 37 = 2187.However, confirming that 632382518061 519432525806 would be much more difficult, as both numbers contain over three million digits.
Using base_exp.txt (right click and 'Save Link/Target As...'), a 22K text file containing one thousand lines with a base/exponent pair on each line, determine which line number has the greatest numerical value.
NOTE: The first two lines in the file represent the numbers in
the example given above.
Solution
# 99
/***************************************************************************************/
#include<stdio.h>
#include<conio.h>
#include<math.h>
int main()
{
long
n1,n2;
char
c;
double
tmp,max=0;
int
counter=0,countermax=0;
FILE*fp;
clrscr();
if(fp=fopen("d:/a.txt","r"))
{
while(!feof(fp))
{
counter++;
fscanf(fp,"%ld",&n1);
fscanf(fp,"
%c",&c);
fscanf(fp,"%ld",&n2);
tmp=(double)n2*log(n1);
if(tmp>max)
{
countermax=counter;
max=tmp;
}
}
printf("tmp
= %lf countermax =
%d",max,countermax);
fclose(fp);
}
else
printf("there
was an error in opening the file");
getch();
return
0;
}
/***************************************************************************************/
No comments:
Post a Comment