PDA

View Full Version : سوال: توجه: برنامه ای بعنوانه ضرب 2 عدد n رقمی در یکدیگر!!!



termavali
شنبه 18 دی 1389, 13:11 عصر
سلام.:لبخندساده:
چه طوری میشه 2 تا عدد چند رقمی رو در هم ضرب کرد؟؟؟:متعجب:
خواهش میکنم هر کی بلده کمکم کنه!!:لبخند:
برنامشو لازم دارم.
مررررررسسسی ی ی ی ی

Arcsinos
شنبه 18 دی 1389, 13:17 عصر
دوست عزیز این برنامه اعداد 100 رقمی رو + و - و / و * میکنه میتونی طول آرایه ها رو هم تغییر بدی و به N برسونی :
توضیحاتش هم اینجاست (http://barnamenevis.org/showthread.php?226788-%D8%A7%D9%84%DA%AF%D9%88%D8%B1%DB%8C%D8%AA%D9%85-%D8%AA%D9%82%D8%B3%DB%8C%D9%85-%D8%A2%D8%B1%D8%A7%DB%8C%D9%87-%D8%A7%DB%8C)

#include "stdafx.h"
#include "iostream"
#include "conio.h"
using namespace std;
void input(int[],int[]);
void jame(int[],int[],int[],int);
void tafrigh(int[],int[],int[],int);
void zarb(int[],int[],int[],int);
void taghsim(int[],int[],int[],int);
int _tmain(int argc, _TCHAR* argv[])
{int
first[100]={0},
second[100]={0},
output[200]={0};
int count=199;
char in='y',op='!';
for(int l=0; l<80; l++)cout<<"-";
input(first,second);
cout<<"\nEnter operator: ";
cin>>op;
switch (op){
case '+':jame(first,second,output,count); break;
case '-':tafrigh(first,second,output,count); break;
case '*':zarb(first,second,output,count); break;
case '/':taghsim(first,second,output,count); break;
default : cout<<"Error: the operator valid.";}
getch();
return 0;
}
void input(int first[],int second[]){
int i=0,j=0;
char n1ch[100];
char n2ch[100];
cout<<"\nFirst number : ";
cin.getline(n1ch,98);
cout<<"\nSecond number : ";
cin.getline(n2ch,98);
while(n1ch[i]!=NULL)
i++;
while(n2ch[j]!=NULL)
j++;
for(int a=0;a<i;a++){
if(((int(n1ch[a])-48)>9)||((int(n1ch[a])-48)<0)||(i>99)){
cout<<"\n Error: input must be a number.";
break;}
else
first[100-i+a]=int(n1ch[a])-48;
}
for(int a=0;a<j;a++){
if(((int(n2ch[a])-48)>9)||((int(n2ch[a])-48)<0)||(j>99)){
cout<<"\n Error: input must be a number.";
break;}
else
second[100-j+a]=int(n2ch[a])-48;
}
}

void jame(int first[],int second[],int output[],int count){
for(int k=99; k>=0; k--){
output[count]+=(first[k]+second[k]);
if (output[count]>9){
output[(count-1)]++;
output[count]=(output[count]-10);}
count--;}
while (output[count]==0) count++;
cout<<"\nResult: ";
for(int r=count; r<200; r++){
cout<<output[r];
output[r]=0;}
}
void tafrigh(int first[],int second[],int output[],int count){
int temp;
bool flag=false;
for(int i=0; i<100; i++){
if (second[i]>first[i]){
flag=true;
for(int j=0; j<100; j++){
temp=second[j];
second[j]=first[j];
first[j]=temp;}
break;}
else if (second[i]<first[i]){
flag = false;
break;
}}
for(int k=99; k>=0; k--){
output[count]+=(first[k]-second[k]);
if (output[count]<0){
output[count-1]=(-1);
output[count]=(output[count]+10);}
count--;}
while (output[count]==0) count++;
cout<<"\nResult: ";
if (flag) cout<<"-";
for(int r=count; r<200; r++){
cout<<output[r];
output[r]=0;}
}
void zarb(int first[],int second[],int output[],int count){
int temp[200][100]={{0},{0}};
int t=0;
for(int i=99; i>=0; i--){
int y=199;
for(int j=100; j>0; j--){
temp[y-t][t]+=(second[i]*first[j-1]);
if (temp[y-t][t]>9){
temp[y-t-1][t]=(temp[y-t][t]/10);
temp[y-t][t]=(temp[y-t][t]%10);}
y--;
}
t++;}
for(int f=199; f>=0; f--){
for(int e=99; e>=0; e--)
output[count]+=temp[f][e];
if (output[count]>9){
output[count-1]=(output[count]/10);
output[count]=output[count]%10;}
count--;
}
count++;
while(output[count]==0)count++;
cout<<endl;
for(int q=count; q<200; q++){
cout<<output[q];
output[q]=0;}
}
void taghsim(int first[],int second[],int output[],int count){
int temp[200]={0},tc=0;
bool flag=true;
for(int i=0; i<100; i++)
if (second[i]>first[i]){
cout<<"Error: Taghsim soorat nemigirad!";
flag=false;
break;}
else if (second[i]<first[i]) break;

while(flag){
output[199]++;
for(int a=199;a>=99;a--)
if(output[a]>9){
output[a]=0;
output[a-1]++;}

for(int k=99; k>=0; k--){
temp[count]+=(first[k]-second[k]);
if (temp[count]<0){
temp[count-1]=(-1);
temp[count]=(temp[count]+10);}
count--;}
while(temp[count]==0) {//>OK
first[count-100]=0;
count++;}

for (int r=199;r>=count;r--){
first[r-100]=temp[r];
temp[r]=0;
}

for(int i=0; i<100; i++)
if(second[i]>first[i])
flag=false;
else if(second[i]<first[i])
break;

count=199; }
while (output[tc]==0)tc++;
cout<<"___________\nResult: ";
for(int b=tc;b<200;b++)
cout<<output[b];
cout<<"\n___________";
}