Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<conio.h>
- #include<string.h>
- #include<stdlib.h>
- #include<stdlib.h>
- const int N = 1000;
- int complong(int *a, int *b) {
- int i = 0;
- if (a[0] < b[0]) return -1;
- if (a[0] > b[0]) return 1;
- for (i = a[0]; i > 0; i--) {
- if (a[i] < b[i]) return -1;
- if (a[i] > b[i]) return 1;
- }
- return 0;
- }
- void readlong(int *a) {
- int i=0,k=0;
- char s[N+1];
- gets_s(s,N+1);
- a[0] = strlen(s);
- for (i = 0; i <a[0]; i++) {
- a[a[0] - i] = s[i] - '0';
- }
- }
- void writelong(int *a) {
- int i = 0;
- for (i = a[0]; i >= 1; i--)
- printf("%d", a[i]);
- }
- void main(void) {
- int a[N + 5] = { 0 };
- int b[N + 5] = { 0 };
- int y[N + 1] = { 0 };
- int m = 0;
- int c = 0;
- int i = 0;
- char p = 0,g=0;
- int j = 0;
- int k = 0;
- int cr = 0;
- int u = 0;
- int l = 0;
- int q = 0;
- printf("Enter the opearation");
- scanf_s("%c", &p);
- scanf_s("%*c", &p);
- fflush(stdin);
- switch (p) {
- case'!':
- {
- printf("Enter the number to factorize ");
- scanf_s("%d", &l);
- int d = 1000000;
- int A[N] = { 1 };
- int len = 1, r, s;
- for (k = 2; k <= l; k++) {
- i = 0; //
- r = 0; //
- while (i < len
- || r > 0) {
- s = A[i] * k + r;
- A[i] = s % d;
- r = s / d;
- i++;
- }
- len = i;
- }
- for (i = len - 1; i >= 0; i--)
- if (i == len - 1) printf("%d", A[i]);
- else printf("%.6d", A[i]);
- break;
- }
- case'-': {
- printf("Enter the first number ");
- readlong(a);
- printf("nEnter the second number ");
- readlong(b);
- if (complong(a, b) < 0) {
- printf("-");
- c = 0;
- for (i = 1; i <= b[0]; i++) {
- c = c + b[i] - a[i] + 10;
- b[i] = c % 10;
- if (c < 10) { c = -1; }
- else { c = 0; }
- }
- while ((b[b[0]] == 0 && b[0] > 1)) b[0] = b[0] - 1;
- writelong(b);
- break;
- }
- else {
- c = 0;
- for (i = 1; i <= a[0]; i++) {
- c = c + a[i] - b[i] + 10;
- a[i] = c % 10;
- if (c < 10) { c = -1; }
- else { c = 0; }
- }
- while ((a[a[0]] == 0 && a[0] > 1)) a[0] = a[0] - 1;
- writelong(a);
- }
- break;
- }
- case'+': {
- printf("Enter the first number ");
- readlong(a);
- printf("nEnter the second number ");
- readlong(b);
- if (a[0] > b[0]) {
- m = a[0];
- }
- else { m = b[0]; }
- c = 0;
- for (i = 1; i <= m; i++) {
- c = c + a[i] + b[i];
- a[i] = c % 10;
- c = c / 10;
- }
- if (c > 0) {
- m = m + 1;
- a[m] = c;
- }
- a[0] = m;
- writelong(a);
- break;
- }
- case'*': {
- printf("Enter the first number ");
- readlong(a);
- printf("nEnter the second number ");
- readlong(b);
- cr = 0;
- for (i = 1; i <= a[0]; i++) {
- for (j = 1; j <= b[0]; j++) {
- cr = a[i] * b[j];
- k = i + j - 1;
- while (cr > 0) {
- cr = cr + y[k];
- y[k] = cr % 10;
- cr = cr / 10;
- if (k > y[0]) y[0] = k;
- k = k + 1;
- }
- }
- }
- writelong(y);
- break;
- }
- case'^': { //возведение в степень
- int n = 0;
- printf("Enter the first number ");
- readlong(a);
- printf("nEnter the stepen ");
- scanf_s("%d", &n);
- cr = 0;
- for (i = 1; i <= a[0]; i++) {
- for (j = 1; j <= a[0]; j++) {
- cr = a[i] * a[j];
- k = i + j - 1;
- while (cr > 0) {
- cr = cr + y[k];
- y[k] = cr % 10;
- cr = cr / 10;
- if (k > y[0]) y[0] = k;
- k = k + 1;
- for (q = 1; q < N - 1; q++) {
- m = y[q];
- y[q] = a[q];
- a[q] = m;
- }
- }
- }
- }
- writelong(a);
- break;
- }
- default: printf("Incorrect operation"); break;
- }
- _getch();
- }
- a^n = (a^{n/2})^2 = a^{n/2} * a^{n/2}
- a^n = a^{n-1} * a
Add Comment
Please, Sign In to add comment