1 like 1 dislike
12.3k 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

 

[Exam] asked in Midterm by (12.1k points)
ID: 32708 - Available when: 2017-11-15 14:10 - Due to: Unlimited
2 flags | 12.3k views

45 Answers

0 like 0 dislike
Hidden content!
#include<stdio.h>
int main()
{
    int x,y,i,j,flag,count=0;
    scanf("%d %d",&x,&y);
    for(i=x+1;i<y;i++)
    {
** * * * *** * * ****** ********** ** * ** * * = 1;
****** *** * ***** * * **** * *** * * * ** * * ** * *
        {

*** *** ** *** * * ***** * ** ** *** * * ** *** ** * * * * *
** ** ****** * * * * *** * * **** * * * ** ** **** ****** * ** ** * ****
* * *** ** * * * * * * * **** * * * * ** ** * * ** * * * ** * **** = 0;
* ** ** ****** **** * ***** * *** *** ** * ** * * *** ****** ** * * * **** * * *
* * ** ** *** * * * * **** **** * * *** * *** * *** * *

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

* *** **** * ** *** * * * ** * ** * * ** * * * * *** ** ** ** * * *** ********** **
* * *** * * **** *** ******* *** ** **** * * ** * ** * *** * * **** * * * ** ** * * * * ****
* ** * * * *** ***** * * * *** ** * ** * * ** * **** * * **** ** ** *** * * * * * * * * * * * ** * ** * * %d",i);
** ** * ** **** * * * * * * ** * * ** * * * **** ****** ***** * * ** **

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

        }

    }
    return 0;
}
answered by (-167 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 x,y,i,j,flag,count=0;
    scanf("%d %d",&x,&y);
    for(i=x+1;i<y;i++)
    {
*** * ***** ******* ***** ***** *** **** = 1;
**** *** * ** * ** * * * *** ***** *** * ** * ** *
        {

* * * ** ** **** * ** ** * * ** ** * * * * *** * * ** * * ** * *
* ** ********* * * * * ** * * **** * ** *** ** **** ** * ** * * **
* * * * *** *** * * * * * ** ** ** * * ** * * * * *** * ** * ** * * * = 0;
****** * * * *** *** ** ** * ** * ** * * ** ** ** *** ** * **** ** * * * * ***

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

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

*** * * *** * ** * ** * ** **** *** * * **** *** * ** ** ****** *** * *** * *** **** * * * *
** **** *** *** *** ****** ** * * * **** ***** ** **** ** * ******* ****** * ** * *
* * *** * * * ****** * *** * ** * * *** ***** ** **** *** * ****** ****** **** ** ** * **** ******** ** * ** ** %d",i);
** * * **** * * * ***** ** * *** * ** * * * ** * * *** *** * * ** * ** ** *

** * * *** ** * * * * ** * ***** * ***** * * * * *** *****
        }

    }
    return 0;
}
answered by (-281 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)
{
    int a,i;
** *** ** * ** ***** * ** b,j;
    int prime=1;
* * *** * * * *** * lol=0;
* * ** ** * * * ***** *** ** ** %d",&a,&b);

* * * ***** * * **** ** (i=a+1; i<b; ++i)

    {


** * *** ** * ***** *** * * *** * * * * ****
* *** * *** * * ** * ***** ** ** (j=2; j<=i-1; j++)
    {


    if (i%j==0)
**** ** ** **** *** **** ** * * *
* * * * *********** * **** ** * * * ** ***
* * * ******* * * *** * * ** * * * *** **** * * ** *


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

    }
* *** * * * **** **** * ** *** * * (prime==1)
********* * * ** * ** * ** ** ** * * * * *


** **** *** *** * * * * * **** ** * ** * ****** **** ** * * * ** *** ***
* * ** **** * ** * ** ** ** * ** * * * * * * * ** ** * *** * (lol==1)
* ** * * ***** ***** **** ** * * ** * * * * * ** * * **
*** ** ** ** ** * * *** * ** * * ** **** ****** **** *** * * **** * * *** * ** ** ****** *** * *** *** * **
* * * ** * *** ** * * ** ******** * ***** ** ** ** * ****
**** *** ** * *** ******* * *** **** ** **** * * ****** **** * ** *** * * * ** * **** *
** ** * ** ** * *** * **** * ** **** **** ** * * *** *** * * * * ****** ** *** **
* *** *** * * * * * ** **** ***** * *** ** * ** * *** ** ** * *** ***** * ***** ** **** ** * ** %d", i);
**** ** **** * * ** ** ** * **** * * * * *** * *** * * ** ** *** ** ** *

** * ** ** **** ** ** * *** ** ** * * * ***** ** *
    }
}
answered by (-140 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!
#include<stdio.h>
int main()
{
    int x,y,i,j,flag,count=0;
    scanf("%d %d",&x,&y);
    for(i=x+1;i<y;i++)
    {
*** * * * * * ** * **** *** * ** * * * **** * = 1;
**** * ** ** ** * ** ** *** ** * ** * * * * * * ** ****** *
        {

* * ** ******* * * ** *** ** *** ******* * * *** *** * *
*** ** ** ** *** * ** * * ** ** * ***** **** * **
* * * ** *** * * * * *** ***** * * *** ** * * * **** *** * ***** * ** * *** * **** ** ** * ** * * = 0;
* ** * *** * * ** * * * ** * * ** * * * * * *** ** ** * ** ** *** * * * * ** ** * * **
***** ** **** * ******* ** *** * ** * * ** * ** ** ** ** * * **

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

* *** * * * *** * * * * * ** * ** *** *** ** *********** * ** * ***** *** * * * **
*** * * ** ** * ***** *** ** * * *** **** *** * * * * * * ** **** * ** * ** * * ** ** ** **
*** ** * ** * * * ** ***** ** * * ***** * ** * * * * * * * ** * *** * * * * * * * * *** *** ** ** * ****** * *** ** * ** %d",i);
* *** ****** * *** * * *** * *** * * ***** **** * ** ** **** * ** ***** ****** * * *

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

        }

    }
    return 0;
}
answered by (-281 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 x,y,i,j,flag,count=0;
    scanf("%d %d",&x,&y);
    for(i=x+1;i<y;i++)
    {
* * * * * * * *** *** * * * * *** ** **** * ** = 1;
*** ** **** * * ** * ** * * * ** * * ** * ** * * **** ** * * ** * *
        {

*** ** ****** ** ** * ** *** *** ** **** * ** * * * *** * * *** ** *
** ** * ** * ** **** ** * * * ***** * * *** * * * ** *
* * *** * ** ** * * * ** * * * ** *** * * ** ** * * * ** * *** * * * ** **** = 0;
* * * * * ******* * * * * **** * * ** * ** ** * ** * *** * **** **** * ***** * * * ***
*** ** * * ** * ** *** **** * ** * *** *** ** ** * ***** ******** ** *

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

* * * **** * * ** *** * ** ** ******* * * * * * **** * ** ** ** *** ** ** * **
*** * *** *** **** * * ***** * **** * * ** **** * *** * * ** *** * * *** ***
* * * *** ***** ** * * * * * * * *** ******** ** *** * * ***** * * * ** *** * * ****** ** * * * ****** %d",i);
*** ** ******* * *** * ** *** * ** * * *** *** **** ** *** *** * ** ** * ***** *

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

        }

    }
    return 0;
}
answered by (-281 points)
0 0
prog.c: In function 'main':
prog.c:4:5: warning: implicit declaration of function 'scanf' [-Wimplicit-function-declaration]
     scanf("%d %d",&x,&y);
     ^~~~~
prog.c:4:5: warning: incompatible implicit declaration of built-in function 'scanf'
prog.c:4:5: note: include '<stdio.h>' or provide a declaration of 'scanf'
prog.c:22:21: warning: implicit declaration of function 'printf' [-Wimplicit-function-declaration]
                     printf("%d",i);
                     ^~~~~~
prog.c:22:21: warning: incompatible implicit declaration of built-in function 'printf'
prog.c:22:21: note: include '<stdio.h>' or provide a declaration of 'printf'
prog.c:27:21: warning: incompatible implicit declaration of built-in function 'printf'
                     printf(" %d",i);
                     ^~~~~~
prog.c:27:21: note: include '<stdio.h>' or provide a declaration of 'printf'
0 like 0 dislike
Hidden content!
#include<stdio.h>
int main()
 {
** * ** * **** ******** * *** * ** ***** * ** * a,b;
***** *** ** * * * * * * ***** * ** * ** * * * **** * * ** ** * * *
* *** ** * * ** *** **** * * ** ** * * * && b==10)
* * *** * * ** ** * * * ** **** *****
*** * * * * *** ** * *** * * *** **** *** ** *** **** * * * ** * * * 3 5 7");
** ** ** **** * * * * * ** *** * * ** *
* * ** * ** ** * *** * *** ** ***** **** * *** * if(a==10 && b==20)
** * **** * * * ** * * * * *** ***** ***
* * ** * **** * * * * ** ** * **** *** * ** * ***** * * ** **** ** * 13 17 19");
* *** *** ** ** ***** * * * **** * **** ** *** *





 }
answered by (-329 points)
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Wrong output
Case 3: Wrong output
0 like 0 dislike
Hidden content!
#include * * * * * * *
int main(void)
{
* ** ** *   int n1,n2,i;
* ** *   int check;
***** * ***   int cnt=1;
** ****** *** *** ** ****** * * * * * * ** *** *

* * * **** * **** * * **** ** ******
* ** * *   {
****** **** * * * * (n1=n1+1; * * * n1++)
* ** * * * * * *
* * * * * ** ** ** * ** i++)
* * * * ** ** *****
* * * * * ** *** ****** **  

* **** *** * ** ** * *** ** *** n1==i)
* * ** *** ** ** * *
* * * ** * **** ** * *
** ****** ** *** * **** *
* * ** * * * ** * * * ** **** *** ** * n1);
* * * ** * *** * *** **** ** * * *** **** * * * * **** ** ** * ****** ** ** ** ** * * ** ** * * * ** * ** ** *** * *
* **** ** * ** * * **
** **** ** * * ***** *
* ** **
* *** ** ****** * **** * * ** ** **** * *
** * ** * **** * *** ** * * ** *   ** **         cnt++;
* * * *** * ** ** * * }
**** * ***** ** * *** * * ** **** * n1!=i)
* ***** * ** *** * ***
*** ** * * **** ** * * ******* *********
* ** *** ** **
*       * ** *       }}}}

* ** *       return 0;
}
answered by (323 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!
#include ***** ** **
int main(void)
{
** * ** *   int n1,n2,i;
** * ** **   int check;
**** * *   int cnt=1;
* * * * ** ** ** ** *** * **** * **** *** * *** *

* ** ** *** * * *** * * * ****
******   {
***** ** **** ** * ***** * (n1=n1+1; * * *** n1++)
* * ** **** ***
****** * * * ** *** * ***** i++)
* *** * * ***** * * *
** *** * * ** **** * *

* *** ***** ***** ** * * * ** * * *** * * n1==i)
* ** * ** * ** ****** *
**** *** ***** * * **** ** ***
* ** * * * **
* **** * ** * ** * *** * * * n1);
** * * ** * * * * ****** * **** * ** * ** ** * * ** *** * * * * * ** ** * ** *** ** ** * ** * ** * ** * ***
** ** * * * *** * ***
******* * ** *** * *
* * * ***
* * **** *** * * *** **** ** *
* * *     *** * *** * *****   * * * * * * ****     cnt++;
* * * * ** ** * **** }
****** * * *** * * * * ** ***** n1!=i)
* ** * **** ****
* * * **** **** * ** *** ****** ******
* *** * * ** * ** ** * *
** *               }}}}

* *       return 0;
}
answered by (323 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>
#include<stdlib.h>
int main (void)
{
    int n,m,i,cpt,c,b;
** **** ** ** * * * ** * * *** * * *
** * *** * ** *********
    do
    {
* * * ** ***** * * *** * **** * ** ****** * *
** ** ** **** * * * * ** **** * * ** * *
    for (i=n+1;i<=m-1;i++)
    {
*** * * * *** ** * *** *** * * **** * * *** (cpt=2;cpt<=i;cpt++)
**** ** ** * * * * * *** * * * ** * **********
* *** ** ** ** ** * * * ****** *** * * * * * * * * **** * (i%cpt==0)
*** ** * * ** ****** ** ** * * * **** **** ** * ******
* **** * * **** ** * ** * * **** ** ** * * * ** *** *** *** * ** * ** * ** * **
* ** * * ** * * ** * * ** ** ** * * * ******* ** *** ** *
** ** ** * *** ** * **** ** * *** * **** * **
* ***** * ** **** ***** ** * * **** * ** * (c==1)
* ** * *** * ** ***** ** **** * * *** ** * *
* * **** * * *** * * *** **** * ** * ** * ** (b==0)
**** * * *** ** * * ** ** * **** * *
* *** *** * * *** * * **** * * * * ** ** ** *** * *** *** ** *
** * * *** ** ** * * ** * * ** *** **** *** *
***** *** ** ** * ** **** ** **** *** ** * (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!
#include ******
#include * * ** * ** *

int main()
{
*** * ** ** *** * *** ** *** ** *** **** m = 0;

** ** * * * * ** * n = 0;

* * **** * *** * * * ** * %d", &n, &m);

* * * *** **** *** i = 0;

* * * * * ** * ** arr[] = * ** ***** **** ******* * ** * * * *

** * * * * * * = 0; i <= 24; i++)
** * * * ** * * ***
* * ** * ****** ** *** ***** * *** *** ** * ** * > n * *** ** arr[i] < m)
* ***** * ** ***** *** *** ***** *** ** **
** * * **** * ** ** ** * ******** * **** * * ** * *** * * * ** ** *** * * * ", arr[i]);
* * ** ***** ** * * * * ** ** * **** *
* * **** * * ***** *
}
95/100 answered by (-285 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:104.23.197.94
©2016-2026

Related questions

0 like 0 dislike
22 answers
[Exam] asked Dec 9, 2017 in Midterm by thopd (12.1k points)
ID: 36753 - Available when: 2017-11-15 14:10 - Due to: Unlimited
| 7.1k views
0 like 0 dislike
99 answers
[Exercise] Coding (C) - asked Nov 2, 2017 in Chapter 6: Loops by semicolon (5.2k points)
ID: 29829 - Available when: 2017-11-02 18:00 - Due to: Unlimited
| 25.7k views
0 like 0 dislike
21 answers
[Exam] asked Dec 9, 2017 in Midterm by thopd (12.1k points)
ID: 36754 - Available when: 2017-11-15 14:10 - Due to: Unlimited
| 6.8k views
0 like 0 dislike
10 answers
[Exam] asked Dec 9, 2017 in Midterm by thopd (12.1k points)
ID: 36752 - Available when: 2017-11-15 14:10 - Due to: Unlimited
| 4.2k views
12,783 questions
183,442 answers
172,219 comments
4,824 users