1 thích 0 k thích
1.3k đã xem

Please write a simple program that can detect 4 country codes: 886 = Taiwan, 976 = Mongolia, 62 = Indonesia, and 66 = Thailand by using if... else condition. If the code doesn't match any of those four, the program must show No

Example

#include <stdio.h>

int main(int argc, char *argv[]) {

int country_code;
printf("Input your country code:\n");
scanf ("%d", &country_code);

//Your condition starts from here

else 
	printf("No");

    return 0;
}

Example Input 1

Input your country code:

886

Example Output 1

Taiwan

 

Example Input 2

Input your country code:

976

Example Output 2

Mongolia

 

Example Input 3

Input your country code:

62

Example Output 3

Indonesia

 

Example Input 4

Input your country code:

66

Example Output 4

Thailand

 

Example Input 5 (else case)

Input your country code:

696969696969

Example Output 5 (else case)

No

 

Explanation

You might be wondering why your result is wrong even you have the same result, that's because an online judge is strict and sensitive; here some cases:

1. Your result MUST be the same as the fixed output, even dot(.), space( ), printf, misspelling, etc. make the result to be wrong.

2. An online judge works the same as a compiler installed in your computer, you don't need to put anything except the code there.

3. For more information and practice, please visit --> http://www.pipls.net/27431/must-read-an-example-program-for-online-judge

[Exercise] Coding (C) - đã hỏi trong Chapter 3: Branching, Looping and Functions bởi (5.9k điểm)
ID: 28130 - Xem được từ: Không giới hạn - Hiệu lực đến: Không giới hạn

đã sửa bởi | 1.3k đã xem

23 Trả lời

0 thích 0 k thích
Hidden content!
#include ** ***** ** * * *

int main(void)
{
* * *** * ** ** * * *
int country_code;
** *** your country * * * * *****
scanf ** ** ** ** * ** * * * **
* ** * *
 {
* **** * *** ** * ***
 }
 else ******** * ***
* * * **
* ** ****** * * * * ** ** * *
* * ******
* *** * * * ** * ** * * * *
* * ***** ***
*** ** * ** *** ****** **
**** *
******* * * * * ** * **
** **
*** ** *** ** * *** * * * **** **
** *** ** ****
*** ****
else
    * * ***** ***

***** *** * * ** ** *** *** 0;
}
100/100 trả lời bởi (244 điểm)
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Correct output
Case 3: Correct output
0 thích 0 k thích
Hidden content!
* * ** * ***

int ** argc, char {

int * *
** * * your country * ** * ***
scanf * ** * * * * ** * *

* * * starts from here
** ** * * ** **
* ** * ** ** * * * **** * * ****
}
else ***** ** *
* * ** * ** * ** *** * ** ** *** * *
}
else * * * ** *** ***
* ** ** * * * ** **** ** *
}
else *** * * ** * *
** * * * ** ** * * *** *
}
else
* * ** * * * * ******

* * ** * * ** ***** 0;
}
100/100 trả lời bởi (227 điểm)
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Correct output
Case 3: Correct output
0 thích 0 k thích
Hidden content!
* * ** ** * *

int *** argc, char *** * {

int * * * *
* *** * *** your country **** ** *
scanf ** * **** ** * **

*** * *** starts from here
** ** ***
* * * * * ** **** * **
}
else **** *
** ** *** * * * * * *
}
else ****** * **
* ** * * ** * * * **** * ** * *
}
else * ** ** * **
* ** ** ** * * *** ** ** ***
}
else
* * *** ** * * ** * * * *

** * **** **** ** * 0;
}
trả lời bởi (227 điểm)
0 0
Case 0: Wrong output
Case 1: Correct output
Case 2: Correct output
Case 3: Correct output
0 thích 0 k thích
Hidden content!
int main(int argc, char *argv[]) {

int ******
* * * ** your country * *
scanf ***** * * * ** ** * * *
* * ******* * * * **
 {
* **** *** ****** * * * * *
* * **
** * * * ** *** * *
* ****** * ***
** ***** * * * ******* *** * ** *
* *** * ****** ****
* ** * * ** * * * ******
* *** *
** * * ** *** * * * ** * **
* ** *
** *** * *** *** *** **
*** * *** *
** ** *** ** * * * * ** * * *
*
* * * condition starts from here

else
    * **** ** *

***** *** * *** * * ** ** * 0;
}
50/100 trả lời bởi (244 điểm)
0 0
prog.c: In function 'main':
prog.c:4:1: warning: implicit declaration of function 'printf' [-Wimplicit-function-declaration]
 printf("Input your country code:\n");
 ^~~~~~
prog.c:4:1: warning: incompatible implicit declaration of built-in function 'printf'
prog.c:4:1: note: include '<stdio.h>' or provide a declaration of 'printf'
prog.c:5:1: warning: implicit declaration of function 'scanf' [-Wimplicit-function-declaration]
 scanf ("%d", &country_code);
 ^~~~~
prog.c:5:1: warning: incompatible implicit declaration of built-in function 'scanf'
prog.c:5:1: note: include '<stdio.h>' or provide a declaration of 'scanf'
0 0
#include <stdio.h> is missing
0 thích 0 k thích
Hidden content!
* * * * *** *

int *** argc, char * * * {

int * * **
* *** *** * *** your * * * ** *
scanf ** **** * * ** ******

if ** * == 886)

***** ***** ***** * * * **** ** *** *

else if * * == 976)

* ** * ** ** * * * *** ** * ** *
else if * * * *** == 62)
*** * * * ** * ** *** * * ** *** *

else if ** * * == 66)

* * * ** ***** **** ****** ** * ** * ** * * ***

else
* * * * * * **** **** * * **

* * **** * * 0;
}
* * End
* * a ** * *
100/100 trả lời bởi (183 điểm)
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Correct output
Case 3: Correct output
0 thích 0 k thích
Hidden content!
** * **** ** * ** *

int * argc, char ** *** {

int * ****
* * *** ** your *** ** ** **
** * **** ** **** * * * *

if **** ** * == 886)

*** ** ** * ** * * *** **** *** * **

else if ** * *** == 976)

** ******** ** * * *** **** * *** * **

else if *** *** * == 66)

***** * ** * ** * * ** * *** * * **** * *

else
* * * * * * * * ** * * **

* *** * **** **** * ** ** 0;
}
* ** * End
** a * ***
trả lời bởi (183 điểm)
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Wrong output
Case 3: Correct output
0 thích 0 k thích
Hidden content!
#include <stdio.h>
#include ** ** * * * ***

/* run this program using the console pauser or add your own getch, * **** **** ***** or input loop */

int main(int argc, char *argv[]) {
** *** ******* ** ** n;
*** *** ** *** *** * ** * * * ** * the what is your country?: ");
* *** * *** * ** **
** * *** ** * * * * ** * ****** &n);
** ** ** ** * **
**** * ** ** * * ** n ==886)
* ** ** ** * ***** * ** * * ***** * ** * * * * * * *
* **** * ** * *** *** ** ** if( n == 976 )
* *** * ** ** *** **** ** ** ** ** **** * * * * ** ** ****
* **** * * * * ** if( n == 66 )
** *** * * * ** ** *** * * * * * **** * * ** ***** ** *** * * *
* ** ** * *** *** * ** * * if( n == 62 )
* * * *** * ** ** **** ** * *** * ** *** * ** ** *****
**** *** * *** * * **
* **** *** *** * ** **** ** *** * *** ****** * ** **** **
* * * *** * ****
* ** * * *** * ** * *
**** * * * **** 0;
}
100/100 trả lời
0 0
Case 0: Wrong output
Case 1: Wrong output
Case 2: Wrong output
Case 3: Wrong output
0 thích 0 k thích
Hidden content!
#include <stdio.h>
#include <stdlib.h>

int main(int argc, char *argv[]) {
*** * * * *** ** ***** *** a;
***** * ** ***** ****
*** * *** ** ** * *** * *** a country code:");
* * * **** *
* * ********* * * ** * * ** * &a);
    
** * * * ** * **** * == 886)
*** ***** ** * ** * * * * *** *** ** ** * ** * * ** **
* * * * * ** * * ** * if(a == 976)
*** ** * * ***** *** **** ** * * * **** * * ** ** * *** * **
**** *** ** **** ** **** if(a == 62)
* ***** ** * ** * * * ** *** *** ** *** * * * * * ***** ** * * * * **
* * * ** ** ** * * * * if(a == 66)
* * ** * *** ** ** ** ** ** ** ** * ** * * ******
* * **** ****** *** * ** *****
* *** * ** **** ** *** * * * **** * ***** **** ******
* * *** *** * ****
**** *** *** ** *** *** *** 0;
}
100/100 trả lời bởi (243 điểm)
0 0
Case 0: Wrong output
Case 1: Wrong output
Case 2: Wrong output
Case 3: Wrong output
0 thích 0 k thích
Hidden content!
* ** * * *

int * * * * * char * * {

int * ** *
*** ** * * your * ** * ** ***
* * * *** * * * * ** * * ** ***

*** ** * * ** * from here
** *** * == 886)
* *** * *** *
*** ** * ** == 976)
*** * ** ** *********
else * ** * * == 62)
*** * *** ***
else * * ** == 66)
**** * * * * * * * *
else
** ** ** ** * * ** *

*** *** * ** **** *** ** * 0;
}
100/100 trả lời bởi (220 điểm)
đã sửa bởi
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Wrong output
Case 3: Correct output
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Wrong output
Case 3: Correct output
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Wrong output
Case 3: Correct output
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Correct output
Case 3: Correct output
0 thích 0 k thích
Hidden content!
* * * * *** * * *** *

int * * * argc, char * ** * {

int * * *
*** * * * your * ** ** *
** * ** ** ** * * * ** *** *

* ** **** **** from here
* * == 976)
** ** *** ***** ** *** * *
else * ** ** == 886)
* * * ** * **
else ** == 62)
* **** * ** **** *
* * * * ** == 66)
* * ** * *** *** * * *
* ***** == 355)
* * * *** * ** * * **
else
** ** ** ** *** * *** ** *

** * ** ***** * * ** 0;
}
trả lời
đã sửa bởi
0 0
Case 0: Wrong output
Case 1: Correct output
Case 2: Wrong output
Case 3: Wrong output
0 0
You almost got it. Please add more if conditions for other countries as well :)
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Wrong output
Case 3: Correct output
0 0
prog.c: In function 'main':
prog.c:23:2: error: expected declaration or statement at end of input
  printf("No");
  ^~~~~~
0 0
prog.c: In function 'main':
prog.c:23:2: error: expected declaration or statement at end of input
  printf("No");
  ^~~~~~
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Wrong output
Case 3: Correct output
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Wrong output
Case 3: Correct output
Welcome to Peer-Interaction Programming Learning System (PIPLS) LTLab, National DongHwa University
English 中文 Tiếng Việt
IP:172.69.58.104
©2016-2024

Những câu hỏi liên quan

0 thích 0 k thích
24 trả lời
[Exercise] Coding (C) - đã hỏi ngày 2 tháng 11 năm 2017 trong Chapter 3: Branching, Looping and Functions bởi nat236919 (5.9k điểm)
ID: 30241 - Xem được từ: Không giới hạn - Hiệu lực đến: Không giới hạn
| 937 đã xem
0 thích 0 k thích
17 trả lời
[Exercise] Coding (C) - đã hỏi ngày 27 tháng 10 năm 2017 trong Chapter 3: Branching, Looping and Functions bởi nat236919 (5.9k điểm)
ID: 29618 - Xem được từ: Không giới hạn - Hiệu lực đến: Không giới hạn
| 867 đã xem
0 thích 0 k thích
14 trả lời
[Exercise] Essay (Open question) - đã hỏi ngày 2 tháng 11 năm 2017 trong Chapter 3: Branching, Looping and Functions bởi nat236919 (5.9k điểm)
ID: 30244 - Xem được từ: Không giới hạn - Hiệu lực đến: Không giới hạn
| 474 đã xem
0 thích 0 k thích
20 trả lời
[Exercise] Coding (C) - đã hỏi ngày 2 tháng 11 năm 2017 trong Chapter 3: Branching, Looping and Functions bởi nat236919 (5.9k điểm)
ID: 30222 - Xem được từ: Không giới hạn - Hiệu lực đến: Không giới hạn
| 867 đã xem
12,783 câu hỏi
183,443 trả lời
172,219 bình luận
4,824 thành viên