summaryrefslogtreecommitdiffstats
path: root/mat/euler/16/mnozi.c
blob: f90cdbdfb2ac12b284f1cd068a3b9a43a9b4ddf9 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#pragma once
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int mnozi (unsigned long long int mnozi_s_tem, char * d, long int b) {
	unsigned long long int carry = 0; // carry je pri množenju vedno pozitiven
	unsigned long long int to = 0;
	unsigned long long int za_napisati = 0;
	for (b = b-1; b >= 0; b--) {
		to = d[b] - '0';
		za_napisati = to * mnozi_s_tem;
		za_napisati = za_napisati + carry;
		carry = 0;
		if (za_napisati > 9) {
			za_napisati = za_napisati - 10;
			carry++;
		}
		d[b] = za_napisati + '0';
	}
	return 0;
}
#ifndef DISABLE_LIB_TESTS
int main (int argc, char ** argv) {
	unsigned long long int m = 2;
	char d[] = "0000000000000000000000000000000000000000000000000000456";
	int b = strlen(d);
	mnozi(m, d, b);
	fprintf(stdout, "test: %s\n", d);
	return 0;
}
#endif