Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*Ejercicio 13, relacion 4*/
- #include<stdio.h>
- #include<math.h>
- void morse(int numero, int elementos, char *l[1000]){
- int i, x;
- int v[1000];
- for(i=elementos-1; i>=0; i--){
- v[i] = numero/pow(10, i);
- numero = numero -v[i]*pow(10, i);
- }
- for(i=0; i<elementos; i++){
- x = v[elementos-i-1];
- if(x==0){
- l[i] = "-----";
- }
- if(x==1){
- l[i] = ".----";
- }
- if(x==2){
- l[i] = "..---";
- }
- if(x==3){
- l[i] == "...--";
- }
- if(x==4){
- l[i] == "....-";
- }
- if(x==5){
- l[i] == ".....";
- }
- if(x==6){
- l[i] = "-....";
- }
- if(x==7){
- l[i] = "--...";
- }
- if(x==8){
- l[i] = "---..";
- }
- if(x==9){
- l[i] = "----.";
- }
- }
- }
- int main(){
- int numero, n, elementos = 1, i;
- char *l[1000];
- printf("\nIntroduce el numero que quiere pasar a morse: ");
- scanf("%d", &numero);
- n = numero;
- while(numero>=10){
- numero = numero/10; /*Clacular elementos*/
- elementos++;
- }
- printf("\nElementos: %d", elementos);
- morse(n, elementos, l);
- printf("\nNumero: %d es en codigo morse: ", n);
- for(i=0; i<elementos; i++){
- printf("%s", l[i]);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement