This forum is now read-only. Please use our new forums! Go to forums

banner
Close banner
0 points
Submitted by Nefi Garcia
over 9 years

language c

in my language c class i tried to do the next two problems;

  1. Get three numbers by the user and print the bigger one.
  2. Get three numbers by the user and print the bigger number, medium and the smaller.

i tried this buy didn’t word y dev program

#include <stdio.h>
#include <conio.h>
int main(){
    int a,b,c;
    printf("ingresa primer valor");
    scanf("%f", &a);
    printf("segundo valor");
    scanf("%f", &b);
    printf("tercer valor");
    scanf("%f", &c);
    if (a>b && a>c){
        printf("este es el mayor: %f", a);
    }
        
       	if(b>a && b>c){
        printf("mayor is:%f", b);
    }
        d

    if (c>a && c>b){
    
        printf("mayor is:%f", c);
}
    return 0;
    }

Edit: made code look like code by haxor789

Answer 540d68528c1ccc061e00ae1e

0 votes

Permalink

a,b and c are int so the corrsponding format string would be %d or %i not %f: http://en.wikipedia.org/wiki/Printf_format_string#Type

Algorithm to get the biggest number. Take two of the numbers e.g. a and b compare them and compare the bigger one to the last. The bigger one of the second comparision is the biggest: e.g.

int max = a;
if(b > a)
   max = b;
//else stays the same so not needed.

if(max < c)
   max = c;
//else stays the same so not needed.
printf("mayor is:%i",max);

And for the second task you just need to compare the remaining two numbers.

points
Submitted by haxor789
over 9 years