ممنون میشم اگه می تونید سورس برنامه(جمع دو عدد n رقمی) رو بنوسیدنقل قول:
ممنون میشم اگه می تونید سورس برنامه(جمع دو عدد n رقمی) رو بنوسیدنقل قول:
قربونه تو [ برای مشاهده لینک ، با نام کاربری خود وارد شوید یا ثبت نام کنید ]
برنامه ای که من مینویسم همین کارو میکنه فقط از یه راه دیگه میره
OK پس حله [ برای مشاهده لینک ، با نام کاربری خود وارد شوید یا ثبت نام کنید ]
اینم اون برنامه ای که میخواستی
فقط یه باگ کوچولو داره اونم توی استفاده از Backspace توی عدد دوم که اگه از backspace استفاده نکنی مشکلی نیست ...
میشه هم اصلاً امکان پاک کردن رو حذف کنم تا این باگ کوچولو رو هم نداشته باشه ...
خودمم روی برطرف کردنش کار میکنم اما الان حسش نیس
قربونه تو [ برای مشاهده لینک ، با نام کاربری خود وارد شوید یا ثبت نام کنید ]
بفرما :
کد:#include "stdafx.h"
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
int main()
{
start: ;
int const n=21;
int A[n]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
int B[n]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
int C[n]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
int m=1,i,j,k;
char ch,opr=';',l,ans_CO,ans_RE;
system("cls");
printf("\n\nEnter Number , Oprator , next number and then enter '=' :\n\n");
En_Num_1: ;
ch=getche(); // enter - + or one number
if(ch=='-')
A[0]=1;
else if(ch=='+')
A[0]=0;
else if(ch>='0'&&ch<='9')
{
for(j=0,l=48;l<58;l++)
{
if(ch==l)
{
A[m]=j;
m++;
}
j++;
}
}
else if(ch=='\b')
{
goto En_Num_1;
}
else
{
printf("\n\nNumber is not valid !!");
printf("\n\nEnter any key to start program again ");
getch();
goto start;
}
for(i=m;i<n;) // enter number 1
{
ch=getche();
if(ch>='0'&&ch<='9') // take it
{
for(j=0,l=48;l<58;l++)
{
if(ch==l)
{
A[i]=j;
i++;
}
j++;
}
}
else if(ch=='+')// May be Oprator typed !
{
opr=ch;
printf("\b %c",opr);
break;
}
else if(ch=='\b') // Backspace
{
printf(" ");
printf("\b");
i--;
A[i]=0;
}
else // error !
{
printf("\n\nNumber is not valid !!");
printf("\n\nEnter any key to start program again ");
getch();
goto start;
}
if(i==0)
goto En_Num_1;
}
if(i!=n) // clean Array A with number 1
{
for(j=i;j>0;j--)
A[j+(n-i)]=A[j];
for(j=1;j<n-i+1;j++)
A[j]=0;
}
Enter_OP : ;
if(opr==';')
{
opr=getche(); // Scan oprator
if(opr=='+')
{
printf("\b %c",opr);
}
else // Oprator not valid
{
printf("\n\nOprator is not valid !!");
printf("\n\nEnter any key to start program again ");
getch();
goto start;
}
}
// Number 2 start
m=1;
printf(" (");
En_Num_2: ;
ch=getche(); // enter - + or one number
if(ch=='-')
B[0]=1;
else if(ch=='+')
B[0]=0;
else if(ch>='0'&&ch<='9')
{
for(j=0,l=48;l<58;l++)
{
if(ch==l)
{
B[m]=j;
m++;
}
j++;
}
}
else if(ch=='\b')
{
printf("(");
goto En_Num_2 ;
}
else // error !
{
printf("\n\nNubmer is not valid !!!");
printf("\n\nEnter any key to start program again ");
getch();
goto start;
}
for(i=m;i<n;) // enter number 2
{
ch=getche();
if(ch>='0'&&ch<='9') // take it
{
for(j=0,l=48;l<58;l++)
{
if(ch==l)
{
B[i]=j;
i++;
}
j++;
}
}
else if(ch=='\b') // Backspace
{
i--;
B[i]=0;
if(i==1)
{
printf("(");
goto En_Num_2;
}
printf(" ");
printf("\b");
}
else if(ch=='=')
{
printf("\b) = ");
break;
}
else // error !
{
printf("\n\nNubmer is not valid !!!");
printf("\n\nEnter any key to start program again ");
getch();
goto start;
}
if(i==0)
goto En_Num_2;
}
if(i==n)
{
printf(") = ");
}
if(i!=n) // clean Array B with number 1
{
for(j=i;j>0;j--)
B[j+(n-i)]=B[j];
for(j=1;j<n-i+1;j++)
B[j]=0;
}
switch( opr )
{
case'+': // OPR = +
{
if(A[0]==0&&B[0]==0||A[0]==1&&B[0]==1) // if Numbers > 0 or < 0
{
for(i=n-1;i>0;i--)
{
if(A[i]+B[i]>=10)
{
C[i]=(A[i]+B[i])%10;
A[i-1]++;
if(i==1)
{
if(A[i]+B[i]>9) // Maybe number larger than 20 numbers
{
printf("\b\b \n\n\t\t * Number is too large *");
goto Ask ;
}
}
}
else
{
C[i]=A[i]+B[i];
}
}
if(A[0]==1&&B[0]==1) // if Numbers < 0 => Result number is -
{
C[0]=1;
}
}
if(A[0]==0&&B[0]==1||A[0]==1&&B[0]==0) // if Number 1 > 0 & Number 2 < 0
{
for(i=1;i<n;i++) // A > B or A < B ???
{
if(A[i]==B[i])
continue;
else if(A[i]>B[i])
{
for(i=n-1;i>0;i--)
{
if(A[i]==0)
{
C[i]=B[i];
continue;
}
else if(A[i]-B[i]<0) // if A[i] < B[i] => A[i-1]-- & A[i]+10
{
C[i]=A[i]+10-B[i];
A[i-1]--;
}
else
{
C[i]=A[i]-B[i];
}
}// for(i=n-1;i>0;i--)
C[0]=A[0];
break;
}// else if(A[i]>B[i])
else
{
for(i=n-1;i>0;i--)
{
if(B[i]<A[i])
{
C[i]=B[i]+10-A[i];
B[i-1]--;
}
else
{
C[i]=B[i]-A[i];
}
}
C[0]=B[0];
break;
}// else
}// for(i=1;i<n;i++)
}
break;
} // Case '+'
default :
{
printf("\n\nProgram is beta you can only use + & -");
printf("\n\nEnter any key to continue program from start it ");
getch();
goto start;
}
}
if(C[0]==0) // Print Result
{
printf("+");
}
if(C[0]==1)
{
printf("-");
}
for(i=1;i<n;i++)
printf("%d",C[i]);
Ask : ;
printf("\n\nDo you wnat to continue ? (y/n)");
ans_CO=getche();
if(ans_CO=='y'&&A[1]+B[1]<10)
{
printf("\n\nDo you want to continue with Result ? (y/n)");
ans_RE=getche();
if(ans_RE=='y')
{
opr=';';
system("cls");
printf("Enter Oprator and number and then enter = :\n\n");
for(i=0;i<n;i++)
{
A[i]=C[i];
if(i==0)
continue;
printf("%d",A[i]);
}
printf(" ");
goto Enter_OP;
}
else
{
goto start;
}
}
else if(ans_CO=='y'&&A[1]+B[1]>9)
{
goto start;
}
else if(ans_CO=='n')
{
goto end;
}
end : ;
getch();
return 0;
}
باگشم برطرف شد : [ برای مشاهده لینک ، با نام کاربری خود وارد شوید یا ثبت نام کنید ]
کد:#include "stdafx.h"
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
int main()
{
start: ;
int const n=21;
int A[n]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
int B[n]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
int C[n]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
int m=1,i,j,k;
char ch,opr=';',l,ans_CO,ans_RE;
system("cls");
printf("\n\nEnter Number , Oprator , next number and then enter '=' :\n\n");
En_Num_1: ;
ch=getche(); // enter - + or one number
if(ch=='-')
A[0]=1;
else if(ch=='+')
A[0]=0;
else if(ch>='0'&&ch<='9')
{
for(j=0,l=48;l<58;l++)
{
if(ch==l)
{
A[m]=j;
m++;
}
j++;
}
}
else if(ch=='\b')
{
goto En_Num_1;
}
else
{
printf("\n\nNumber is not valid !!");
printf("\n\nEnter any key to start program again ");
getch();
goto start;
}
for(i=m;i<n;) // enter number 1
{
ch=getche();
if(ch>='0'&&ch<='9') // take it
{
for(j=0,l=48;l<58;l++)
{
if(ch==l)
{
A[i]=j;
i++;
}
j++;
}
}
else if(ch=='+')// May be Oprator typed !
{
opr=ch;
printf("\b %c",opr);
break;
}
else if(ch=='\b') // Backspace
{
printf(" ");
printf("\b");
i--;
A[i]=0;
}
else // error !
{
printf("\n\nNumber is not valid !!");
printf("\n\nEnter any key to start program again ");
getch();
goto start;
}
if(i==0)
goto En_Num_1;
}
if(i!=n) // clean Array A with number 1
{
for(j=i;j>0;j--)
A[j+(n-i)]=A[j];
for(j=1;j<n-i+1;j++)
A[j]=0;
}
Enter_OP : ;
if(opr==';')
{
opr=getche(); // Scan oprator
if(opr=='+')
{
printf("\b %c",opr);
}
else // Oprator not valid
{
printf("\n\nOprator is not valid !!");
printf("\n\nEnter any key to start program again ");
getch();
goto start;
}
}
// Number 2 start
m=1;
printf(" (");
En_Num_2: ;
ch=getche(); // enter - + or one number
if(ch=='-')
B[0]=1;
else if(ch=='+')
B[0]=0;
else if(ch>='0'&&ch<='9')
{
for(j=0,l=48;l<58;l++)
{
if(ch==l)
{
B[m]=j;
m++;
}
j++;
}
}
else if(ch=='\b')
{
printf("(");
goto En_Num_2 ;
}
else // error !
{
printf("\n\nNubmer is not valid !!!");
printf("\n\nEnter any key to start program again ");
getch();
goto start;
}
for(i=m;i<n;) // enter number 2
{
ch=getche();
if(ch>='0'&&ch<='9') // take it
{
for(j=0,l=48;l<58;l++)
{
if(ch==l)
{
B[i]=j;
i++;
}
j++;
}
}
else if(ch=='\b') // Backspace
{
i--;
if(i==0)
{
if(temp==1)
{
printf(" \b");
goto En_Num_2;
}
else if(temp==0)
{
printf("(");
goto En_Num_2;
}
}
B[i]=0;
printf(" ");
printf("\b");
}
else if(ch=='=')
{
printf("\b) = ");
break;
}
else // error !
{
printf("\n\nNubmer is not valid !!!");
printf("\n\nEnter any key to start program again ");
getch();
goto start;
}
if(i==0)
goto En_Num_2;
}
if(i==n)
{
printf(") = ");
}
if(i!=n) // clean Array B with number 1
{
for(j=i;j>0;j--)
B[j+(n-i)]=B[j];
for(j=1;j<n-i+1;j++)
B[j]=0;
}
switch( opr )
{
case'+': // OPR = +
{
if(A[0]==0&&B[0]==0||A[0]==1&&B[0]==1) // if Numbers > 0 or < 0
{
for(i=n-1;i>0;i--)
{
if(A[i]+B[i]>=10)
{
C[i]=(A[i]+B[i])%10;
A[i-1]++;
if(i==1)
{
if(A[i]+B[i]>9) // Maybe number larger than 20 numbers
{
printf("\b\b \n\n\t\t * Number is too large *");
goto Ask ;
}
}
}
else
{
C[i]=A[i]+B[i];
}
}
if(A[0]==1&&B[0]==1) // if Numbers < 0 => Result number is -
{
C[0]=1;
}
}
if(A[0]==0&&B[0]==1||A[0]==1&&B[0]==0) // if Number 1 > 0 & Number 2 < 0
{
for(i=1;i<n;i++) // A > B or A < B ???
{
if(A[i]==B[i])
continue;
else if(A[i]>B[i])
{
for(i=n-1;i>0;i--)
{
if(A[i]==0)
{
C[i]=B[i];
continue;
}
else if(A[i]-B[i]<0) // if A[i] < B[i] => A[i-1]-- & A[i]+10
{
C[i]=A[i]+10-B[i];
A[i-1]--;
}
else
{
C[i]=A[i]-B[i];
}
}// for(i=n-1;i>0;i--)
C[0]=A[0];
break;
}// else if(A[i]>B[i])
else
{
for(i=n-1;i>0;i--)
{
if(B[i]<A[i])
{
C[i]=B[i]+10-A[i];
B[i-1]--;
}
else
{
C[i]=B[i]-A[i];
}
}
C[0]=B[0];
break;
}// else
}// for(i=1;i<n;i++)
}
break;
} // Case '+'
default :
{
printf("\n\nProgram is beta you can only use + & -");
printf("\n\nEnter any key to continue program from start it ");
getch();
goto start;
}
}
if(C[0]==0) // Print Result
{
printf("+");
}
if(C[0]==1)
{
printf("-");
}
for(i=1;i<n;i++)
printf("%d",C[i]);
Ask : ;
printf("\n\nDo you wnat to continue ? (y/n)");
ans_CO=getche();
if(ans_CO=='y'&&A[1]+B[1]<10)
{
printf("\n\nDo you want to continue with Result ? (y/n)");
ans_RE=getche();
if(ans_RE=='y')
{
opr=';';
system("cls");
printf("Enter Oprator and number and then enter = :\n\n");
for(i=0;i<n;i++)
{
A[i]=C[i];
if(i==0)
continue;
printf("%d",A[i]);
}
printf(" ");
goto Enter_OP;
}
else
{
goto start;
}
}
else if(ans_CO=='y'&&A[1]+B[1]>9)
{
goto start;
}
else if(ans_CO=='n')
{
goto end;
}
end : ;
getch();
return 0;
}
خیلی آقایی
نمیدونم چطور جبران کنم؟ انشالله همیشه موفق باشی
قربونت ...نقل قول:
من فقط کپی پیست کردم برات [ برای مشاهده لینک ، با نام کاربری خود وارد شوید یا ثبت نام کنید ]
موفق باشی [ برای مشاهده لینک ، با نام کاربری خود وارد شوید یا ثبت نام کنید ]
آقا این باگ داشت که الان برطرف شد
شرمنده :11:
[PHP]#include "stdafx.h"
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
int main()
{
start: ;
int const n=21;
int A[n]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
int B[n]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
int C[n]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
int m=1,i,j,k;
char ch,opr=';',l,ans_CO,ans_RE;
system("cls");
printf("\n\nEnter Number , Oprator , next number and then enter '=' :\n\n");
En_Num_1: ;
ch=getche(); // enter - + or one number
if(ch=='-')
A[0]=1;
else if(ch=='+')
A[0]=0;
else if(ch>='0'&&ch<='9')
{
for(j=0,l=48;l<58;l++)
{
if(ch==l)
{
A[m]=j;
m++;
}
j++;
}
}
else if(ch=='\b')
{
goto En_Num_1;
}
else
{
printf("\n\nNumber is not valid !!");
printf("\n\nEnter any key to start program again ");
getch();
goto start;
}
for(i=m;i<n;) // enter number 1
{
ch=getche();
if(ch>='0'&&ch<='9') // take it
{
for(j=0,l=48;l<58;l++)
{
if(ch==l)
{
A[i]=j;
i++;
}
j++;
}
}
else if(ch=='+')// May be Oprator typed !
{
opr=ch;
printf("\b %c",opr);
break;
}
else if(ch=='\b') // Backspace
{
printf(" ");
printf("\b");
i--;
A[i]=0;
}
else // error !
{
printf("\n\nNumber is not valid !!");
printf("\n\nEnter any key to start program again ");
getch();
goto start;
}
if(i==0)
goto En_Num_1;
}
if(i!=n) // clean Array A with number 1
{
for(j=i;j>0;j--)
A[j+(n-i)]=A[j];
for(j=1;j<n-i+1;j++)
A[j]=0;
}
Enter_OP : ;
if(opr==';')
{
opr=getche(); // Scan oprator
if(opr=='+')
{
printf("\b %c",opr);
}
else // Oprator not valid
{
printf("\n\nOprator is not valid !!");
printf("\n\nEnter any key to start program again ");
getch();
goto start;
}
}
// Number 2 start
m=1;
printf(" (");
En_Num_2: ;
ch=getche(); // enter - + or one number
if(ch=='-')
B[0]=1;
else if(ch=='+')
B[0]=0;
else if(ch>='0'&&ch<='9')
{
for(j=0,l=48;l<58;l++)
{
if(ch==l)
{
B[m]=j;
m++;
}
j++;
}
}
else if(ch=='\b')
{
printf("(");
goto En_Num_2 ;
}
else // error !
{
printf("\n\nNubmer is not valid !!!");
printf("\n\nEnter any key to start program again ");
getch();
goto start;
}
for(i=m;i<n;) // enter number 2
{
ch=getche();
if(ch>='0'&&ch<='9') // take it
{
for(j=0,l=48;l<58;l++)
{
if(ch==l)
{
B[i]=j;
i++;
}
j++;
}
}
else if(ch=='\b') // Backspace
{
i--;
if(i==0)
{
if(temp==1)
{
printf(" \b");
goto En_Num_2;
}
else if(temp==0)
{
printf("(");
goto En_Num_2;
}
}
B[i]=0;
printf(" ");
printf("\b");
}
else if(ch=='=')
{
printf("\b) = ");
break;
}
else // error !
{
printf("\n\nNubmer is not valid !!!");
printf("\n\nEnter any key to start program again ");
getch();
goto start;
}
if(i==0)
goto En_Num_2;
}
if(i==n)
{
printf(") = ");
}
if(i!=n) // clean Array B with number 1
{
for(j=i;j>0;j--)
B[j+(n-i)]=B[j];
for(j=1;j<n-i+1;j++)
B[j]=0;
}
switch( opr )
{
case'+': // OPR = +
{
if(A[0]==0&&B[0]==0||A[0]==1&&B[0]==1) // if Numbers > 0 or < 0
{
for(i=n-1;i>0;i--)
{
if(A[i]+B[i]>=10)
{
C[i]=(A[i]+B[i])%10;
A[i-1]++;
if(i==1)
{
if(A[i]+B[i]>9) // Maybe number larger than 20 numbers
{
printf("\b\b \n\n\t\t * Number is too large *");
goto Ask ;
}
}
}
else
{
C[i]=A[i]+B[i];
}
}
if(A[0]==1&&B[0]==1) // if Numbers < 0 => Result number is -
{
C[0]=1;
}
}
if(A[0]==0&&B[0]==1||A[0]==1&&B[0]==0) // if Number 1 > 0 & Number 2 < 0
{
for(i=1;i<n;i++) // A > B or A < B ???
{
if(A[i]==B[i])
continue;
else if(A[i]>B[i])
{
for(j=n-1;j>0;j--)
{
if(A[j]-B[j]<0) // if A[i] < B[i] => A[i-1]-- & A[i]+10
{
C[j]=A[j]+10-B[j];
k=1;
while(A[j-k]==0)
{
A[j-k]=9;
k++;
continue;
}
A[j-k]--;
}
else
{
C[i]=A[i]-B[i];
}
}// for(i=n-1;i>0;i--)
C[0]=A[0];
break;
}// else if(A[i]>B[i])
else
{
for(i=n-1;i>0;i--)
{
if(B[i]<A[i])
{
C[i]=B[i]+10-A[i];
B[i-1]--;
}
else
{
C[i]=B[i]-A[i];
}
}
C[0]=B[0];
break;
}// else
}// for(i=1;i<n;i++)
}
break;
} // Case '+'
default :
{
printf("\n\nProgram is beta you can only use + & -");
printf("\n\nEnter any key to continue program from start it ");
getch();
goto start;
}
}
if(C[0]==0) // Print Result
{
printf("+");
}
if(C[0]==1)
{
printf("-");
}
for(i=1;i<n;i++)
printf("%d",C[i]);
Ask : ;
printf("\n\nDo you wnat to continue ? (y/n)");
ans_CO=getche();
if(ans_CO=='y'&&A[1]+B[1]<10)
{
printf("\n\nDo you want to continue with Result ? (y/n)");
ans_RE=getche();
if(ans_RE=='y')
{
opr=';';
system("cls");
printf("Enter Oprator and number and then enter = :\n\n");
for(i=0;i<n;i++)
{
A[i]=C[i];
if(i==0)
continue;
printf("%d",A[i]);
}
printf(" ");
goto Enter_OP;
}
else
{
goto start;
}
}
else if(ans_CO=='y'&&A[1]+B[1]>9)
{
goto start;
}
else if(ans_CO=='n')
{
goto end;
}
end : ;
getch();
return 0;
}[/PHP]