Problem 8 solution
More...
#include <stdio.h>
#include <stdlib.h>
|
long long int | get_product (FILE *fp, long start_pos, int num_digits) |
| Compute the product of two numbers in a file. More...
|
|
int | main (int argc, char *argv[]) |
| Main function. More...
|
|
◆ get_product()
long long int get_product |
( |
FILE * |
fp, |
|
|
long |
start_pos, |
|
|
int |
num_digits |
|
) |
| |
Compute the product of two numbers in a file.
- Parameters
-
[in] | fp | pointer to file that is already open |
[in] | start_pos | line number of the first numer |
[in] | num_digits | number of digits on the line to multiply |
- Returns
- expected product
19 unsigned char num = 0;
20 long long int prod = 1;
25 for (
int i = 0; i < num_digits; i++,
count++)
33 if (ch < 0x30 || ch > 0x39)
56 fseek(fp, -
count + 1, SEEK_CUR);
int count(int *arr, const int size)
Count func counts the number of prime numbers.
Definition: prime_seive.c:42
◆ main()
int main |
( |
int |
argc, |
|
|
char * |
argv[] |
|
) |
| |
Main function.
66 long long int prod, max_prod = 0;
73 num_digits = atoi(argv[1]);
76 FILE *fp = fopen(
"digits.txt",
"rt");
79 perror(
"Unable to open file");
92 position = ftell(fp) - 1;
96 printf(
"Maximum product: %lld\t Location: %d^th position\n\t", max_prod,
101 for (; num_digits > 0; num_digits--)
105 if (ch < 0x30 || ch > 0x39)
110 printf(
"%c = %lld\n", ch, max_prod);
long long int get_product(FILE *fp, long start_pos, int num_digits)
Compute the product of two numbers in a file.
Definition: sol1.c:16