Jump to content

Realizati Schema Logica Pentru Determinarea Maximului Dintre Trei Numere A,b,c In C


Courage

Recommended Posts

  • Moderators

Rezolvare:

#include <stdio.h>

 #include <conio.h>


 int main ()

 {

 int a,b,c,max;

 printf ("Introduceti cele 3 numere:/n");

 scanf ("%d %d %d",&a,&b,&c);

 if (a>=c) max=a;

 else max=c;

 }

 else

 {

 if (b>=c) max=b;

 else max=c;

 }

 printf("Maximul este:%d",max);

 getch();

 return 0;

 }

sursa: tutorialehd.info

Link to comment
Share on other sites

Codul asta nici nu se va compila. Este bug-uit atat la nivel de sintaxa cat si de logica de determinare a celui mai mare numar.

Functia main se incheie dupa primul else. Tot codul de dupa e ca si inexistent.

Acum sa interpretam logica in limba noastra: daca a este mai mare sau egal cu c, atunci maxim este egal cu a, iar daca nu, maxim egal cu c ?

Pai daca a = c, cum poti sa spui ca a este mai mare ca c sau invers ?

Si cum poti determina care numar este mai mare din 3 introduse, daca tu in program compari tot timpul numai 2 dintre ele ?

Si "new line" este \n, nu /n.

O varianta corecta ar fi:

#include <stdio.h>

#include <conio.h>

int main() {

    int a,b,c,max;

    printf("Introduceti cele 3 numere: ");

    scanf ("%d %d %d",&a,&b,&c);

    if (a>b && a>c)

        max=a;

    else if (b>a && b>c)

        max=b;

    else

        max=c;

    printf("Maximul este: %d",max);

    getch();

    return 0;

}

Nu e treaba mea, dar cineva ar trebui sa ia masuri contra articolelor copiate si netestate sau revizuite de cineva competent. Se inmultesc mizeriile de pe forum si ii scad considerabil calitatea.

  • Upvote 2
Link to comment
Share on other sites

Daca vorbim de "if - then - do - else; do - while; switch - case; alea alea", automat vorbim de logica, fie ea sub forma de schema sau nu.

In cazul de fata, ma refeream la logica defectuoasa implementata in program care, evident, poate fi transformata si in schema daca tii neaparat.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.