0 like 0 dislike
17.7k views

Write a program that get the input of two integers n and m(n < m). Find out all prime numbers between n and m (not include n and m), then display them on the screen.

寫一個程式 輸入兩個整數n和m (n < m),找出所有n到m之間的質數(不包含n和m)。

Example input 1

1 10

Example output 1

2 3 5 7

 

Example input 2

10 20

Example output 2

11 13 17 19

 

[Exercise] Coding (C) - asked in Chapter 6: Loops by (5.2k points)
ID: 29829 - Available when: 2017-11-02 18:00 - Due to: Unlimited

edited by | 17.7k views

99 Answers

0 like 0 dislike
Hidden content!
* * * * * **
* * ** **
** * * * **** **

int main()
{
int *** * * *
* ** **** * *** * **** *
**** * * ** * *** *** ****
n=o;

* * * ***** *
{
***** * ** ** *****
{
* *
** *
}
**** * * *** * *

else{

}}



* * ** * ****
{
**** **** * ** ** *
{
** **
**
}
****** * * *
else{

if **** **
{
* ** ** ** ** * * *** **** * ** ** * *** *
***
}else **
* * ** ** ** **** **** *

}
}


** 0;
}
answered by (-336 points)
0 0
Case 0: Wrong output
Case 1: Wrong output
Case 2: Wrong output
Case 3: Correct output
0 like 0 dislike
Hidden content!
#include<stdio.h>
int main(void)
{
    int a,cpt,n,m,i,b;
   a=0;b=0;
*** **** * ** ** ******* * ** ***** * ** ** *
    do
    {
* * * *** *** * **** ** * *** * *** ** ** ** *** * * *** *** **
    }while(m<n);
    for (i=n+1;i<=m-1;i++)
    {
****** ** * ** * *** * **** ** ** * * * ** **** (cpt=2;cpt<=i;cpt++)
        {
* ** *** ***** ** ** ** * ** ** ** * * * ** **** * ***** * * * * (i%cpt==0)
** * ** ** ****** **** ** ** * ** ** * * * * * * * ***
**** ** * ** **** * * **** * ** * * *** ********* *** * * ** ** * * * * * *
* * ** * *** * ** * * * ** * * ** *** *** * ** *** * ** * * *
** ***** * *** ** **** * ***** * ** ** ******* *** **
** * ** *** * * ** * ** ** * ** *** *** **** * **** * * ** ** *
** ***** * * * ** ***** * *** ** * * * * * (a==1)
* * ** * ** **** ** ** ***** * * *** * ** *** *** * * *

** * * * ** * **** * **** * **** * * * *** * * ** * * ** ****** ** * ** *** * * * ** * ** ** * **** (b==0)
* ***** ** * * *** ** * * * * * **** **** * *** ** * ** * **** *** *
* ** *** * * * * * * **** *** * * ** * ** ** * *** * ** ** * * * * *** * * * ** * * * ** ** ** *
*** **** * ** ** * * ** **** *** * * *** ** ***** ** ** * * * *
* ** ** ** * *** * ** * * * ****** ****** * * *** **** * * ** * * *** * *****
* *** * ** * * * *** * *** * ****** * * ** ** * * ** ******* * ** *
** ********* ** * * * ** * * ** ** *** * ** ***** ***** ** *** *** ** *** * * * ** * *** *** ** %d",i);
** *** ** ****** ** * * * *** *** *** * ** ** *** *** ** * ** * *
**** ** ** ** * * * *** ***** **** *** * * **** ***** ** * ** *** * *** ** * * *** * *
** * * * * **** ** ** ** * *** ** * **** * ** ** *** * * ******
****** * ** *** **** * * * *** * **** ** * * *** ** *** *** * * **
    }
    return 0;
}
answered by (-168 points)
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Correct output
Case 3: Correct output
0 like 0 dislike
Hidden content!
** * * * ** **
*** * ** * * * * **
* ***** * **** *

int main()
{
int * ** *
* ** ** * * *
* ***** ** **** **
n=o;

*** ** **** *
{
* * **** * ** ** ***
{
* * *
*
}
* ***** *

else{
**
}}



** * ** * * **
{
** * * *** * *
{
* *
***
}
* ** * * * ** *
else{

if *******
{
*** *** ** ******* * *** * **** * ** * * *
** *
}else
* *** * ** * * ***

}
}


* 0;
}
answered by (-336 points)
0 0
Case 0: Wrong output
Case 1: Wrong output
Case 2: Wrong output
Case 3: Wrong output
0 like 0 dislike
Hidden content!
*** * * *
*** **** * * *
** *** * ** **

int main()
{
int * * ***
* ** * ** * * * * **
* ***** ** * * * *
n=o;

* * * ** * **
{
** ***** * ** * * *
{
**
**
}
* * *** * *

else{
******
}}



* *** * ***
{
* **** ****** *
{
** * **
*
}
* * * *
else{

if * ** *
{
* ** **** *** ** **** * ** ** ** *
q+=1;
}else
* * * * ******** * *

}}
answered by (-336 points)
0 0
prog.c: In function 'main':
prog.c:44:1: error: expected declaration or statement at end of input
 }}
 ^
0 like 0 dislike
Hidden content!
#include <stdio.h>

int main(void)


{
int num1, num2,x,y,flag;
int a[0];

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

* ** *** ** (y=num1+1; y<num2; ++y)
  {
*** ** * * * * **** ** * * *
* * *** ***** * *** ** ** * x<=y/2; ++x)
* * * **** *** ** * * * * * * *** ** **
**** * *** *** * * * * **** *** ****** * * * *** *
* ** *** * * *** ** * * **** * *** * * *
*** * ** *** * * * *** * * * *** * * ****** * * **
** * ** ***** * * ***** * * * * * * *** * * *
* * * *** * **** ******* **** * * * ***
** *** **** * ** *** ** *** * ** * *
** ** * * ** *** * * ** * *****
**** ** * **** * ** * * ** * * * * * * ** ",y,a[0]);
  }


** * * ** * ** * *** 0;


}
answered by (-107 points)
0 0
prog.c: In function 'main':
prog.c:24:13: warning: too many arguments for format [-Wformat-extra-args]
      printf("%1d ",y,a[0]);
             ^~~~~~
0 like 0 dislike
Hidden content!
#include<stdio.h>
int main(void)
{
** * ** * * * ** a,cpt,n,m,i;
   a=0;
** * * ** * * ** * ** ****** * *** * * *
    do
    {
** ** * * ** ** *** * * * **** * * * * ***** * ** **** * ** * **
* * ** *** ** ******* **** ** * ** ** *** **
    for (i=n+1;i<=m-1;i++)
    {
* ** *** * *** * * **** ** ** *** * (cpt=2;cpt<=i;cpt++)
* ** * **** *** ** * ** **** *** * * * *
* * * ** * * ** * ** ** * * ***** ** ** *** * *** ** ** * (i%cpt==0)
* ** ****** * * * **** * * **** * * * * ** ** *** ** ** ***** *
**** ****** * * * *** * * * * *** ** ** * * * ******** * * **** * * * ** *** *
** * * ** ** * **** * ** * *** **** *** *** * * *** *** ** *** ** ** **
******** * ****** * **** * *** ** ** * *** * *
*** * * ** *** ******* ****** * ** **** * * * * * ** *** ***** * ***
** * ** * ****** * * *** * ** ** **** * * (a==1)
* * * * * *** ** ** * ** * * ** ** ** ******* *** * * * ****** **
* ** ** * ** * ** ** * ** * * *** * * ** * ******** * * * ** * **** * * *** ** ** * * * ",i);
** * ** * ** ** * * * **** **** * * *** * ** * ** * * * ** *
* *** * ** *** *** * * * * * ** **** * ** ** * * ** * * ***
    }
* * * * *** * * ** ** 0;
}
answered by (-168 points)
0 0
Case 0: Wrong output
Case 1: Wrong output
Case 2: Wrong output
Case 3: Wrong output
0 like 0 dislike
Hidden content!
#include<stdio.h>
int main(void)
{
** * * ****** * * * a,cpt,n,m,i;
   a=0;
* ** * * * *** *** **** **** ** ** * *
    do
    {
** ** * ** * * **** ** * ** * ** *** * *** ** * * * * ** *
*** * ** **** **** * ****** * * ****** *
    for (i=n+1;i<m-1;i++)
    {
* ** * ** * * * ** * * * * * ** ** * * (cpt=2;cpt<=i;cpt++)
** * * **** * ** * ** *** **** * * *
* *** * ** ***** * * * * ** * ** ** *** ** * * * * ** ** * * * *** * (i%cpt==0)
** * *** * * * * *** * ** * ** *** * * * * * * ***** * ** ** **** ***
* * * *** * ** ***** ****** ** * * * * * * **** * ** ** * ** *** * *** * *** *
** * * ** * *** * * *** * * **** * * * *** * * * *
** ** * * *** ** * * **** ***** ** * **** ***
* * *** *** ** * ***** ****** * ** * * * ** **** ** ** **
** *** * ** * *** * ******* * * * * (a==1)
* **** * ** ** ** * * ** * * * * **** ** * * ** ***** *** *
* ** * * ** *** **** * * ** ** *** ** ** * * ** **** * * ** * ** * * * ** ** * * * * ** ",i);
** ***** ** ***** *** **** * ** **** ** * * ***** * * ** ** **
***** * * * * * ***** * * * **** ** *** * * * * ** ** ** *
    }
* *** ** *** * * *** 0;
}
answered by (-168 points)
0 0
Case 0: Wrong output
Case 1: Wrong output
Case 2: Wrong output
Case 3: Wrong output
0 like 0 dislike
Hidden content!
* ***** * ***

int main(){

* **** * * ** * * * ** * a,b,i;
*** * ** *** * * ** * ***** * ** ** *** **

*** * **** ** * *** ** ** *
* * ** * *** * ***** ** * * ** * ***** * ** * * * * && i<=2){
***** ** * * ** ** * ** ** ** *** * *** * * * * **** *** *** * * ** ***** ***** ",i);
***** ****** **** * * * **** *** * **** *** **
* **** * *** * *** ** **** * **** * if(i>2 && ** * ***** * ** ");
* ***** ** * * ** * ******* *** * ** * if(i>3 && i<=5){
* *** * * ** * ***** ***** ** * * ** * ** * * ** ** ***** * ** * * ** ** * && * **** ** ",i);
**** * * * ** *** ** * *** ** * **
* ** *** ** ** **** * * * *** * ** **** * *
** * *** *** ** * *** * * ****** **** ** * *** * ** ** ** * * ** ** * && i%3!=0 && i%5!=0 && * * * ** *** * * ",i);
** ** *** ** * * * * * ** * * ** *

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


return 0;
}
answered by (-301 points)
0 0
Case 0: Wrong output
Case 1: Wrong output
Case 2: Wrong output
Case 3: Wrong output
0 like 0 dislike
Hidden content!
#include <stdio.h>
int main()
{
    int d,n,m;
* * *** ** ** ******* %d",&n,&m);
    n++;
* *** ****** ** * ** ** * * * *
** * *** ** ** ** * * * *** ** ** * ** * * **

** * * ** * * * * * * *** ** * *** ( d = 2;  d < n ; d++)
* * * ** * *** * * ***** * * * * * *
** ** * * * ** *** *** ** * * ** ** *** * *** * **** * *** ** * (n % d == 0)
*** * ** * * * *** * **** *** * * * * **** ** ** * * ** * * *
** * * *** ** ** * * * **** * ** * ** **

* * * ***** *** ** ** * ** ***** ** * ** * ** * *** * *** ** *
* * ** * * **** ** * *** * * * * *** * *** * * * ******* *** **** ** *** ",n);
* * ** * * ** ** **** * * ** **** * * * *** ** ***** ** * * ** * *

* *** ****** * ** * *** 0;
}
answered by (-196 points)
0 0
Case 0: Wrong output
Case 1: Wrong output
Case 2: Wrong output
Case 3: Wrong output
0 like 0 dislike
Hidden content!
#include <stdio.h>
int main()
{
    int d,n,m;
* *** * * ***** ** * * ** * * * %d",&n,&m);
    n++;
* * * * *** ** * **** * * * *
* ** ** ** * ** *** * * * ** * * * * * **

*** * * ** * ** ** * *** * * **** * ** * * ( d = 2;  d < n ; d++)
**** * **** ** * * *** *** *** ** * ****
* * * * *** * *** * * * ** * * **** *** * ** **** *** (n % d == 0)
********* * ** * ** *** * *** * *** ** * ** ** ** *** * * ** * * * ***
* * * ** ** ** ***** *** * * * * ** * * *

* ** ** ** ** **** ** * * * ** * ** * * ** * **** * **** * ** **
** * * * **** *** *** **** * ** * ** * ** * **** * ** * * * *** *** ",n);
* * ** ** ***** *** ***** * ** * **** ** * ** * ** **** * * ** * *** ** * *

* * * * * ** * * ** ** 0;
}
answered by (-196 points)
0 0
Case 0: Wrong output
Case 1: Wrong output
Case 2: Wrong output
Case 3: Wrong output
Welcome to Peer-Interaction Programming Learning System (PIPLS) LTLab, National DongHwa University
English 中文 Tiếng Việt
IP:172.69.214.38
©2016-2025

Related questions

0 like 0 dislike
72 answers
[Exercise] Coding (C) - asked Nov 2, 2017 in Chapter 6: Loops by semicolon (5.2k points)
ID: 29831 - Available when: 2017-11-02 18:00 - Due to: Unlimited
| 12.4k views
0 like 0 dislike
93 answers
[Exercise] Coding (C) - asked Nov 2, 2017 in Chapter 6: Loops by semicolon (5.2k points)
ID: 29830 - Available when: 2017-11-02 18:00 - Due to: Unlimited
| 15k views
12,783 questions
183,442 answers
172,219 comments
4,824 users