Pascal/Turbo Pascal - Necesito ayuda con uns ejercicios

 
Vista:

Necesito ayuda con uns ejercicios

Publicado por Oscar (2 intervenciones) el 11/02/2013 19:46:00
Ayudan con estos programas.!
PD.: Deben utilizarce procedimientos y funciones en los programas.!

1) Elabore un programa que genere la sucesión de Fibonacci. En este programa debe usar una función que genere dichos números.


2) Elabore un programa que muestra si un carácter introducido es un número o no, para ello usted debe de construir que verifique lo anterior.


3) Construir una función que reciba como parámetro un entero positivo y devuelva su factorial.


4) Construir una función que reciba como parámetro un entero positivo y devuelva su equivalente en el sistema binario.


5) Diseñar una función que devuelva el máximo común divisor de los números naturales suministrados como parámetros, otra que devuelva el mínimo común múltiplo, y una tercera que devuelva si los numerosa son primos entre si. Para el cálculo del m.c.d se utilizara el algoritmo de Euclides: mcd(a,b)=mcd(b, a mod b), y mcd(a,0)=a. Para el resto se intentara aprovechar las funciones desarrolladas.



6) Diseñe un procedimiento que calcule el número combinatorio.


7) Dos números se dicen amigos si la suma de los divisores de cada uno de ellos (incluida la unidad, y exceptuando el número mismo) es igual al otro número dado. Escribir un procedure en Pascal para determinar si dos números enteros x e y son amigos.
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder

Necesito ayuda con uns ejercicios

Publicado por ramon (2158 intervenciones) el 14/02/2013 19:34:19
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
{A ver si esto es lo que pides el resto mas tarde}
 
 program multiples;
  uses
     crt;
 
 
  function fibonacci(n : longint) : longint;
  begin
      if n < 2 then
       fibonacci := n
    else
      fibonacci := fibonacci(n - 1) + fibonacci(n - 2);
  end;
 
  procedure caracteresnumero;
  var
    tec : char;
  begin
      writeln;
      write('    Entre Caracter : ');
      tec := readkey;
      write(tec);
      writeln;
      if ord(tec) - 48 in[0..9] then
      writeln('  El Caracter Entrado Es Un Numerico')
    else
      writeln('  El Caracter Entrado No Es Un Numerico');
  end;
 
  function factorialdenumero(n : integer) : longint;
  var
    k : integer;
    da : longint;
  begin
     factorialdenumero := 0;
     da := n;
     for k := n downto 1 do
     da := da * k;
     factorialdenumero := da;
  end;
 
  function enterobinario(n : integer) : string;
   Var
       binario : String[8];
       i, t, cont : Byte;
  begin
   cont := 2;
   i := 1;
   For t := 8 downto 1 do
    begin
     if (n and cont) = cont then
     begin
     binario[t] := '1';
     binario[0] := chr(i);
     i := i + 1;
     end
 else
     begin
     binario[t] := '0';
     binario[0] := chr(i);
     i := i + 1;
     end;
     cont := cont * 2;
    end;
    enterobinario := copy(binario,1,length(binario));
  end;
 
 
 
 
 
 
 
   begin
      clrscr;
      writeln('  El Fibonacci     Es = ',fibonacci(10));
      writeln('  El Factorial     Es = ',factorialdenumero(10));
      writeln('  El Binario N.    Es = ',enterobinario(2));
      caracteresnumero;
      readln;
   end.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

Necesito ayuda con uns ejercicios

Publicado por ramon (2158 intervenciones) el 16/02/2013 14:49:34
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
{A qui tienes todo a ver si te vale como ayuda}
 
program multiples;
  {$N+}
  uses
     crt;
  var
     num, num1 : longint;
     dar : extended;
 
  function fibonacci(n : word) : longint;
  var
     v1 : integer;
     m1, n1, h1 : longint;
  begin
    if n > 46 then
    n := 46;
    h1 := 1;
    n1  := 1;
    m1  := 1;
    if n < 2 then
       fibonacci := n
   else
    for v1 := 3 to n do
    begin
      h1 := n1 + m1;
      m1  := n1;
      n1  := h1;
    end;
     fibonacci := h1;
    end;
 
  procedure caracteresnumero;
  var
    tec : char;
  begin
      write('    Entre Caracter : ');
      tec := readkey;
      writeln;
      if ord(tec) - 48 in[0..9] then
      writeln('  El Caracter Entrado Es [',tec,']    = Es Un Numerico')
    else
      writeln('  El Caracter Entrado Es [',tec,']    = No Es Un Numerico');
  end;
 
  function factorialdenumero(n : integer) : extended;
  var
    k : integer;
    da : extended;
  begin
     if n <= 0 then
     da := 1
   else
     begin
       if (n > 0) and (n < 500) then
       begin
          da := 1;
           for k := 1 to n do
           begin
              da := da * k;
           end;
         end
       else
          da := 0;
       end;
     factorialdenumero := da;
  end;
 
  function enterobinario(n : integer) : string;
   Var
       binario : String[8];
       i, t, cont : Byte;
  begin
   cont := 2;
   i := 1;
   For t := 8 downto 1 do
    begin
     if (n and cont) = cont then
     begin
     binario[t] := '1';
     binario[0] := chr(i);
     i := i + 1;
     end
 else
     begin
     binario[t] := '0';
     binario[0] := chr(i);
     i := i + 1;
     end;
     cont := cont * 2;
    end;
    enterobinario := copy(binario,1,length(binario));
  end;
 
  function numerosonprimosentresi(c1, c2 : longint) : string;
  var
    m, t, t1, t2 : integer;
   begin
      m := 1;
      t := 1;
      numerosonprimosentresi := 'Si Son Primos';
    repeat
        t1 := c1 div m;
        t2 := c2 div t;
       if (t1 = t2) and (t > 1) then
       numerosonprimosentresi := 'No Son Primos';
       m := m + 1;
       t := t + 1;
    until (m > c1) or (t > c2);
   end;
 
  function comundivisores(n1, n2 : longint) : longint;
  var
    mx, mn, t, i : longint;
  begin
      if n1 < n2 then
      begin
          t := n1;
          n1 := n2;
          n2 := t;
      end;
      mx := n1;
      mn := n2;
      if n1 = 0 then
      comundivisores := n2
   else
      if n2 = 0 then
      comundivisores := n1
   else
     if (n1 = 0) and (n2 = 0) then
     comundivisores := 0
   else
      comundivisores := comundivisores(mx mod mn,mn);
  end;
 
  function comunmultiplo(n1, n2 : longint) : longint;
  var
    mx, mn, t, i : longint;
  begin
     mx := comundivisores(n1,n2);
     comunmultiplo := (n1 * n2) div mx;
  end;
 
  function numerocombinatorio(m1, n1 : integer) : longint;
  var
    t, canv, rest : integer;
    toma : longint;
    t1, t2 : longint;
  begin
      if n1 > m1 then
      begin
         canv := m1;
         m1 := n1;
         n1 := canv;
      end;
      rest := m1 - n1;
      t := 1;
      toma := 0;
      t1 := m1;
      t2 := rest;
    repeat
        t1 := (t1 * (m1 - t));
        t2 := (t2 * (rest - t));
        t := t + 1;
    until t = rest;
    toma := (t1 div t2);
    numerocombinatorio := round(toma);
  end;
 
  function numerosamigos(m1, n1 : longint) : boolean;
  var
    to1, to2 : longint;
    h1, h2 : integer;
  begin
     to1 := 0;
     to2 := 0;
     for h1 := 1 to m1 - 1 do
      if m1 mod h1 = 0 then
       to1 := to1 + h1;
       for h2 := 1 to n1 - 1 do
        if n1 mod h2 = 0 then
         to2 := to2 + h2;
     if (to1 = n1) and (to2 = m1) then
     numerosamigos := true
   else
     numerosamigos := false;
  end;
 
  procedure menu;
  var
    tec : char;
    sal : boolean;
  begin
     sal := false;
    repeat
       clrscr;
       writeln('    ***** Menu Jeneral *****');
       writeln;
       writeln('     1 =  Sucesion de Fibonacci');
       writeln('     2 =  El Caracter Es Un Numero');
       writeln('     3 =  El Factorial De Un Entero');
       writeln('     4 =  Entero Positivo A Binario');
       writeln('     5 =  Maximo Comun Divisor');
       writeln('     6 =  Minimo Comun Multiplo');
       writeln('     7 =  Numeros Son Primos Entre Si');
       writeln('     8 =  Numero Combinatorio');
       writeln('     9 =  2 Numeros Enteros Son Amigos');
       writeln('     0 =  Salir');
       writeln;
       writeln('     <<<<< Elija Opcion >>>>>');
       repeat
       tec := readkey;
       until tec in[#48..#57];
       clrscr;
    case tec of
 '1' : begin
          write('    Entre numero : ');
          readln(num);
          writeln;
          writeln('   El Numero Fibonacci De [',num,'] Es : ',fibonacci(num));
          writeln;
          writeln('    Pulse [Enter]');
          readln;
       end;
 '2' : begin
          caracteresnumero;
          writeln;
          writeln('   Pulse [Enter]');
          readln;
       end;
 '3' : begin
          write('    Entre numero : ');
          readln(num);
          dar := factorialdenumero(num);
  writeln('    El Factorial De [',num,'] Es : ',trunc(dar));
          writeln;
          writeln('    Pulse [Enter]');
          readln;
       end;
 '4' : begin
          write('    Entre numero : ');
          readln(num);
    writeln('    El Numero Binario De [',num,'] Es : ',enterobinario(num));
          writeln;
          writeln('    Pulse [Enter]');
          readln;
       end;
 '5' : begin
          write('    Entre numero [1] : ');
          readln(num);
          write('    Entre numero [2] : ');
          readln(num1);
          writeln('    El Comun Divisor De [',num,' Y ',num1,'] Es : ',
                                              comundivisores(num, num1));
          writeln;
          writeln('    Pulse [Enter]');
          readln;
       end;
 '6' : begin
          write('    Entre numero [1] : ');
          readln(num);
          write('    Entre numero [2] : ');
          readln(num1);
          writeln('    El Comun Multiplo De [',num,' Y ',num1,'] Es : ',
                                        comunmultiplo(num,num1));
          writeln;
          writeln('    Pulse [Enter]');
          readln;
       end;
 '7' : begin
          write('    Entre numero [1] : ');
          readln(num);
          write('    Entre numero [2] : ');
          readln(num1);
 writeln('    Los Numeros [',num,' Y ',num1,'] Son Primos Entresi : ',
                                     numerosonprimosentresi(num, num1));
          writeln;
          writeln('    Pulse [Enter]');
          readln;
       end;
 '8' : begin
          write('    Entre numero [1] : ');
          readln(num);
          write('    Entre numero [2] : ');
          readln(num1);
     writeln('    El Numero Combinatirio De [',num,' Y ',num1,'] Es : ',
                                 numerocombinatorio(num, num1));
          writeln;
          writeln('    Pulse [Enter]');
          readln;
       end;
 '9' : begin
          write('    Entre numero [1] : ');
          readln(num);
          write('    Entre numero [2] : ');
          readln(num1);
          writeln('    Los Numeros [',num,' Y ',num1,'] Son Amigos : ',
                                        numerosamigos(num, num1));
          writeln;
          writeln('    Pulse [Enter]');
          readln;
       end;
 '0' : sal := true;
     end;
    until sal = true;
  end;
 
   begin
      clrscr;
      menu;
   end.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar