• Downloads
  • ! Read Me !
  • Μαθήματα
  • Φοιτητικά
  • Τεχνικά Θέματα
  • Συζητήσεις
  • Happy Hour!
  • About THMMY.gr
 V  < 
Search:  
Welcome, Guest. Please login or register.
June 16, 2025, 14:07:51 pm

Login with username, password and session length
Links
  Thmmy.gr portal
   Forum
   Downloads
   Ενεργ. Λογαριασμού
   Επικοινωνία
  
  Χρήσιμα links
   Σελίδα τμήματος
   Βιβλιοθήκη Τμήματος
   Elearning
   Φοιτητικά fora
   Πρόγραμμα Λέσχης
   Πρακτική Άσκηση
   Ηλεκτρονική Εξυπηρέτηση Φοιτητών
   Διανομή Συγγραμμάτων
   Ψηφιακό Καταθετήριο Διπλωματικών
   Πληροφορίες Καθηγητών
   Instagram @thmmy.gr
   mTHMMY
  
  Φοιτητικές Ομάδες
   ACM
   Aristurtle
   ART
   ASAT
   BEAM
   BEST Thessaloniki
   EESTEC LC Thessaloniki
   EΜΒ Auth
   IAESTE Thessaloniki
   IEEE φοιτητικό παράρτημα ΑΠΘ
   SpaceDot
   VROOM
   Panther
  
Πίνακας Ελέγχου
Welcome, Guest. Please login or register.
June 16, 2025, 14:07:51 pm

Login with username, password and session length

Αναζήτηση

Google

THMMY.gr Web
Πρόσφατα
[Αρχές Οικονομίας] Να επι...
by _Trob
[Today at 13:28:21]

[Σ.Α.Π.Γ.] Εργασία 2025
by Nikos_313
[Today at 12:13:45]

Αποτελέσματα Εξεταστικής ...
by Nikos_313
[Today at 12:01:53]

Πρακτική Άσκηση ΤΗΜΜΥ 201...
by George_RT
[Today at 10:22:18]

[Διανεμημένη Παραγωγή] Γε...
by Διάλεξις
[Today at 01:56:37]

[Σ.Π.Η.Ε.] Γενικές απορίε...
by nmpampal
[Today at 00:16:23]

Ισραήλ - Ιράν: Πόλεμος στ...
by Katarameno
[June 15, 2025, 20:08:49 pm]

Αντικατάστασης πυκνωτή σε...
by nmpampal
[June 15, 2025, 16:25:56 pm]

[Σ.Π.Η.Ε.] Παλιά θέματα -...
by nmpampal
[June 15, 2025, 06:43:15 am]

Το thmmy.gr στο instagram...
by Mr Watson
[June 15, 2025, 00:50:23 am]

[Λογισμός ΙΙ] Απορίες σε...
by el mariachi
[June 14, 2025, 20:47:07 pm]

ΠΡΟΣΟΧΗ στο ανέβασμα θεμά...
by tzortzis
[June 14, 2025, 16:54:08 pm]

Ρυθμίσεις Θεμάτων της Ανώ...
by el mariachi
[June 14, 2025, 11:56:45 am]

Πότε θα βγει το μάθημα; -...
by Nikos_313
[June 14, 2025, 10:00:55 am]

Αρχείο Ανακοινώσεων [Arch...
by Nikos_313
[June 14, 2025, 09:58:14 am]

Αλέξης Τσίπρας, η επιστρο...
by Yamal
[June 14, 2025, 04:42:23 am]

Έναρξη Δηλώσεων Συμμετοχή...
by IEEE SB
[June 14, 2025, 00:10:19 am]

[Δυναμική Συμπεριφορά ΣΗΕ...
by soko_freta
[June 13, 2025, 01:05:36 am]

[Εφ.Θερμοδυναμική]Παλιά θ...
by Giannis Masterio
[June 12, 2025, 22:30:38 pm]

Paid Internships in a Eur...
by okan
[June 12, 2025, 22:30:02 pm]
Στατιστικά
Members
Total Members: 9959
Latest: valco08
Stats
Total Posts: 1426669
Total Topics: 31711
Online Today: 201
Online Ever: 2093
(April 17, 2025, 08:47:49 am)
Users Online
Users: 56
Guests: 125
Total: 181
JoHn!
georsoti
mpournaz
kraxtopoulos
glavdakis
ioannisdamantis
Nikos_313
billaraspap7
george14
valentini
gkg
ggalamat
johncow
zille
ddantono
genethalsss74
ioannisfa
gp6
iliaspapam
jh13
mariaxalk
manolitsis
Domnious
EiriniGeo
et7gr
kouf
faidonchatz
anna.ts
cpapadd
mikrosdia
vasilis saitis
nikolakys
Antigoni
vaggelisx
Antreas17
Vasilis Koudounis
Konstantinoy
George_RT
DimStyl
adamchatz
AcDimitri
tinidou
chatzisot
apapathe
Mr Watson
panagiwt1s
mmikelo
trelogauros7
Dimosthenis
geo66
Bill g
theodorevic
Εμφάνιση

Νέα για πρωτοετείς
Είσαι πρωτοετής;... Καλώς ήρθες! Μπορείς να βρεις πληροφορίες εδώ. Βοήθεια για τους καινούργιους μέσω χάρτη.
Κατεβάστε εδώ το Android Application για εύκολη πρόσβαση στο forum.
Ανεβάζετε τα θέματα των εξετάσεων στον τομέα Downloads με προσοχή στα ονόματα των αρχείων!

Νέα!
Επίσημη ενημέρωση για Αντιστοίχηση Μαθημάτων ΝΠΣ με ΠΠΣ και η συζήτηση στο forum.
THMMY.gr > Forum > Μαθήματα Βασικού Κύκλου > 1ο Εξάμηνο > Δομημένος Προγραμματισμός (Moderators: Tasos Bot, tzortzis, Nekt) > [Δομημένος Προγραμματισμός] Απορια στην χρηση της if
0 Members and 1 Guest are viewing this topic.
Pages: [1] Go Down Print
Author Topic: [Δομημένος Προγραμματισμός] Απορια στην χρηση της if  (Read 1587 times)
leukosaraphs!
Veteran
Καταστραμμένος
******
Gender: Male
Posts: 9596


εφακ


View Profile
[Δομημένος Προγραμματισμός] Απορια στην χρηση της if
« on: April 01, 2016, 13:56:24 pm »

Παιδες προσπαθω να γραψω ενα προγραμμα (ασκηση εργαστηριου ειναι απλα δν προλαβα να τν κανω εκει) και πρεπει να χρησιμοποιησω την "if" .
Code:
#include <stdio.h>
int main()
{
    int x1,x2; //x1: wra enar3hs, x2:wra lh3hs
    scanf("%d",&x1);
    scanf("%d",&x2);
    int c;
    int d;
    c=x1%100; //c:to ypoloipo ths akeraias diaireshs tou me to 100
    d=x2%100; //d:to ypoloipo ths akeraias diaireshs tou me to 100
    if(d-c>0){
        double x=(d-c)*0.2;
        double poso=x+0.6;
        printf("%lf\n",poso);
    } else {
        double x=((d+60)-c)*0.2;
        double poso=x+0.6;
        printf("%lf\n",poso);
    }
    return 0;

}

Οπως βλεπετε κι στο στελεχος της if και της else υπαρχουν δυο εντολες
Code:
ouble poso=x+0.6;
        printf("%lf\n",poso);
οι οποιες γινεται να χρησιμοποιηθουν μια φορα εξω απο τν if , απλα για καποιο λογο οταν το κανω δεν "μεταφερει" την τιμη που της εχεις δοθει

edit: tag
« Last Edit: April 01, 2016, 14:00:40 pm by Vlassis » Logged


-What  do you get  when you cross  an insomniac, an agnostic and a dyslexic?
-Someone who stays up all night wondering if there is a Dog.

You can't spell fart without art

Quote from: Xplicit on June 17, 2018, 20:03:39 pm
Συνεχίστηκε η παράδοση που θέλει τους Γερμανούς να φεύγουν ηττημένοι από τη Μόσχα  Grin
nvog1993
Θαμώνας
****
Posts: 459


View Profile
Re: [Δομημένος Προγραμματισμός] Απορια στην χρηση της if
« Reply #1 on: April 01, 2016, 14:01:18 pm »

Τι εννοείς εξωτερικά της if? Πως αλλάζεις ακριβώς τον κώδικα?
Logged
Escobar
Veteran
Αbsolute ΤΗΜΜΥ.gr
******
Posts: 2821



View Profile
Re: Απορια στην χρηση της if
« Reply #2 on: April 01, 2016, 14:01:42 pm »

Quote from: leukosaraphs! on April 01, 2016, 13:56:24 pm

Οτιδήποτε δηλώνεις στο εσωτερικό ενός μπλοκ έχει τοπική ισχύ, δηλαδή δε φαίνεται στο εξωτερικό του μπλοκ.
Logged

"Yesterday is History-Today is a Gift-Tommorow is a Mystery"

Vlassis
Veteran
Μόνιμος κάτοικος ΤΗΜΜΥ.gr
******
Posts: 2162


εφακ


View Profile
Re: [Δομημένος Προγραμματισμός] Απορια στην χρηση της if
« Reply #3 on: April 01, 2016, 14:02:18 pm »

την μεταβλητη poso την δηλωνεις μεσα στα  { } της if και else αντιστοιχα. αυτη ειναι και η εμβελεια της. καλο ειναι να την δηλωσεις εξω απο την if, και μετα να την χρησιμοποιεις..
Logged

πρόπελ
Is any of it real? I mean, look at this. Look at it! A world built on fantasy! Synthetic emotions in the form of pills, psychological warfare in the form of advertising, mind-altering chemicals in the form of food, brainwashing seminars in the form of media, controlled isolated bubbles in the form of social networks. mr.robot s01e10
leukosaraphs!
Veteran
Καταστραμμένος
******
Gender: Male
Posts: 9596


εφακ


View Profile
Re: [Δομημένος Προγραμματισμός] Απορια στην χρηση της if
« Reply #4 on: April 01, 2016, 14:10:13 pm »

Ξερω οτι πρεπει να την δηλωσω κι εξω απο την if  την μεταβλητη poso και την μεταβλητη x, κατι που δοκιμασα κιολας αλλα μολις το ετρεξα μου βγαζε αποτελεσμα μονο 0 , υπεθεσα οτι απλα δν περαστηκε η τιμη που της δοθηκε μεσα στην if .Κι ρωτησα αν υπαρχει τροπος να την περασω

Quote
Οτιδήποτε δηλώνεις στο εσωτερικό ενός μπλοκ έχει τοπική ισχύ, δηλαδή δε φαίνεται στο εξωτερικό του μπλοκ.
Δηλαδη μονο ετσι γινεται να εμφανισω αυτο που θελω? Μεσα στην if?

Quote
Τι εννοείς εξωτερικά της if? Πως αλλάζεις ακριβώς τον κώδικα?
Απλα μου φανηκε χαζο να γραφω πολλες φορες τις ιδιες γραμμες κωδικα..Το αλλαζει ετσι :
Code:
#include <stdio.h>
int main()
{
    int x1,x2; //x1: wra enar3hs, x2:wra lh3hs
    scanf("%d",&x1);
    scanf("%d",&x2);
    int c;
    int d;
    c=x1%100; //c:to ypoloipo ths akeraias diaireshs tou me to 100
    d=x2%100; //d:to ypoloipo ths akeraias diaireshs tou me to 100
    if(d-c>0)
    {
        double x=(d-c)*0.2;

    }
    else
    {
        double x=((d+60)-c)*0.2;

    }
    double x,poso;
    poso=x+0.6;
    return 0;

}
Logged


-What  do you get  when you cross  an insomniac, an agnostic and a dyslexic?
-Someone who stays up all night wondering if there is a Dog.

You can't spell fart without art

Quote from: Xplicit on June 17, 2018, 20:03:39 pm
Συνεχίστηκε η παράδοση που θέλει τους Γερμανούς να φεύγουν ηττημένοι από τη Μόσχα  Grin
Vlassis
Veteran
Μόνιμος κάτοικος ΤΗΜΜΥ.gr
******
Posts: 2162


εφακ


View Profile
Re: [Δομημένος Προγραμματισμός] Απορια στην χρηση της if
« Reply #5 on: April 01, 2016, 14:15:10 pm »

Quote from: leukosaraphs! on April 01, 2016, 13:56:24 pm
Code:
int main()
{
    int x1,x2; //x1: wra enar3hs, x2:wra lh3hs
    scanf("%d",&x1);
    scanf("%d",&x2);
    int c;
    int d;
    c=x1%100; //c:to ypoloipo ths akeraias diaireshs tou me to 100
    d=x2%100; //d:to ypoloipo ths akeraias diaireshs tou me to 100
   double poso=0;
   double x=0;
    if(d-c>0){
        x=(d-c)*0.2;
        poso=x+0.6;
        printf("%lf\n",poso);
    } else {
        x=((d+60)-c)*0.2;
        poso=x+0.6;
        printf("%lf\n",poso);
    }
    return 0;

}
για δοκιμασε ετσι.
« Last Edit: April 01, 2016, 14:26:26 pm by Vlassis » Logged

πρόπελ
Is any of it real? I mean, look at this. Look at it! A world built on fantasy! Synthetic emotions in the form of pills, psychological warfare in the form of advertising, mind-altering chemicals in the form of food, brainwashing seminars in the form of media, controlled isolated bubbles in the form of social networks. mr.robot s01e10
leukosaraphs!
Veteran
Καταστραμμένος
******
Gender: Male
Posts: 9596


εφακ


View Profile
Re: [Δομημένος Προγραμματισμός] Απορια στην χρηση της if
« Reply #6 on: April 01, 2016, 14:20:53 pm »

Απλα αρχικοποιησες τις τιμες των x,poso?
Συμφωνω οτι τρεχει , απλα χρησιμοποιησεις printf μεσα στην if και else ,κατι που θελω να αποφυγω(αν γινεται)
Logged


-What  do you get  when you cross  an insomniac, an agnostic and a dyslexic?
-Someone who stays up all night wondering if there is a Dog.

You can't spell fart without art

Quote from: Xplicit on June 17, 2018, 20:03:39 pm
Συνεχίστηκε η παράδοση που θέλει τους Γερμανούς να φεύγουν ηττημένοι από τη Μόσχα  Grin
Vlassis
Veteran
Μόνιμος κάτοικος ΤΗΜΜΥ.gr
******
Posts: 2162


εφακ


View Profile
Re: [Δομημένος Προγραμματισμός] Απορια στην χρηση της if
« Reply #7 on: April 01, 2016, 14:25:41 pm »

Quote from: leukosaraphs! on April 01, 2016, 14:20:53 pm
Απλα αρχικοποιησες τις τιμες των x,poso?
Συμφωνω οτι τρεχει , απλα χρησιμοποιησεις printf μεσα στην if και else ,κατι που θελω να αποφυγω(αν γινεται)
τις δηλωνεις κυριως και τις αρχικοποιεις εξω απο την if.
α για αυτο απλα βαλε, το printf("%lf\n",poso); ακριβως μια εντολη πριν το return, εξω απο το if
Logged

πρόπελ
Is any of it real? I mean, look at this. Look at it! A world built on fantasy! Synthetic emotions in the form of pills, psychological warfare in the form of advertising, mind-altering chemicals in the form of food, brainwashing seminars in the form of media, controlled isolated bubbles in the form of social networks. mr.robot s01e10
leukosaraphs!
Veteran
Καταστραμμένος
******
Gender: Male
Posts: 9596


εφακ


View Profile
Re: [Δομημένος Προγραμματισμός] Απορια στην χρηση της if
« Reply #8 on: April 01, 2016, 14:29:04 pm »

Α ωραιος τωρα ετρεξε, λογικα με τις αρχικοποιησεις εκανα βλακεια

Ευχαριστωωωωω
Logged


-What  do you get  when you cross  an insomniac, an agnostic and a dyslexic?
-Someone who stays up all night wondering if there is a Dog.

You can't spell fart without art

Quote from: Xplicit on June 17, 2018, 20:03:39 pm
Συνεχίστηκε η παράδοση που θέλει τους Γερμανούς να φεύγουν ηττημένοι από τη Μόσχα  Grin
Vlassis
Veteran
Μόνιμος κάτοικος ΤΗΜΜΥ.gr
******
Posts: 2162


εφακ


View Profile
Re: [Δομημένος Προγραμματισμός] Απορια στην χρηση της if
« Reply #9 on: April 01, 2016, 14:30:40 pm »

απλα εσυ καθε φορα που εγραφες double poso; , η μεταβλητη poso εχανε την προηγουμενη τιμη της και δεν ειχε καμια σχεση με την μεταβλητη που εσυ ορισες πριν, εξω απο το μπλοκ που ησουν ..
 Wink
Logged

πρόπελ
Is any of it real? I mean, look at this. Look at it! A world built on fantasy! Synthetic emotions in the form of pills, psychological warfare in the form of advertising, mind-altering chemicals in the form of food, brainwashing seminars in the form of media, controlled isolated bubbles in the form of social networks. mr.robot s01e10
Andromedas
Εθισμένος στο ΤΗΜΜΥ.gr
*****
Posts: 504



View Profile
Re: [Δομημένος Προγραμματισμός] Απορια στην χρηση της if
« Reply #10 on: April 01, 2016, 14:36:22 pm »

Quote from: leukosaraphs! on April 01, 2016, 14:10:13 pm
Code:
#include <stdio.h>
int main()
{
    int x1,x2; //x1: wra enar3hs, x2:wra lh3hs
    scanf("%d",&x1);
    scanf("%d",&x2);
    int c;
    int d;
    c=x1%100; //c:to ypoloipo ths akeraias diaireshs tou me to 100
    d=x2%100; //d:to ypoloipo ths akeraias diaireshs tou me to 100
    if(d-c>0)
    {
        [u]double x=(d-c)*0.2;[/u]

    }
    else
    {
       [u] double x=((d+60)-c)*0.2;[/u]

    }
    [u]double x[/u],poso;
    poso=x+0.6;
    return 0;

}

Πρακτικα κανεις δηλωση δυο διαφορετικων pointer ετσι ενα μεσα στο bracket της if και ενα στο bracket της main οποτε χανετε οταν βγαινει εξω η τιμη. Σωστο ειναι η δηλωση Xcorrect
Code:
#include <stdio.h>
int main()
{
    int x1,x2; //x1: wra enar3hs, x2:wra lh3hs
    printf("Give x1 \n");
    scanf("%d",&x1);
    printf("Give x2 \n");
    scanf("%d",&x2);
    int c;
    int d;
    c=x1%100; //c:to ypoloipo ths akeraias diaireshs tou me to 100
    d=x2%100; //d:to ypoloipo ths akeraias diaireshs tou me to 100
   
    double Xcorrect=0;
   
    if(d-c>0)
    { Xcorrect=(d-c)*0.2;
        double x=(d-c)*0.2;
        printf("INSide x= %f \n",(float)x);

    }
    else
    { Xcorrect=((d+60)-c)*0.2;
        double x=((d+60)-c)*0.2;
         printf("INSide x= %f \n",(float)x);

    }
    double x,poso=0.6;
    poso=x+poso;
    printf("Outside x= %f poso=%f\n",(float)x,(float)poso);
  poso=Xcorrect+poso;
printf("Xcorrect=%f poso=%f",(float)Xcorrect,(float)poso);
   
    return 0;

}
Logged
Apostolof
WebSlave
Αbsolute ΤΗΜΜΥ.gr
***
Gender: Male
Posts: 2660


Κεραυνοί, φωτιές, ece


View Profile WWW
Re: [Δομημένος Προγραμματισμός] Απορια στην χρηση της if
« Reply #11 on: April 01, 2016, 14:36:29 pm »

Quote from: leukosaraphs! on April 01, 2016, 14:10:13 pm
Code:
int main()
{
    ...
    if(d-c>0)
    {
        double x=(d-c)*0.2;

    }
    else
    {
        double x=((d+60)-c)*0.2;

    }
    double x,poso;
    poso=x+0.6;
    ...

Εδώ δηλώνεις ένα double x μέσα στην if, αυτό αποθηκεύεται σε μία θέση μνήμης. Όταν βγαίνει από την if δεν υπάρχει πια x!
Ύστερα δηλώνεις ξανά ένα double x μέσα στην else. Αυτό είναι άλλο x! Θα μπει σε άλλη θέση μνήμης! Βγαίνεις από την else και πάλι δεν υπάρχει x.
Τέλος πας κάτω από την else και δηλώνεις ένα τελευταίο double x. Αυτό θα πάει σε μία τυχαία θέση μνήμης που είναι διαθέσιμη. Αυτή η θέση έχει μέσα σκουπίδια από προηγούμενη χρήση. Πας και κάνεις poso=x+0.6; το οποίο στην ουσία θα προσθέσει 0.6 στα σκουπίδια. Αυτό που θες να κάνεις γίνεται έτσι:

Code:
#include <stdio.h>
int main()
{
    int x1,x2,c,d; //x1: wra enar3hs, x2:wra lh3hs
    double x,poso;

    scanf("%d",&x1);
    scanf("%d",&x2);

    c=x1%100; //c:to ypoloipo ths akeraias diaireshs tou me to 100
    d=x2%100; //d:to ypoloipo ths akeraias diaireshs tou me to 100
    if(d-c>0)
    {
        x=(d-c)*0.2;
    }
    else
    {
        x=((d+60)-c)*0.2;
    }
    poso=x+0.6;
    return 0;

}
Logged

All these moments will be lost in time, like tears in rain.
In the meanwhile, life goal.
leukosaraphs!
Veteran
Καταστραμμένος
******
Gender: Male
Posts: 9596


εφακ


View Profile
Re: [Δομημένος Προγραμματισμός] Απορια στην χρηση της if
« Reply #12 on: April 01, 2016, 15:53:34 pm »

Καταλαβα τι μ@..κια εκανα  Sad Sad τεσπα τον παρατησα αυτον τον τροπο λυσης , ηταν πιο περιπλοκος απο οτι υπολογιζα
Logged


-What  do you get  when you cross  an insomniac, an agnostic and a dyslexic?
-Someone who stays up all night wondering if there is a Dog.

You can't spell fart without art

Quote from: Xplicit on June 17, 2018, 20:03:39 pm
Συνεχίστηκε η παράδοση που θέλει τους Γερμανούς να φεύγουν ηττημένοι από τη Μόσχα  Grin
Pages: [1] Go Up Print
Jump to:  

Powered by SMF | SMF © 2006-2009, Simple Machines LLC
Scribbles2 | TinyPortal © Bloc | XHTML | CSS
Loading...