Sign in to follow this  
Cornel Iulian

[C] Transcrierea unui numar in notatie romana (<=100)

1 post in this topic

Cerinta: Sa se scrie un program care, preluand un numar intreg (<=100) de la consola, afiseaza transcrierea sa in notatie romana.

#include <conio.h>
#define SIMBOL_UNU		caractere_romane[simbol]
#define SIMBOL_CINCI	caractere_romane[simbol + 1]
#define SIMBOL_ZECE		caractere_romane[simbol + 2]

int main(){
	char caractere_romane[] = "IVXLC"; //i=1, v=5, x=10, l=50, c=100
	int n;
	printf("Sa se introduca un numar din intervalul 1-100: ");
	if (scanf("%d", &n) != 1)
		printf("Date eronate");
	if(n>100 || n<1){
		printf("Numarul nu se afla in intervalul [1-100]");
	int copie = n, nr_cifre = 1, pozitie = 1;
	while((copie /= 10) && nr_cifre++ && (pozitie *= 10));
	int simbol = nr_cifre * 2 - 2;
	printf("Notatia in cifre romane pentru numarul %d este: ",n);
		int cifra = n / pozitie % 10;
			case 9: printf("%c%c", 		SIMBOL_UNU, SIMBOL_ZECE); 							break;
			case 8: printf("%c%c%c%c", 	SIMBOL_CINCI, SIMBOL_UNU, SIMBOL_UNU, SIMBOL_UNU); 	break;
			case 7: printf("%c%c%C", 	SIMBOL_CINCI, SIMBOL_UNU, SIMBOL_UNU);				break;
			case 6: printf("%c%c", 		SIMBOL_CINCI, SIMBOL_UNU);						 	break;
			case 5: printf("%c",		SIMBOL_CINCI);										break;
			case 4: printf("%c%c", 		SIMBOL_UNU, SIMBOL_CINCI);							break;
			case 3: printf("%c%c%c", 	SIMBOL_UNU, SIMBOL_UNU, SIMBOL_UNU);				break;
			case 2: printf("%c%c", 		SIMBOL_UNU, SIMBOL_UNU);							break;
			case 1: printf("%c", 		SIMBOL_UNU);										break;
			default: break;
		pozitie /= 10;
		simbol -= 2;
	return 0;	


Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this