View difference between Paste ID: z2JmBsed and iqbaqMum
SHOW: | | - or go back to the newest paste.
1-
char toromai(int a) /* Arab számot alakít római számmá */
1+
void main(void)
2
{
3
	//srand(time(NULL));
4
	int a=1234;
5
	char *romai;
6
	romai=toromai(a);
7
	printf("%s\n",romai);
8
	free(romai);
9
}
10
11
char *toromai(int a) /* Arab számot alakít római számmá */
12
{
13
	int tmp,n=0;
14
	char *romai;
15
	char *error = "#ÉRTÉK!";
16
	char egyesek[][10]  = {"I","II","III","IV","V","VI","VII","VIII","IX"};
17
	char tizesek[][10]  = {"X","XX","XXX","XL","L","LX","LXX","LXXX","XC"};
18
	char szazasok[][10] = {"C","CC","CCC","CD","D","DC","DCC","DCCC","CM"};
19-
	if(1<=a<4000)
19+
20
21-
		romai[n]='\0';
21+
22
	while(tmp>0)
23
	{
24
		tmp/=10;
25-
			a%=1000;
25+
26-
			n--;
26+
27
28
	romai=(char*)malloc(n*sizeof(char));
29
	romai[0]=0;
30
	if(1<=a && a<4000)
31-
			a%=100;
31+
32-
			n--;
32+
33
		{
34
			strcat(romai,ezresek[(a/1000)-1]);
35
			if(a%1000!=0)
36
			{
37-
			a%=10;
37+
				a%=1000;
38-
			n--;
38+
				if(9<a%1000 && a%1000<100) n--;
39
				if(1<=a%1000 && a%1000<10) n-=2;
40-
		else strcat(romai,egyesek[a-1]);
40+
				n--;
41
			}
42-
		free (romai);
42+
			else *romai;
43-
		return *romai;
43+
44
		if(n==3)
45-
	else return *error;
45+
46
			strcat(romai,szazasok[(a/100)-1]);
47
			if(a%100!=0)
48
			{
49
				a%=100;
50
				if(1<=a%100 && a%100<10) n--;
51
				n--;
52
			}
53
			else *romai;
54
		}
55
		if(n==2)
56
		{
57
			strcat(romai,tizesek[(a/10)-1]);
58
			if(a%10!=0)
59
			{
60
				a%=10;
61
				n--;
62
			}
63
			else *romai;
64
		}
65
		if(n==1) strcat(romai,egyesek[a-1]);
66
		
67
		return romai;
68
	}
69
	else return error;
70
}