עבור לתוכן
View in the app

A better way to browse. Learn more.

HWzone

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

char *add_str (char *num1,char num*2) C languge

Featured Replies

פורסם
  • מחבר

לא כתבתי כלום שניצל...

בגלל זה אני פה,לקבל עזרה בכתיבת הקוד

פורסם

תחשוב איך עושים חיבור ארוך, צעד אחרי צעד.

תרשום את הצעדים אחד אחד (איפה מתחילים? מתי מפסיקים?, מה חוזר על עצמו? מה לא?), על דף, עד שאתה סגור לגמרי שכיסית את כל המקרים.

ותרגם את זה לקוד.

זהו, סיימת

פורסם
  • מחבר


char * add_str (char *num1, char *num2)
{
int l1= strlen(num1);
int l2= strlen(num2);
int newsize=0;
int i=0,j=0;
int carry=0,x=0;
char temp,temp2;
char *newstr;
if(l1 >= l2)
newsize=l1+2;
else
newsize = l2+2;
newstr=(char*)calloc(newsize , sizeof(char));

for(i = newsize-2 ; i>=0 ; i--)
{


x = num1[i]-'0' + num2[i]-'0' + carry ;
if(x>9){
carry = 1 ;
newstr[i+1] = x%10 + '0' ;
}
else{
carry=0 ;
newstr[i] = x+'0' ;
}


}
if(carry){
for(i=0; i < strlen(newstr) ; i++){
temp = newstr[i+1] ;
newstr[i+1] = newstr[i] ;
newstr[i]=temp;



}
newstr[0] = '1';
}
//newstr[0]= carry + '0' ;
newstr[newsize+1] = '\0' ;
return newstr;

חבר'ה יש למישהו משהו יותר אלגנטי?

פורסם

הרעיון מוצלח, אבל יש לך כמה באגים פה ושם.

אני מבין שאתה צריך לרוץ על המספרים מהסוף להתחלה, אבל הלולאה שלך עובדת כאילו שניהם באותו אורך. שים לב שהתא הראשון שאתה ניגש אליו הוא newsize-2, כשזה לא בהכרח התא שמכיל את ספרת האחדות בשני המספרים.

ארכיון

דיון זה הועבר לארכיון ולא ניתן להוסיף בו תגובות חדשות.

דיונים חדשים

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.