Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string.h>
- #include <stdlib.h>
- #include <stdio.h>
- using namespace std;
- void find_the_Number(int,int,int,int);
- int gcd(int,int);
- char problem[20], beg[20],mid[10],end[10];char extr;
- int main(){
- int temp;
- cin >> problem; // 6x^2
- cin >> mid; // +5x
- cin >> end;//-6
- char *ptr;
- int a,b,c;
- a = strtol(problem, &ptr, 10); b = strtol(mid, &ptr, 10);c = strtol(end, &ptr, 10);
- for(int i=0;i<strlen(mid);i++){ // extracting the mid char
- if(mid[i] >= 97 && mid[i] <= 122){
- extr = mid[i];
- break;
- }
- }
- if(a == 0) a = 1;
- if(b == 0 ) b = 1;
- cout << " A = " <<a << " b = " << b << "C = "<<c<<endl;
- long int res = a*c;
- strcpy(beg,problem);
- strcat(problem,mid);//Making It The Total String 6x^2 + 5x - 6
- strcat(problem,end);//Same
- find_the_Number(res,b,a,c);
- }
- void find_the_Number(int number,int diff,int begNum,int endNum){
- bool negativeBit = false;
- int co =0; int flag=0;
- int arr[20];
- if (number < 0){
- negativeBit = true; number = -number;
- }
- for(int i=1; i <= number; ++i){
- if (number%i == 0) arr[co++] = i;
- }// (ax^2 + bx + c) //
- int a , b;
- for(int k = 0;k<co;k++){ // product should be equal to res,and the diffrence
- for(int s= 0;s<co;s++){ /*should be equal to b*/
- if(negativeBit){
- if(arr[k] - arr[s] == diff && arr[k] * arr[s] == number){
- a = arr[k]; b = -arr[s];
- flag = 1;
- break;}
- if(flag == 1)break;
- }
- else{
- if(arr[k] + arr[s] == diff && arr[k] * arr[s] == number){
- a = arr[k]; b = arr[s];
- flag = 1;
- break;}
- if(flag == 1)break;
- }
- }
- }
- system ("cls");
- cout << endl<<endl;
- cout << problem;cout << endl;
- cout << endl;
- printf("%s %+d%c %+d%c %s\n",beg,a,extr,b,extr,end);
- cout << endl;
- int com1 = gcd(begNum,a);
- int com2 = gcd(endNum,b);
- printf("%+d%c(%+d%c%+d)%+d(%+d%c%+d)\n",com1,extr,begNum/com1,extr,a/com1,com2,b/com2,extr,endNum/com2);
- cout << endl;
- printf("(%+d%c%+d)(%+d%c%+d)\n",com1,extr,com2,begNum/com1,extr,a/com1);
- cout << endl;
- }
- int gcd(int a ,int b){
- int rem = 10;
- while(rem != 0){
- rem = b%a;
- b = a;
- a = rem;
- }
- return b;
- }
Add Comment
Please, Sign In to add comment