From bf8737f02a08f0dd9cf9c7754cb6027124450553 Mon Sep 17 00:00:00 2001 From: Diksha0510 <55033692+Diksha0510@users.noreply.github.com> Date: Thu, 2 Apr 2020 23:24:52 +0530 Subject: [PATCH 1/3] Create answer_2.c --- Question 2/Answer/answer_2.c | 79 ++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 Question 2/Answer/answer_2.c diff --git a/Question 2/Answer/answer_2.c b/Question 2/Answer/answer_2.c new file mode 100644 index 0000000..aa41066 --- /dev/null +++ b/Question 2/Answer/answer_2.c @@ -0,0 +1,79 @@ +#include +#include +#include +int main() +{ + char ch[1000]; + FILE *fptr; //pointer to the file + int i,j,n,temp,pos; + float prod=1,max=1; + fptr=fopen("1Kdigits.txt","r"); //stored the digits in a file + if(fptr==NULL) //checking if the file has openend successfully or not + printf("Unable to open file"); + else + { + fgets(ch,1000,fptr); + j=0; + i=0; + while(i<13) + { + n=ch[j]-'0'; + if(n==0) + { + prod=1; + i=0; + } + else + { + prod=prod*n; + i=i+1; + } +j=j+1; + } + pos=j-1; + i=13; + max=prod; + while(j<1000) + { + n=ch[j]-'0'; + if(n==0) + { + if (i>=13&&prod>max) + { + max=prod; + pos=j; + } + prod=1; + i=0; + } + else + { + if(i<13) + { + prod=prod*n; + i=i+1; + } + else + { + if(prod>max) + { + max=prod; + pos=j; + } + temp=ch[j-13]-'0'; + prod=prod/temp; + prod=prod*n; + } + + } + j=j+1; + } + if(prod>max) + { + max=prod; + pos=j; + } +} + printf("The highest product is %f",max); + return 0; +} From a2514cc982be9475b0d0240b5ea48658a90a5a9b Mon Sep 17 00:00:00 2001 From: Diksha0510 <55033692+Diksha0510@users.noreply.github.com> Date: Thu, 2 Apr 2020 23:25:58 +0530 Subject: [PATCH 2/3] Create README.md --- Question 2/Answer/README.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 Question 2/Answer/README.md diff --git a/Question 2/Answer/README.md b/Question 2/Answer/README.md new file mode 100644 index 0000000..c8595d4 --- /dev/null +++ b/Question 2/Answer/README.md @@ -0,0 +1,18 @@ +**Question 1 - Solution** +**Execution Instructions** + + Compiler Details : gcc + Type down the command in the linux terminal answer_2.c -o ob + The above mentioned command will generate an object file which can be run directly on the terminal using ./ob + +**Input & Output** + + Input + A file named "1Kdigits.txt" containing the digits + Output + The highest product is 23514624000.000000 + +**Author** + + Diksha Choudhary + Email: diksha2.choudhary83@gmail.com From 2f4065c2d6f51e0c4b9f3b2bbf2d779cf22afaf8 Mon Sep 17 00:00:00 2001 From: Diksha0510 <55033692+Diksha0510@users.noreply.github.com> Date: Sat, 4 Apr 2020 22:44:25 +0530 Subject: [PATCH 3/3] Update README.md --- Question 2/Answer/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Question 2/Answer/README.md b/Question 2/Answer/README.md index c8595d4..87abb04 100644 --- a/Question 2/Answer/README.md +++ b/Question 2/Answer/README.md @@ -1,4 +1,4 @@ -**Question 1 - Solution** +**Question 2 - Solution** **Execution Instructions** Compiler Details : gcc