Dev - C++ - Convertir de c a C++

 
Vista:

Convertir de c a C++

Publicado por anonimus (1 intervención) el 04/10/2020 03:42:08
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
#include <cstdlib>
#include <conio.h>
#include <stdio.h>
 
int main(){
 
int y,w;
cout>>"Escribe cuantos numeros:">>endl;
scanf("%i",&w);
 
int x[w];
x[0]=0;
x[1]=1;
printf("Serie Fibonacci \n");
 
for(y=2; y<w; y++) {
x[y]=x[y-2]+x[y-1];
}
for(y=0; y<w; y++) {
printf("%i",x[y]);
}
 
printf("\n\n");
printf("****************** fin *************** \n");
system("PAUSE");
return 0;
}
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
Imágen de perfil de Alfil
Val: 4.344
Oro
Ha mantenido su posición en Dev - C++ (en relación al último mes)
Gráfica de Dev - C++

Convertir de c a C++

Publicado por Alfil (1444 intervenciones) el 05/10/2020 16:57:47
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
#include <iostream>
#include <limits>
 
using namespace std;
 
int main() {
    int termino, anterior, aux, n;
 
    anterior = 0;
    termino = 1;
 
    cout << "\nNmeros: "; cin >> n;
    cout << endl;
 
    if (n >= 2)
    {
        cout << anterior << " " << termino << " ";
    }
    else if (n == 1)
        cout << anterior;
 
    int k = 2;
    while (INT_MAX - termino >= anterior && k++ < n) {
        aux = termino + anterior;
        anterior = termino;
        termino = aux;
        cout << termino << " ";
    }
 
    cout << endl;
 
    return 0;
}
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