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

פורסם

היי,

קיבלתי תרגיל לכתוב תוכנה לניהול צלילה של צוללת. התוכנית מקבלת רק לא ראשוני את האותיות E או D. במידה והמשתמש לחץ על E התוכנית תיסגר ובמידה והמשתמש לחץ על D הצוללת לצלול לעומק הארמסטרונג הראשון וכך הלאה. כתבתי את תחילת הקוד אבל אני לא מצליחה להעלות בכל פעם במספר הארמסטרונג הבא. אשמח לעזרה איך להתקדם ממה שכבר התחלתי. אסור להשתמש בפונקציות.

מצ"ב הקוד שהתחלתי לכתוב:

#include <stdio.h>

int main ()

{

    int n,sum,i,t,a;

    printf("Submarine at water level, D to Dive, E to Exit the Program: \n");

    char c= getchar();


    for(i = 1; i <= 10000; i++)

    {

        t = i;

        sum = 0;

        while(t != 0)

        {

            a = t%10;

            sum += a*a*a;

            t = t/10;

        }


        while(sum == i){

        if(c=='D'){

         printf("%d meters, D to Dive, A to Ascend: \n", i);

         return 0;

        }

    }

    }

    return 0;

}

תודה!

פורסם

מה זה עומק ארמסטרונג?

כרגע הקוד שלך נראה מאוד מבולבל ולא ממש ברור לי מה ניסית לעשות. תנסה לתת למשתנים שמות בעלי משמעות, מה  t,a ו-i אמורים לייצג?

חובה גם לאתחל את המשתנים לפני שאתה משתמש בהם, אי אפשר להניח שהם אפס.

 

בכל מקרה כדאי שתכניס את הקוד שלך לתוך תגיות code כי ככה הוא פשוט לא קריא

#include <stdio.h>

int main ()

{
 
    int n,sum,i,t,a;

    printf("Submarine at water level, D to Dive, E to Exit the Program: \n");

    char c= getchar();


    for(i = 1; i <= 10000; i++)

    {

        t = i;

        sum = 0;

        while(t != 0)

        {

            a = t%10;

            sum += a*a*a;

            t = t/10;

        }


        while(sum == i){

        if(c=='D'){

         printf("%d meters, D to Dive, A to Ascend: \n", i);

         return 0;

        }
    }
    }
    return 0;
}

 

ארכיון

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

דיונים חדשים

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.