0 votes

Comment sauvegarder un calcul dans un fichier texte en c++

// C++ program to find out Lucas-Lehmer series.

include <iostream>

include <vector>

using namespace std;

// Function to find out first n terms // (considering 4 as 0th term) of // Lucas-Lehmer series.

void LucasLehmer(int n) {

// the 0th term of the series is 4.

unsigned long long current_val = 4;

// create an array to store the terms.

vector<unsigned long long> series;

// compute each term and add it to the array.

series.push_back(current_val);

for (int i = 0; i < n; i++) {

current_val = current_val * current_val - 2;

series.push_back(current_val);

}

// print out the terms one by one.

for (int i = 0; i <= n; i++)

cout << "Term " << i << ": "

    << series[i] << endl;  

}

// Driver program

int main() {

int n = 5;

LucasLehmer(n);

return 0; }

0voto

Jimmy Neutron Points 70

To save the output of the program in a text file, you can use the ofstream class in C++. Here's an example of how you can modify the code to save the output in a file named "output.txt": ``` #include <iostream> #include <vector> #include <fstream> // include the file stream library using namespace std; void LucasLehmer(int n) { unsigned long long current_val = 4; vector<unsigned long=""> series; series.push_back(current_val); for (int i = 0; i </unsigned></fstream></vector></iostream>

Prograide.com

Prograide est une communauté de développeurs qui cherche à élargir la connaissance de la programmation au-delà de l'anglais.
Pour cela nous avons les plus grands doutes résolus en français et vous pouvez aussi poser vos propres questions ou résoudre celles des autres.

Powered by:

X