1 /* ---------- */
2 /* najimath.c */
3 /* ---------- */
4 
5 /* naji math functions and macros */
6 /* (it's maths for people in the uk) */
7 
8 /* this  .c  file is a part */
9 /* of libnaji version 0.6.4 */
10 
11 /* libnaji is based on   */
12 /* the original najitool */
13 
14 /* both najitool and libnaji */
15 /* are public domain and are */
16 /* made by the same author   */
17 /* please read license.txt   */
18 
19 /* made by NECDET COKYAZICI  */
20 
21 #include "libnaji.h"
22 
23 /* todo, make a function that says, first, second, third, fourth,
24 fith, sixth, seventh, eighth, ninth, tenth
25 and also a more complicated one that says 343rd for example
26 and a function that says it full, like three hundred and fourty
27 third, and also a another function that says an integer, or floating
28 point in normal english and turkish
29 
30 very useful for redirecting to text to speech programs
31 i've used some modern text to speech programs that sound
32 like they are real human.
33 */
34 
35 
rand_init(void)36 void rand_init(void) { srand(time(NULL)); }
37 
ul_rand_range(ulong start,ulong end)38 ulong ul_rand_range (ulong start, ulong end)
39 { return ( ( (rand() % (end) ) + (start) ) ); }
40 
sl_rand_range(slong start,slong end)41 slong sl_rand_range(slong start, slong end)
42 { return ( ( (rand() % (end) ) + (start) ) ); }
43 
ui_rand_range(uint start,uint end)44 uint ui_rand_range(uint start, uint end)
45 { return ( ( (rand() % (end) ) + (start) ) ); }
46 
si_rand_range(sint start,sint end)47 sint si_rand_range(sint start, sint end)
48 { return ( ( (rand() % (end) ) + (start) ) ); }
49 
uc_rand_range(uchar start,uchar end)50 uchar uc_rand_range(uchar start, uchar end)
51 { return ( ( (rand() % (end) ) + (start) ) ); }
52 
sc_rand_range(schar start,schar end)53 schar sc_rand_range(schar start, schar end)
54 { return ( ( (rand() % (end) ) + (start) ) ); }
55 
56 
57 /* i couldnt remember what these were called so i made up my own term */
naji_addim(unsigned long start,unsigned long end,unsigned long addby)58 void naji_addim(unsigned long start, unsigned long end, unsigned long addby)
59 {
60 int i;
61 
62 for (i=start; i<=end; i+=addby)
63 printf("% 4i", i);
64 
65 printf("\n");
66 }
67 /*
68 void naji_hexaddim(unsigned long start, unsigned long end, unsigned long addby)
69 {
70 int i;
71 
72 for (i=start; i<=end; i+=addby)
73 printf("% 4X", i);
74 
75 printf("\n");
76 }
77 */
addim(int max_times)78 void addim(int max_times)
79 {
80 int i;
81 
82 for (i=1; i<=max_times; i++)
83 naji_addim(i, (max_times * i), i);
84 }
85 /*
86 void hexaddim()
87 {
88 int i;
89 int max_times=30;
90 
91 for (i=1; i<=max_times; i++)
92 naji_hexaddim(i, (max_times * i), i);
93 }
94 */
95 
96 
97 /*
98 Give it a start and end range, and it returns you the total of all the
99 numbers from start to end added up, for example, if you give a range
100 1 to 100, the total of all the numbers from 1 to 100 added up is 5050.
101 */
102 
rngtotal(int start,int end)103 int rngtotal(int start, int end)
104 {
105 int a=0;
106 int b=0;
107 
108  for (a=start; a<=end; a++)
109  b+=a;
110 
111 return b;
112 }
113 
114 
115 
rngtotal_test()116 void rngtotal_test()
117 {
118 
119  printf("\n\n%i\n\n", rngtotal(1, 100));
120 
121 }
122 
123 
naji_calc(void)124 void naji_calc(void)
125 {
126 double a;
127 double b;
128 double result;
129 char *end;
130 
131 char buffer[100];
132 
133 int oper;
134 
135 
136 safegets(buffer, 80);
137 a = strtod(buffer, &end);
138 
139     loop
140     {
141 
142         printf("\n+ - * /\n");
143         safegets(buffer, 80);
144 
145         if (!strcmp(buffer, "+"))
146         {
147         oper = '+';
148         endloop;
149         }
150 
151         else if (!strcmp(buffer, "-"))
152         {
153         oper = '-';
154         endloop;
155         }
156 
157         else if (!strcmp(buffer, "*"))
158         {
159         oper = '*';
160         endloop;
161         }
162 
163         else if (!strcmp(buffer, "/"))
164         {
165         oper = '/';
166         endloop;
167         }
168 
169 
170     }
171 
172 
173 safegets(buffer, 80);
174 b = strtod(buffer, &end);
175 
176 
177     if (oper == '+')
178     result = (a + b);
179 
180     else if (oper == '-')
181     result = (a - b);
182 
183     else if (oper == '*')
184     result = (a * b);
185 
186     else if (oper == '/')
187     result = (a / b);
188 
189 
190 printf("\n%f\n", result);
191 
192 return;
193 }
194 
195 
196 
engnum(void)197 void engnum(void)
198 {
199 char *units[10] = {
200 "zero",
201 "one",
202 "two",
203 "three",
204 "four",
205 "five",
206 "six",
207 "seven",
208 "eight",
209 "nine",
210 };
211 
212 char *teens[10] = {
213 "ten",
214 "eleven",
215 "twelve",
216 "thirteen",
217 "fourteen",
218 "fifteen",
219 "sixteen",
220 "seventeen",
221 "eighteen",
222 "nineteen",
223 };
224 
225 char *tens[8] = {
226 "twenty",
227 "thirty",
228 "fourty",
229 "fifty",
230 "sixty",
231 "seventy",
232 "eighty",
233 "ninety"
234 };
235 
236 
237 int i=0;
238 int tens_pos=0;
239 int hundreds_pos=0;
240 int thousands_pos=0;
241 
242 /***/
243   for (i=1; i<10; i++)
244   printf("%s\n", units[i]);
245 
246   for (i=0; i<10; i++)
247   printf("%s\n", teens[i]);
248 
249   for (tens_pos=0; tens_pos<8; tens_pos++)
250   {
251 
252     printf("%s\n", tens[tens_pos]);
253 
254     for (i=1; i<10; i++)
255     printf("%s %s\n", tens[tens_pos], units[i]);
256   }
257 /***/
258 
259 
260 /***/
261 
262 
263   for (hundreds_pos=1; hundreds_pos<10; hundreds_pos++)
264   {
265 
266 
267   printf("%s hundred\n", units[hundreds_pos]);
268 
269 
270   for (i=1; i<10; i++)
271   printf("%s hundred and %s\n", units[hundreds_pos], units[i]);
272 
273   for (i=0; i<10; i++)
274   printf("%s hundred and %s\n", units[hundreds_pos], teens[i]);
275 
276   for (tens_pos=0; tens_pos<8; tens_pos++)
277   {
278 
279     printf("%s hundred and %s\n", units[hundreds_pos], tens[tens_pos]);
280 
281     for (i=1; i<10; i++)
282     printf("%s hundred and %s %s\n",
283     units[hundreds_pos], tens[tens_pos], units[i]);
284   }
285 
286 
287  }
288 
289 /***/
290 
291 
292 
293 
294 
295 
296 
297 /***/
298 
299   for (thousands_pos=1; thousands_pos<10; thousands_pos++)
300   {
301 
302   printf("%s thousand\n", units[thousands_pos]);
303 
304   for (i=1; i<10; i++)
305   printf("%s thousand and %s\n", units[thousands_pos], units[i]);
306 
307   for (i=0; i<10; i++)
308   printf("%s thousand and %s\n", units[thousands_pos], teens[i]);
309 
310   for (tens_pos=0; tens_pos<8; tens_pos++)
311   {
312 
313     printf("%s thousand and %s\n", units[thousands_pos], tens[tens_pos]);
314 
315     for (i=1; i<10; i++)
316     printf("%s thousand and %s %s\n",
317     units[thousands_pos], tens[tens_pos], units[i]);
318   }
319 
320 
321 
322   for (hundreds_pos=1; hundreds_pos<10; hundreds_pos++)
323   {
324 
325 
326   printf("%s thousand %s hundred\n",
327   units[thousands_pos], units[hundreds_pos]);
328 
329 
330   for (i=1; i<10; i++)
331   printf("%s thousand %s hundred and %s\n",
332   units[thousands_pos], units[hundreds_pos], units[i]);
333 
334   for (i=0; i<10; i++)
335   printf("%s thousand %s hundred and %s\n",
336   units[thousands_pos], units[hundreds_pos], teens[i]);
337 
338   for (tens_pos=0; tens_pos<8; tens_pos++)
339   {
340 
341     printf("%s thousand %s hundred and %s\n",
342     units[thousands_pos], units[hundreds_pos], tens[tens_pos]);
343 
344     for (i=1; i<10; i++)
345     printf("%s thousand %s hundred and %s %s\n",
346     units[thousands_pos], units[hundreds_pos], tens[tens_pos], units[i]);
347   }
348 
349 
350 
351 
352 
353  }
354 
355 
356 
357 }
358 
359 
360 /***/
361 
362 
363 
364 
365 }
366 
367 
368 
369 
turnum(void)370 void turnum(void)
371 {
372 char *units[10] = {
373 "sifir",
374 "bir",
375 "iki",
376 "uc",
377 "dort",
378 "bes",
379 "alti",
380 "yedi",
381 "sekiz",
382 "dokuz",
383 };
384 
385 char *teens[10] = {
386 "on",
387 "on bir",
388 "on iki",
389 "on uc",
390 "on dort",
391 "on bes",
392 "on alti",
393 "on yedi",
394 "on sekiz",
395 "on dokuz",
396 };
397 
398 char *tens[8] = {
399 "yirmi",
400 "otuz",
401 "kirk",
402 "eli",
403 "altmis",
404 "yetmis",
405 "seksen",
406 "doksan"
407 };
408 
409 
410 int i=0;
411 int tens_pos=0;
412 int hundreds_pos=0;
413 int thousands_pos=0;
414 
415 /***/
416   for (i=1; i<10; i++)
417   printf("%s\n", units[i]);
418 
419   for (i=0; i<10; i++)
420   printf("%s\n", teens[i]);
421 
422   for (tens_pos=0; tens_pos<8; tens_pos++)
423   {
424 
425     printf("%s\n", tens[tens_pos]);
426 
427     for (i=1; i<10; i++)
428     printf("%s %s\n", tens[tens_pos], units[i]);
429   }
430 /***/
431 
432 
433 /***/
434 
435 
436   printf("yuz\n");
437 
438 
439   for (i=1; i<10; i++)
440   printf("yuz %s\n", units[i]);
441 
442   for (i=0; i<10; i++)
443   printf("yuz %s\n", teens[i]);
444 
445   for (tens_pos=0; tens_pos<8; tens_pos++)
446   {
447 
448     printf("yuz %s\n", tens[tens_pos]);
449 
450     for (i=1; i<10; i++)
451     printf("yuz %s %s\n",
452     tens[tens_pos], units[i]);
453   }
454 
455 
456   for (hundreds_pos=2; hundreds_pos<10; hundreds_pos++)
457   {
458 
459 
460   printf("%s yuz\n", units[hundreds_pos]);
461 
462 
463   for (i=1; i<10; i++)
464   printf("%s yuz %s\n", units[hundreds_pos], units[i]);
465 
466   for (i=0; i<10; i++)
467   printf("%s yuz %s\n", units[hundreds_pos], teens[i]);
468 
469   for (tens_pos=0; tens_pos<8; tens_pos++)
470   {
471 
472     printf("%s yuz %s\n", units[hundreds_pos], tens[tens_pos]);
473 
474     for (i=1; i<10; i++)
475     printf("%s yuz %s %s\n",
476     units[hundreds_pos], tens[tens_pos], units[i]);
477   }
478 
479 
480  }
481 
482 /***/
483 
484 
485 
486 
487 
488 
489 
490 /***/
491 
492 
493   printf("bin\n");
494 
495   for (i=1; i<10; i++)
496   printf("bin %s\n", units[i]);
497 
498   for (i=0; i<10; i++)
499   printf("bin %s\n", teens[i]);
500 
501   for (tens_pos=0; tens_pos<8; tens_pos++)
502   {
503 
504     printf("bin %s\n", tens[tens_pos]);
505 
506     for (i=1; i<10; i++)
507     printf("bin %s %s\n",
508     tens[tens_pos], units[i]);
509   }
510 
511 
512 
513   printf("bin yuz\n");
514 
515   for (i=1; i<10; i++)
516   printf("bin yuz %s\n", units[i]);
517 
518   for (i=0; i<10; i++)
519   printf("bin yuz %s\n", teens[i]);
520 
521   for (tens_pos=0; tens_pos<8; tens_pos++)
522   {
523 
524     printf("bin yuz %s\n", tens[tens_pos]);
525 
526     for (i=1; i<10; i++)
527     printf("bin yuz %s %s\n",
528     tens[tens_pos], units[i]);
529   }
530 
531 
532 
533 
534 
535   for (hundreds_pos=2; hundreds_pos<10; hundreds_pos++)
536   {
537 
538 
539   printf("bin %s yuz\n",
540   units[hundreds_pos]);
541 
542 
543   for (i=1; i<10; i++)
544   printf("bin %s yuz %s\n",
545   units[hundreds_pos], units[i]);
546 
547   for (i=0; i<10; i++)
548   printf("bin %s yuz %s\n",
549   units[hundreds_pos], teens[i]);
550 
551   for (tens_pos=0; tens_pos<8; tens_pos++)
552   {
553 
554     printf("bin %s yuz %s\n",
555     units[hundreds_pos], tens[tens_pos]);
556 
557     for (i=1; i<10; i++)
558     printf("bin %s yuz %s %s\n",
559     units[hundreds_pos], tens[tens_pos], units[i]);
560   }
561 
562 
563 
564 
565 
566  }
567 
568 
569 
570 
571 /***/
572 
573 
574 
575 
576 
577 /***/
578 
579   for (thousands_pos=2; thousands_pos<10; thousands_pos++)
580   {
581 
582   printf("%s bin\n", units[thousands_pos]);
583 
584   for (i=1; i<10; i++)
585   printf("%s bin %s\n", units[thousands_pos], units[i]);
586 
587   for (i=0; i<10; i++)
588   printf("%s bin %s\n", units[thousands_pos], teens[i]);
589 
590   for (tens_pos=0; tens_pos<8; tens_pos++)
591   {
592 
593     printf("%s bin %s\n", units[thousands_pos], tens[tens_pos]);
594 
595     for (i=1; i<10; i++)
596     printf("%s bin %s %s\n",
597     units[thousands_pos], tens[tens_pos], units[i]);
598   }
599 
600 
601 
602 
603   printf("%s bin yuz\n", units[thousands_pos]);
604 
605 
606   for (i=1; i<10; i++)
607   printf("%s bin yuz %s\n",
608   units[thousands_pos], units[i]);
609 
610   for (i=0; i<10; i++)
611   printf("%s bin yuz %s\n",
612   units[thousands_pos], teens[i]);
613 
614   for (tens_pos=0; tens_pos<8; tens_pos++)
615   {
616 
617     printf("%s bin yuz %s\n",
618     units[thousands_pos], tens[tens_pos]);
619 
620     for (i=1; i<10; i++)
621     printf("%s bin yuz %s %s\n",
622     units[thousands_pos], tens[tens_pos], units[i]);
623   }
624 
625 
626 
627 
628   for (hundreds_pos=2; hundreds_pos<10; hundreds_pos++)
629   {
630 
631 
632   printf("%s bin %s yuz\n",
633   units[thousands_pos], units[hundreds_pos]);
634 
635 
636   for (i=1; i<10; i++)
637   printf("%s bin %s yuz %s\n",
638   units[thousands_pos], units[hundreds_pos], units[i]);
639 
640   for (i=0; i<10; i++)
641   printf("%s bin %s yuz %s\n",
642   units[thousands_pos], units[hundreds_pos], teens[i]);
643 
644   for (tens_pos=0; tens_pos<8; tens_pos++)
645   {
646 
647     printf("%s bin %s yuz %s\n",
648     units[thousands_pos], units[hundreds_pos], tens[tens_pos]);
649 
650     for (i=1; i<10; i++)
651     printf("%s bin %s yuz %s %s\n",
652     units[thousands_pos], units[hundreds_pos], tens[tens_pos], units[i]);
653   }
654 
655 
656 
657 
658 
659  }
660 
661 
662 
663 }
664 
665 
666 /***/
667 
668 
669 
670 
671 
672 }
673 
674 
675 
676 
677 
gplus(int start,int end)678 void gplus(int start, int end)
679 {
680 int x;
681 int y;
682 
683   if (start > end)
684   {
685   fprintf(stderr, "ERROR: start value cannot be greater than end value.\n");
686   return;
687   }
688 
689 for (x=start; x<=end; x++)
690 for (y=start; y<=end; y++)
691 printf("%d + %d = %d\n", x, y, (x + y));
692 }
693 
694 
695 
gminus(int start,int end)696 void gminus(int start, int end)
697 {
698 int x;
699 int y;
700 
701 
702   if (start > end)
703   {
704   fprintf(stderr, "ERROR: start value cannot be greater than end value.\n");
705   return;
706   }
707 
708 for (x=start; x<=end; x++)
709 for (y=start; y<=end; y++)
710 printf("%d - %d = %d\n", x, y, (x - y));
711 }
712 
713 
714 
gtimes(int start,int end)715 void gtimes(int start, int end)
716 {
717 int x;
718 int y;
719 
720   if (start > end)
721   {
722   fprintf(stderr, "ERROR: start value cannot be greater than end value.\n");
723   return;
724   }
725 
726 for (x=start; x<=end; x++)
727 for (y=start; y<=end; y++)
728 printf("%d x %d = %d\n", x, y, (x * y));
729 }
730 
731 
732 
gdivide(float start,float end)733 void gdivide(float start, float end)
734 {
735 float x;
736 float y;
737 
738 
739   if ( (start == 0) ||  (end == 0) )
740   {
741   fprintf(stderr, "ERROR: cannot divide by zero.\n");
742   return;
743   }
744 
745 
746   if (start > end)
747   {
748   fprintf(stderr, "ERROR: start value cannot be greater than end value.\n");
749   return;
750   }
751 
752 
753 
754 for (x=start; x<=end; x++)
755 for (y=start; y<=end; y++)
756 printf("%f / %f = %f\n", x, y, (x / y));
757 }
758 
759 
760