עבור לתוכן
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.

שאלה - ++c

Featured Replies

פורסם

כתבתי את זה, זה מזהה אם האיבר זוגי/אי זוגי את הזוגיים כופל פי 2 ולאי זוגיים מוסיף 2.

עכשיו אני רוצה שהאיברים לא יהיו קבועים ומספר האיברים לא יהיה קבוע. אני יודע שצריך להשתמש ב- new ואני גם יודע שאני לא יודע להשתמש ב- new.

אולי מישהו יכול לכוון אותי, את ההתחלה לפחות?

#include <iostream.h>

void evenfun(int *x, int *y)

{

*x = *y;

*x *= 2;

}

void oddfun(int *x, int *y)

{

*x = *y;

*x += 2;

}

int main()

{

int orig[10] = {5,16,7,18,27,31,33,36,47,49};

int odds[7];

int evens[3];

int i,a=0,b=0;

for(i=0; i<10; i++)

if(orig%2==0)

evenfun(evens+a++, orig+i);

else

oddfun(odds+b++, orig+i);

cout<<"\n"<<"The even numbers after modification: "<<"\n";

for(a=0;a<3;a++)

cout<<evens[a]<<" ";

cout<<"\n"<<"The odd numbers after modification: "<<"\n";

for(a=0;a<7;a++)

cout<<odds[a]<<" ";

return(0);

}

בתודה מראש.

פורסם

במקום לכתוב

int bla[10]

אתה כותב

new int bla[10]

וככה אין לך בעיה להקצות זיכרון דינאמי

כלומר אם יש לך משתנה n שאתה מקבל בקלט שמכיל את מספר האיברים אתה עושה

new int bla[n]

וזה יגדיר לך מארך בגודל n שקוראים לו bla

פורסם
  • מחבר

אז מה לא בסדר פה:

#include <iostream.h>

int main()

{

int i;

int num;

new int mush[num];

cout<<"how many numbers";

cin>>num;

for (i=0; i<num; i++)

mush = i+1;

return(0);

}

פורסם

שהגדרת את המערך לפני שקיבלת את num

זה צריך להיות

#include <iostream.h>

int main()

{

int i;

int num;

cout<<"how many numbers";

cin>>num;

int *mush = new int[num];

for (i=0; i<num; i++)

mush = i+1;

return(0);

}

התבלבלתי קודם בסינטקס המדוייק כי מזמן לא עבדתי עם C++

בעיקרון אתה עושה

int *bla = new int

או

char *bla = new char

וכו...

פורסם
  • מחבר

תודה!

ארכיון

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

דיונים חדשים

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.