0 like 0 dislike
17.4k 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.4k views

99 Answers

0 like 0 dislike
Hidden content!
#include <stdio.h>

int main(void)


{
int num1, num2,x,y,flag;


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

  for (y=num1+1; y<num2; ++y)
  {
* * ** *** * * ***** *** ****** ** *
*** * ** **** * ** * x<=y/2; ++x)
* *** * ** *** ******** ** **** ****
** * * * **** * * * **** * * ** * ** ** **** ****
* * *** * **** ***** *** * * * * * * ******* *
** ** *** ** * * **** * * *********** * * * ** ****
*** * *** * * * ***** ** *** * * * * *** **** ** *** ** * * *
** * ** **** ***** * ** * *** * *** **** * * *
* ** * * ** * * *** *
* ******** ** *** ** ** **** ** *
* ******* ***** * ** *** ** *** * *** ***** * **** *** * * * ",y);
  }


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


}
answered by (-107 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)printf("%d ",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 *** * *** *

int main(void)

//Code to displau the prime numbers between two integers

{
int num1, num2,x,y,g;


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

** * ** (y=num1+1; y<num2; ++y)
  {
**** * **** **** * ** *
** * * * *** * * ** x<=y/2; ++x)
****** * * * *** ** ****** *
* ** ** * * *** * ** * * * * ** * ***** * ** *
* ** ** * * ** ****** * ****** * *** ***
*** * *** ** * * * *** * * * * ** * * ** * * ** * * ** * *** *
* * * * * * **** * * *** ** * * **** * * *** * ***
*** * ** **** ***** * ** * * * * ** **
* **** * * * * * ** *** *** ** **
**** * ** *** ** ******* * * ** * * * *
** * * *** * * * * ** * *** ** ** ** *** ",y);
* * ** *







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


}
answered by (-107 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 a;
    int b;
    int n;
*** * ** * * ******** ***** first=0;
*** * * * * * ** ** * *** * %d",&a,&b);
***** * * * * ** ** * ** * (n=(a+1);n<b;n++){
****** ***** * ** * * * **** ** * * * * * *** d;
* ***** * * *** ** * * * ** ** ** * * *** (d = 2; d < n; d++){
**** * ** ** * * * * *** **** * ** * * ** **** * * ** * (n % d == 0)
** * ******* * * ** * *** * **** * * *** ** ** * * * **
**** * *** ** * *** * *** * * * * ** ** *
** * *** ** *** * ** ** * * * * * (d < n)
** *** * ** * ** * * *** * ** ** **** * * *
*** * * ** ** * * * *** * ** * * * **** ** * *
***** * * ** ** * ** ** * ** * * * * ** * ***** * (first==0)
* * * **** *** * ** * *** ** **** ** ** *** * * ** ** ** ** * ** * * ** * *** ** ****
* * * * ** * ** ** ** * ***** * * *** *
* * * ** *** ** * * * * * ** **** * ** * ** * ******* * **** * * ** ");
** ** ******* ** * * *** *** * * *** ** * * * ** * ** * *
** * ** * *** * * * **** **** * ** * **** *** * * * * ** *** ** n);
** **** * * ** * * ** ***** *** * * *
    }
** ** **** ***** * 0;
}
answered by (52 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 d,n,m;
*** *** ** * * * ***** * * %d",&n,&m);

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

* * * * * *** * * *** ** ** * ** ** * ( 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() {
** ** ******* * * * * a,b,i,j;
** *** * ** * ****** * * ** ** * %d", &a, &b);
** * * ** ** * * * ** *** {
** * * * **** * ***** **** * * ** ** ** ** * * * ** ** ** * * {
**** * * *** * * **** ***** * *** * * * * * * * * * * * * * break;
* *** *** * * ** ** * **** * ** ****
* ******** * * ** * * ** ** ** **** * * printf("%d ", i);
* ** *** * * **
}
answered
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()
{
** * *** *** * * * d,n,m;
* * * * * *** * ** ** ** ** ** *** ****** **** *

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

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


***** * *** ****** ** *** ** ** * * *** * * * * ** *** ** ** * * ** * ***** ***
** * * ********** * *** ** * * * ** * * **** *** *** * ******* ** * ",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(void)

{
    int n,m,i,def=0;

    scanf("%d %d",&n,&m);
* ** ** * **** * * * * *** * ** * **** * * (n<m)

        { def=0;
* * * * **** * * * *** * *** * * *** ***** * * ** * * *
* *** **** ** ** * * * ** * * ** * *** * * * * ** ** * ******* i<=n/2; ++i)
**** * * *** * * **** * ** ** *** ** * ** ********** * ** * **** *** * ** ****
* ** ** * ** * * * ** * * * * ** * ** * ** ** * *** * **** ** * * * * * * *** * * ** (n%i==0)
** ** * ** * ** ** * ***** * * * *** ***** *** * ******* ** * **** ** * * ** * * * * * *** * *** * ** **
* ** **** ** * * * *** * * * * * *** ** * * ***** * ******** ** *** ** *** * ** *** * * ** ** **
* * ** * * **** * * * * ** ** * *** *** ** ** * * * ** ** * * *** ** *** * **** ** ******* ***** * *
* * ****** ** ** * * ** ** * * **** * * ****** * ** * ** ** * * * * * ** **** *** ** ** ** *** * * *
********* *** ***** * *** * *** * ** * * * *** ** ******* ** ** * ** *
** * * *** ** * *** ** *** ** * **** **** * ** * *** ** ** *
** **** ** * ** * ******** * ** * *** * * ** **

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

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

* *********** ** * ** *** * ** * *** ** ** * *
       return 0; }
answered by (-304 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 n,m,i,j,k,c=0;
    scanf("%d %d",&n,&m);
    for(i=n+1;i<m;i++){
        for(j=2;j<=i;j++){
* * ***** * *** ** **** ** ***** *** * **** * ** ** **** * * * ****** *
* ******* *** * *** ** *** * * ** * * * * ** ** ** * **** ** **** ** * ** **
** ** *** * * * * ** * * * * ** * * *** ** ** * ** * ** * ** **** *** *
* ******** ** * * * ** * ** * * * * ** ** ****** * * * **** * *** * * ** * ** ** * * *
* * * **** ** **** * ** ** * * ** * * * ** ** * * ** *** ** * *** *** *** ** * * * * ****** * *** * ***** *** **
*** * * * *** ** * * *** * * * * **** * * ** ** ** ** **** ** ***** * * * ** ** ***** * * * ** * *** * **** * * *** *
* * * ** * ** **** *** *** * * * *** * * * ** * * * ** ** ** * * ** * * ** * ** ** ** ** *******
***** ** * * * * * * *** * ** **** *** **** ** * ** **** *** * * * **** * ** *
* * * ** * ****** * * * ** *** ***** ** ** ** * *** * **** * ** ** * ****** *** ** * *
* ****** ** * * * * ** * ******** ** ** * **** ** ****** * * ******** * * * ** * * *** **** ** ** * *** * %d",i);
** ** *** ** * ** * *** * **** *** ** ******** *** * * ** ***** *** ** ** ****
* * *** *** ** * *** * ** * * ******* ** ** * ** *** * ** * ** ** * ***
** * ** * * ** * **** * * * ** ****** * ** *** ** **** * * if(k==0){
*** * * ** * ******* *** ** * ** ** ***** ** ** * * * ** * ** * *** * ** * * ** * * * ** *
* ** * * ** * * *** ** * * ** * * * * * **** * ** *** * * **** * ****** * *
        }
    }
    return 0;
}
answered by (54 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 a,b,c=0;
**** * * *** ** * * * **** * * %d",&a ,&b );

***** ******** *** * *** i=a+1;i<b;i++){
* * ** **** * * * * * * ** ** *** * * * * * *** **** j=2;j<=b;j++){
* * ****** ** *** ** **** * * * * * ** * * *** * * * * * *** ** * && i%j==0) break;
* * * ** * * *** * * ** * * * * ** ** *** * ************ *** * if(i==j){
** * *** * *** * ** ** ** * *** * ** **** * ******* * * * ** **** *** * * * * * **** ** *
* *** ** ******** ** * *** *** ********* * * ** *** ** ** ***** ** * ** * * ** * * *** ** * * * * * ** * **** ** * *** * ** ** * ** ** ** *
* * * ** ** **** * *** * * * ** * * * ** ** ******* ** * ** * * *** ** * * ***** ** * ** * ** * *******
* * * ** * * *** * * *** * ** **** ***** ** * ** * **** * * * * ** ** *
* *** ** * ** *** ** * * **** * * * *** * * **** * ** *** * * ** *** * **** * ****** * *** printf(" %d",i);
****** ** * **** ******* * **** *** * *** * ** *** ** *
** *** * * ** * *** * * ** *** * **** * **** *

    }

    return 0;
}
answered by (-116 points)
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Correct output
Case 3: Correct output
Welcome to Peer-Interaction Programming Learning System (PIPLS) LTLab, National DongHwa University
English 中文 Tiếng Việt
IP:172.70.194.138
©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.1k 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
| 14.4k views
12,783 questions
183,442 answers
172,219 comments
4,824 users