Pascal/Turbo Pascal - Ejercicios para pascal (Necesito ayuda)

 
Vista:

Ejercicios para pascal (Necesito ayuda)

Publicado por Roger (4 intervenciones) el 28/01/2013 18:17:21
Buenas para ver si me pueden ayudar en estos ejercicios que tengo que resolver, soy nuevo en pascal y no se tanto:

CICLOS
1.- REALICE UN PROGRAMA QUE CALCULE EL FACTORIAL DE UN NUMERO INTRODUCIDO POR TECLADO UTILIZANDO LOS TRES CICLOS (FOR, WHILE Y REPEAT).

2.- ENCONTRAR EL NUMERO MAYOR DE UNA SERIE DE NUMEROS. LA CANTIDAD DE NUMEROS SE PEDIRA AL PRINCIPIO DEL PROGRAMA.

3.- CALCULAR LA MEDIA DE LAS NOTAS INTRODUCIDAS POR TECLADO. LA CANTIDAD DE NOTAS SERA PEDIDA AL PRINCIPIO DEL PROGRAMA.

4.- DETERMINAR SI UN NUMERO INTRODUCIDO POR TECLADO ES PRIMO O NO.

5.- CALCULAR LA SUMA DE LA SERIE 1/1+1/2+…+1/N, DONDE N ES UN NUMERO QUE SE INTRODUCE POR TECLADO.

6.- ESCRIBIR UN PROGRAMA QUE CALCULE LA SUMA DE LOS 50 PRIMEROS NUMEROS ENTEROS.

7.- CALCULAR LA SUMA DE UNA SERIE DE NUMEROS INTRODUCIDOS POR TECLADO.
8.- UN NUMERO PERFECTO ES AQUEL NUMERO QUE ES IGUAL LA SUMA DE TODAS SUS DIVISIONES EXCEPTO EL MISMO. EL PRIMER NUMERO PERFECTO ES EL 6 YA QUE 1+2+3=6. ESCRIBIR UN PROGRAMA QUE MUESTRE TODOS LOS NUMEROS PERFECTOS HASTA UN NUMERO LEIDO POR TECLADO.

9.- ESCRIBIR UN PROGRAMA QUE CACULE Y VISUALICE EL MAS GRANDE, EL MAS PEQUEÑO Y LA MEDIA DE N NUMEROS. EL VLOR DE N SE SOLICITARA AL PRINCIPIO DEL PROGRAMA Y LOS NUMEROS SERAN INTRODUCIDOS POR EL USUARIO.

10.- PAR ENCONTRAR EL MAXIMO COMUN DIVISOR(mcd), DE DOS NUMEROS SE EMPLEA EL ALGORITMO DE EUCLIDES, QUE SE PUEDE DESCRIBIR ASI: DADOS LOS ENTEROS A Y B (A>B), SE DIVIDE A POR B, OBTENIENDO EL COCIENTE Q1 Y EL RESTO R1. SI R1<>0, SE DIVIDE B POR R1, OBTENIENDO EL COCIENTE Q2 Y EL RESTO R2. SI R2<>0, SE DIVIDE R2 POR R1, OBTENIENDO COCIENTES Y RESTOS SUCESIVOS. EL PROCESO CONTINUA HASTA OBTENER UN RESTO IGUAL A 0. EL RESTO ANTERIOR A ESTE ES EL MAXIMO COMUN DIVISOR DE LOS NUMEROS INICIALES. DISEÑE UN PROGRAMA QUE CALCULE EL MAXIMO COMUN DIVISOR MEDIANTE EL ALGORITMO DE EUCLIDES.
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
1
Responder

Ejercicios para pascal (Necesito ayuda)

Publicado por ramon (2158 intervenciones) el 30/01/2013 18:51:27
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
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
{A ver si esto te ayuda}
 
 program numeros;
 {$N+}
 uses
   crt;
  var
    numero : integer;
 
  procedure entradas;
  begin
     write('  Entre Numero : ');
     readln(numero);
  end;
 
  procedure factorial_de_un_numero;
  var
    cont : integer;
    fact : longint;
  begin
      entradas;
      if numero = 0 then
      fact := 1
    else
       begin
         if (numero > 0) and (numero <= 500) then
         begin
            fact := 1;
            for cont := 1 to numero do
            fact := fact * cont;
          end
       else
         fact := 0;
       end;
           writeln;
           writeln('  El Factor De [ ',numero,' ] Es : ',fact);
           writeln;
           writeln('  Pulse [Enter]');
           readln;
      end;
 
    procedure mayor_numero;
    var
      canti : integer;
      may, cont  : integer;
      numeros : array[1..20] of integer;
     begin
         clrscr;
         writeln;
         write('  Entre Cuantos Numeros Entrara max.[20] : ');
         readln(canti);
       for cont := 1 to canti do
       begin
          write(' Entre Num.[ ',cont,' ] : ');
          readln(numeros[cont]);
       end;
         may := 0;
         for cont := 1 to canti do
         if numeros[cont] > may then
         may := numeros[cont];
         writeln;
         writeln('  El Numero Mayor Es : ',may);
         writeln;
         writeln('  Pulse [Enter]');
         readln;
     end;
 
   procedure calculo_media;
    var
      canti : integer;
      nota, cont  : integer;
      notas : array[1..30] of integer;
     begin
         clrscr;
         writeln;
         write('  Entre Cuantas Notas Entrara max.[30] : ');
         readln(canti);
         for cont := 1 to canti do
         begin
            write('  Entre Nota Num.[ ',cont,' ] : ');
            readln(notas[cont]);
         end;
         nota := 0;
         for cont := 1 to canti do
         nota := nota + notas[cont];
         writeln;
         writeln('  El Medio De Las Notas Es : ',nota div canti);
         writeln;
         writeln('  Pulse [Enter]');
         readln;
      end;
 
   procedure el_numero_es_primo;
   var
     i, nu, num : integer;
     esp : boolean;
   begin
        Write('Introduzca Un Numero Entero : ');
        Readln(num);
        Writeln;
        if num < 1 then
        num := 1;
        if num > 2 then
        begin
        if num mod 2 = 0 then
        esp := true;
        nu := round(sqrt(num));
        for i := nu to (num - 1) do
        begin
          If num mod i = 0 Then
          esp := true
        end;
        If esp = true then
        writeln(' El Num. [ ',num,' ] No Es Un Numero Primo')
     else
        writeln(' El Num. [ ',num,' ] Si Es Un Numero Primo');
     end
   else
      writeln(' El Num. [ ',num,' ] Es El Unico Numero Par Que Es Primo');
      writeln;
      writeln('   Pulse [Enter]');
      readln;
   end;
 
   procedure suma_de_la_serie_num;
   var
      i, num : integer;
      suma : real;
   begin
       clrscr;
       write('  Entre Numeros A sumar : ');
       readln(num);
       suma := 0;
       for i := 1 to num do
       begin
          suma := suma + (1 / i);
       end;
       writeln;
       writeln('  La Suma Es : ',suma:8:2);
       writeln;
       writeln('  Pulsa [Enter]');
       readln;
   end;
 
  procedure Suma_de_los_50_numeros_enteros;
  var
    num : word;
    i : integer;
  begin
      clrscr;
      num := 0;
      for i := 1 to 50 do
      num := num + i;
      writeln;
      writeln('  La Suma De Los 50 Primeros Numeros Enteros Es : ',num);
      writeln;
      writeln('  Pulse [Enter]');
      readln;
  end;
 
  procedure calculo_suma_numeros;
  var
    num : integer;
    suma : word;
  begin
     suma := 0;
     while num <> 0 do
     begin
     write('  Entre Numero A Sumar El [0] termina : ');
     readln(num);
     if num <> 0 then
     suma := suma + num;
     end;
     writeln;
     writeln('  La Suma De Los Numeros Entrados Es : ',suma);
     writeln;
     writeln('  Pulse [Enter]');
     readln;
  end;
 
   procedure el_num_es_perfecto;
   var
     numero, i, divi, almac : integer;
     ok : boolean;
   begin
      clrscr;
      write(' Entre El Numero : ');
      readln(numero);
      ok := false;
      for i := 1 to 1000 do
      begin
      almac := 0;
       for divi := 1 to i - 1 do
       if i mod divi = 0 then
       almac := almac + divi;
       if almac = i then
         if almac = numero then
         begin
         writeln;
         writeln('   El Numero [ ',numero,' ] Es Perfecto');
         ok := true;
         break;
        end;
      end;
      if ok = false then
      begin
      writeln;
      writeln('   El Numero [ ',numero,' ] No Es Perfecto');
      end;
      writeln;
      writeln('   Pulse [Enter]');
      readln;
   end;
 
 
  procedure mas_grande_el_mas_peque_y_la_media;
  var
    numeros : array[1..40] of integer;
    n, temp, num : integer;
    k, i, gra, peq, med : integer;
    begin
        writeln('  Entre Numeros a Entrar Max 40');
        write(' Num. : ');
        readln(n);
        clrscr;
        writeln('  Entre Numeros ');
        writeln;
        num := 1;
        while num <> n do
        begin
        write(' Numero [ ',num,' ] : ');
        readln(numeros[num]);
        if numeros[num] <> 0 then
        num := num + 1;
        if num > 40 then
        num := 40;
        end;
        for i := 1 to num - 1 do
          for k := i + 1 to num - 1 do
          begin
          if numeros[i] < numeros[k] then
          begin
             temp := numeros[k];
             numeros[k] := numeros[i];
             numeros[i] := temp;
          end;
        end;
          i := 0;
          for k := 1 to num - 1 do
          i := i + numeros[k];
          writeln;
          writeln('  El Numero Mayor Es : ',numeros[1]);
          writeln('  El Numero Menor Es : ',numeros[num - 1]);
          writeln('  La Media Es        : ',i div 2);
          writeln;
          writeln('  Pulse [Enter]');
          readln;
      end;
 
   procedure maximo_comun_divisor;
   var
     dividendo, divisor, resto : integer;
   begin
      clrscr;
      write(' Entre El Numero Del Dividendo : ');
      readln(dividendo);
      write(' Entre El Numero Del Divisor   : ');
      readln(divisor);
     repeat
         begin
         resto := dividendo mod divisor;
         dividendo := divisor;
         divisor := resto;
         end;
      until resto = 0;
      writeln;
      writeln('  El Maximo Comun Divisor es : ',dividendo);
      writeln;
      writeln('  Pulse [Enter]');
      readln;
   end;
 
   procedure menu;
   var
      sal : boolean;
      tec : char;
   begin
       sal := false;
       repeat
           clrscr;
           writeln('**** Menu General ****');
           writeln;
           writeln('  0 = factorial_de_un_numero');
           writeln('  1 = mayor_numero');
           writeln('  2 = calculo_media');
           writeln('  3 = el_numero_es_primo');
           writeln('  4 = suma_de_la_serie_num');
           writeln('  5 = Suma_de_los_50_numeros_enteros');
           writeln('  6 = calculo_suma_numeros');
           writeln('  7 = mas_grande_el_mas_peque_y_la_media');
           writeln('  8 = el_num_es_perfecto');
           writeln('  9 = maximo_comun_divisor');
           writeln('  S = Salir');
           writeln;
           writeln('<<< Elija Opcion >>>');
           repeat
               tec := readkey;
           until tec in[#48..#57,'s','S'];
     case tec of
   #48 : begin
            clrscr;
            factorial_de_un_numero;
         end;
   #49 : begin
            clrscr;
            mayor_numero;
         end;
   #50 : begin
            clrscr;
            calculo_media;
         end;
   #51 : begin
            clrscr;
            el_numero_es_primo;
         end;
   #52 : begin
            clrscr;
            suma_de_la_serie_num;
         end;
   #53 : begin
            clrscr;
            Suma_de_los_50_numeros_enteros;
         end;
   #54 : begin
            clrscr;
            calculo_suma_numeros;
         end;
   #55 : begin
           clrscr;
           mas_grande_el_mas_peque_y_la_media;
         end;
   #56 : begin
           clrscr;
           el_num_es_perfecto;
         end;
   #57 : begin
           clrscr;
           maximo_comun_divisor;
         end;
  's','S' : 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
1
Comentar

Ejercicios para pascal (Necesito ayuda)

Publicado por Roger (4 intervenciones) el 30/01/2013 22:41:33
Gracias Ramon mil mil mil mil gracias!!! Te debo una
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