C + + programming calculates 2 of the 1 million square (n-th square of M), long result output file

Source: Internet
Author: User

#include <iostream> #include <stdio.h> #include <stdlib.h> #include <string> #include < math.h> #include <vector> #include <sstream> #include <list> #include <algorithm> #include <time.h> #include <stdarg.h> #include "myLibrary.h"//header file reference more, some and this program independent using namespace Std;const int M = 1000000;int Main (int argc, char *argv[]) {int arr[m];//Every 1 million bits, max 999999arr[0] = 1;int k, m, N, r, num = 1;//k Save a single calculation product, M As a base (input), n is a power (input), r carry, num is an array length cout << "Please enter the contents to be computed in a space-delimited case m n (Calculate the n power of M):" << endl;while (1) {cin >> m >& Gt  N;if (!cin.fail () && m > 0 && n > 0) break;cin.clear ();   Error bit reset Cin.sync (); Empty buffers Assuming that this function is not added to the loop cout << "input error, please enter again:" << Endl;} Calculate for (int i = 0; i < n; i++) {r = 0;for (int j = 0; j < Num; J + +) {k = arr[j] * m + r;arr[j] = k% m;r = k/m;} while (R > 0) {arr[num++] = r% M;r = r/m;}} Write File *FP = fopen ("D:\\resoult.txt", "W"), fprintf (FP, "%d of%d times" computedPower \ n ", M, N); for (int i = num-1; I >= 0; i--) {if (Arr[i] < 100000 && Arr[i] > 10000 && i! = num-1 ) fprintf (FP, "%s", "0"), else if (Arr[i] < 10000 && Arr[i] > 00 && i! = num-1) fprintf (FP, "%s", "  ") Else if (Arr[i] < && arr[i] > + && i! = num-1) fprintf (FP,"%s "," $ "); else if (Arr[i] <  && Arr[i] > && i! = num-1) fprintf (FP, "%s", "0000"); else if (Arr[i] < && i! = num -1) fprintf (FP, "%s", "00000"); fprintf (FP, "%d", Arr[i]);} Fclose (FP); system ("pause"); return 0;}

C + + programming calculates 2 of the 1 million square (n-th square of M), long result output file

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.