1 like 1 dislike
12.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

 

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

45 Answers

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

int n,m,i,PrintedPrime=0;

int IsPrime(int a){
* * * * *** * ** * ** * u;
** *** * ****** * * **** result=1;
*** * ** ** * **** * * **** ****
**** ***** *** * * * *** *** * * ** ***** * **** *** = 0;}

* ** * * * * * *
* * ** * * ***** ****** * * result;
}
int NextPrime(int a, int limit){

* * * * ** ** * * * * ** ** *
* *** * * * * ***** ** u;
** **** ** * * * * *** e;
* * * *** *** * * * ** result=1;

* * * * *** *** ****** *** * * *
* *** * *** * ** ** * * * *** * *** * ** || a==1 || a>limit){result = 0;}
    }

* **** * ** * * * ** result;
}


int main(){
** * * * ** * ** * * * * * * * * %d",&n,&m);

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

* * *** *** ** ** (i=n;i<=m;i++){

**** ** * * ** * ** * * ** * * * **** ** * * && i!=0){
* ** * * ** *** * * * *** ** * * ***** ** ***** *** * * * * ** * * ***** ** * **
** * * * * *** ** * * ***** ** **** ***** * * * *** * *** * * **** * ****** ***
** ** ** ** ** * ***** * * ** * * * ** ** * * *
* * ** *** ** ** ** * *** ** ***** && PrintedPrime==1){
* * ** * *** ** * ** **** ***** * * ** **** ** * * * * * * ** **** * * * * * *
* * * * * * *** *** ** ** ** * **** **** * * * * * * *** * *** * *
* ** *** * * ** **** * * ** *** ** * * ***** ** **
* ** ** * * * ** *


* * ** * ***** *** * * 0;
}
answered by (-286 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()
{

int n,m,i,j,prime=1,count=0;

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

for(i=n+1;i<m;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>
#include<math.h>
 int main ()
 {
* ***** * ** * * ***** ** * * a,b,i,j, prime=1,cnt=0;
* ** ******* * ** * * * * **** * * * * &a,&b);
*** * ** *** ****** * ** * (i=a+1; i<b; ++i)
     {
* ** * *** ** ** **** * ** * * * * * ******* *
** ** * ****** ** * ** ** (j=2; j<i-1; j++)
     {
*** **** * *** * * ********* **** ** * (i%j==0)
* * *** ** *** * * *** **** *** ** ** **
* * * * ** * *** * * ** * ** * * **** * **** * * ***
** * **** * ** ***** * * * * ** *** **** * * * ** * * ** **** ** ***** **
*** * * ** * * **** *** ***** * ** * **** **** * **
     }

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


     }
 }
answered by (-254 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>
#include <stdlib.h>

int main()
{
* *** ****** ** * ** * a,b,i,k;

* * ** * * ** ******** * *** %d",&a,&b);

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

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

**** ** * *** * * ** * * * * 0;
}
answered by (-16 points)
edited by
0 0
Case 0: Wrong output
Case 1: Wrong output
Case 2: Wrong output
Case 3: Wrong output
0 0
Case 0: Wrong output
Case 1: Wrong output
Case 2: Wrong output
Case 3: Wrong output
0 0
prog.c: In function 'main':
prog.c:13:20: warning: zero-length gnu_printf format string [-Wformat-zero-length]
             printf("");
                    ^~
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)
{
* * ** ** * * * * m,n,i;
**** * ** * ** ** * *** * a,b,c;

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

*** ** *** ******* *** * * ** ** && i<n;i++)
    {
** * *** * * **** * * * * * ****** * ****
*** **** * ** * * * * * * * * * **** *** * *

* * ******* **** **** * ** ** * * * * * * * * && b==0)
* ** * ******* * ** *** * * ****** * * ***
** ****** ** ** ** * * * * ** *** **** * * * ***** * * * **** * * *** *** *** **
*** * **** * * * * ** * **** * * *** *
* * * * * ***** * * *** * *** * *** ** * * ** ** *** && c!=b)
** * * * **** * * * * ** ***** * * * *
* * ******** * * * ** **** *** *** * **** ** ***** * ** * * * * ** ** ** ****** * *
** * * **** ** * * *** ** * ** * *** *

    }
*** ** ***** * * ***** 0;
}
answered by (-249 points)
0 0
prog.c: In function 'main':
prog.c:16:20: warning: zero-length gnu_printf format string [-Wformat-zero-length]
             printf("");
                    ^~
0 like 0 dislike
Hidden content!
#include <stdio.h>
int main()
{
** ** * * ** ** ** * a,b,gcd,lcm,c,d;
* * * ** ** **** * * **** ** *** %d",&a,&b);
**** ** * * *** *
***** * * * ** ***
* * ** * * ** **** *** (a%b!=0)
** * ** * ** * ** *
** ***** ** ** ** **** ** ** * *** * **
* ** * * * ** **** ** * ** *** ** ** * **** *
*** * * * ***** * * **** * ** * **** * * **
** *** * ** * * * * **
* * * * * ** * ** * * * ***
*** * * * ***** * ** ** * * * *** ** %d",gcd,lcm);
** *** ** * ** ** ** * 0;
}
answered by (-229 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,flag,counter=0;
    scanf("%d %d",&n,&m);

    if (n<m)
    {
*** * * * ** * * * * * * *** * * * * *** ** * (n=n+1;n<m;n++)
        {
* ** * ** * ** * * * * * * * ***** ***** *** **** ** (i=2;i<m;i++)
*** * ** ***** * ** * ** * *** * ** ** ** *** **** ** * ***
***** *** * * * ** *** * *** * ** ** * *** * * ** *** * * **** ** * *
* ** **** **** ** * *** ** *** * ** * * *** ** * ** * * ** ** * **** * *** * * * * * (flag==0 && n==i)
* ***** * ** ** ******* **** * ** * * * * ** * ** ** ** **** **** * *** * *
* ** * *** * *** ****** **** * *** ** ** *** ** ** * * ** * * * **** ** * ** * * * **** ** ** * ** ** *** * ** **
** * * * **** *** ***** * * ** * ** *** * * ** *** * ** * * * *** **** * * * **** ** ** * * ** *** * **** * (counter==1)
**** * * * *** * **** * * ** ** *** * * **** ** *** * * * ** * **** **** *** * ** * * *** * *** * * * * ** *** * *** * ** **** ******
* ** * * * * ** * * ** * * * * * *** *** * * * * **** *** * ** ** ***** * ***** **** ** ** * **** *** ** *
** *** * * ** * ** ** * * ** * *** ** * * * * ** * * ** **************** *** ** * * ** * * * ** * ** * %d",i);}
*** ** * * ** *** ** **** ***** ** * * ** * ** ** *** * * ** * * * **** * *** * ** * ******** * * * **
* ****** ** ** * * ***** *** ********* * ***** ** ** ** ******* * ** ***** ** * * * *
*** ** * * ** ** * * * ** * * * ** * * *** * * ***** *** **** *** ** ****** if (flag==0 && n!=i)
**** * * ****** ** * * **** * * * * * ** ***** *** * * ** *** *** ** **** * ** * * ** * ** *
** * ** ** ** ** * ***** ** ** *** ** *** * * **** * *** * *** **** * **** * *** * ** * * * * * **** ***
******** * ** ** * * ** ***** ** **** * ** **** *** *** **** ** * ** * * * * **** * ** ******
*** * *** **** ** * * **** ** **** ***** * * * **** ** *********
        }
    }

    return 0;
}
answered by (-249 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>
#include <stdlib.h>

int main()
{
    int a,b,i,j,prime=1,cnt=0;
* * ******* * * ***** * * ****** %d",&a,&b);

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

    prime=1
    {
* * * * * * ** **** ***** * ** * * * * j<i-1; j++)
** ** * * * ** **** * * *** ** * ***
* **** **** * * ***** *** **** ** * ****** * **** ** * * ***** *
**** ** * * *** **** ** * *** *** *** * * *** ***** ** * * ***
* ** ** ** ** **** ** ***** *** * * **** *** ** * * * ** ** ** * **** * * * ** * ***
**** ** ** ** * *** **** ** **** * ** ***** * * * * *** ** *** * ****** * ** *** ** * * * * ** * * * ****
* * **** * ** ** * *** * ** ***** * ** **** * * ***** *
**** **** * ** **** *** ******* *

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

    }

    return 0;
}
answered by (-127 points)
0 0
prog.c: In function 'main':
prog.c:12:5: error: expected ';' before '{' token
     {
     ^
0 like 0 dislike
Hidden content!
#include<stdio.h>
int main(){
    int a,b,c=0;
    scanf("%d %d",&a,&b);
*** ** * ** ** * * ***** * * *
* * ** * *** ** * * * **** *** *** * i;
* *** *** * * *** * *** * *** * ** *** ** *** **** **** *
*** * * ** * ** ** * ** * **** * ***** * * * * * * ** * **** ** *
* ** * ** *** *** * *** * * * * ** * * ** ** * ****** * * ******* * **** printf(" %d",a);
* * * ** * * * * * * *** * *** ** *** * *** ** * * ** *** * * * * *** * * * ** * **** *** *
** *** * * * * * * * * **** **** ** **** * *** * ***** *** ** * ** * * * ** * ** **** * ** ** * *** * * **
** **** * *** * ** * ** *** ** ******** * ****** * *** * ** ** **** ***** * * * ** ** ** * ** * ** ** * ****
** *** ** *** ** **** * ***** ** * * * * * ** *** * *********** * * **** * ****
** ** ****** ******* * ** ** * *** *** * ** * *** ** **** * **
** * * * * **** * * *** * *** * * ** * ** * * ** * * ** ** if(a%i==0) break;
* * * ** * ** **** ***** * * *** * ** **** **
    }
    return 0;
}
answered by (-116 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(){
* ** ** **** ******** * * a,b;
* * * ** * *** *** ** ** * * ** ** %d",&a,&b);
* *** **** ** *** ** * * **** **
* ** ** ** * **** * * ** * *** * * *** * * * i;
** ** ** ** * * * * * **** ** ** * **** * * * * *
*** * * **** ******* * *** *** * ** *** *** ** * * ** * ** *** * ** printf("%d ",a);
* * **** ** ******* ** *** * ** * ** * *** ** ** ** * *** * ** * * if(a%i==0) break;
*** * ***** * **** *** ** ** ** ** * ** ** *
** * **** **** * ** * *
* *** ** * *** * 0;
}
answered by (-116 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.243.108
©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.3k 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
| 26.5k 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.9k 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.3k views
12,783 questions
183,442 answers
172,219 comments
4,824 users