🔒 Closed Largest digit in an inputted integer problem (C language)

Status
Not open for further replies.

Liikii

Eternal Poster
Pano po to kanina pa ko nag trtry diko parin makuha 😢 Eto po sa pic yung trial code ko..kelangan 5 digit number yung input eh...kelangan po ba gumamit ng %10 tsaka /10? Di ko pa naman alam yun..
Yung output po sa pic is "Middle"



Screenshot_2020-12-13-12-45-26-293_com.android.chrome.jpgIMG_20201213_185214.jpg
 
pa test nalang ts.
[CODE lang="c" highlight="11, 13, 15"]#include <stdio.h>
int higher(int a, int b){
if(a > b) return a;
else return b;
}
int main()
{
int a, b, c, d, e;
printf("Enter Numbers: ");
scanf("%d %d %d %d %d",&a,&b,&c,&d,&e);
if(a > higher(b,c) && a > higher(d,e))
printf("leftmost");
else if(c > higher(a,b) && c > higher(d,e))
printf("middle");
else if(e > higher(a,b) && e > higher(c,d))
printf("rightmost");
else
printf("unknown");
return 0;
}[/CODE]
 
Bakit po ganito di agad lumabas yung output... kelangan ko pa mag input ng 4 more numbers...pano po maayos?
 

Attachments

  • 1607863949441.webp
    1607863949441.webp
    4.2 KB · Views: 15
eto ts without spaces yung input but using array.
C:
#include <stdio.h>
int higher(int a, int b){
    if(a > b) return a;
    else    return b;
}
int main()
{
    int a[5];
    int i, number_of_digits = 5;
    printf("Enter Numbers: ");
    for (i = 0; i < number_of_digits; i++)
        scanf("%1d", &a[i]);
    if(a[0] > higher(a[1],a[2]) && a[0] > higher(a[3],a[4]))
    printf("leftmost");
    else if(a[2] > higher(a[0],a[1]) && a[2] > higher(a[3],a[4]))
    printf("middle");
    else if(a[4] > higher(a[0],a[1]) && a[4] > higher(a[2],a[3]))
    printf("rightmost");
    else
    printf("unknown");
    return 0;
}
 
Status
Not open for further replies.

About this Thread

  • 11
    Replies
  • 474
    Views
  • 4
    Participants
Last reply from:
Arcturus

Online now

Members online
1,017
Guests online
962
Total visitors
1,979

Forum statistics

Threads
2,276,215
Posts
28,968,392
Members
1,231,170
Latest member
nico062026
Back
Top