Advertisement
Guest User

Untitled

a guest
Nov 22nd, 2019
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.45 KB | None | 0 0
  1. /*Ejercicio 13, relacion 4*/
  2. #include<stdio.h>
  3. #include<math.h>
  4.  
  5. void morse(int numero, int elementos, char *l[1000]){
  6.  
  7. int i, x;
  8. int v[1000];
  9.  
  10.  
  11. for(i=elementos-1; i>=0; i--){
  12. v[i] = numero/pow(10, i);
  13. numero = numero -v[i]*pow(10, i);
  14. }
  15. for(i=0; i<elementos; i++){
  16. x = v[elementos-i-1];
  17. if(x==0){
  18. l[i] = "-----";
  19. }
  20. if(x==1){
  21. l[i] = ".----";
  22. }
  23. if(x==2){
  24. l[i] = "..---";
  25. }
  26. if(x==3){
  27. l[i] == "...--";
  28. }
  29. if(x==4){
  30. l[i] == "....-";
  31. }
  32. if(x==5){
  33. l[i] == ".....";
  34. }
  35. if(x==6){
  36. l[i] = "-....";
  37. }
  38. if(x==7){
  39. l[i] = "--...";
  40. }
  41. if(x==8){
  42. l[i] = "---..";
  43. }
  44. if(x==9){
  45. l[i] = "----.";
  46. }
  47. }
  48.  
  49.  
  50.  
  51.  
  52.  
  53. }
  54.  
  55.  
  56.  
  57. int main(){
  58.  
  59. int numero, n, elementos = 1, i;
  60. char *l[1000];
  61.  
  62.  
  63. printf("\nIntroduce el numero que quiere pasar a morse: ");
  64. scanf("%d", &numero);
  65.  
  66. n = numero;
  67. while(numero>=10){
  68. numero = numero/10; /*Clacular elementos*/
  69. elementos++;
  70. }
  71. printf("\nElementos: %d", elementos);
  72.  
  73. morse(n, elementos, l);
  74. printf("\nNumero: %d es en codigo morse: ", n);
  75. for(i=0; i<elementos; i++){
  76. printf("%s", l[i]);
  77. }
  78.  
  79. return 0;
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement