0 like 0 dislike
17.6k 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.6k views

99 Answers

0 like 0 dislike
Hidden content!
#include<stdio.h>
int main()
{
int i,a,b;
int flag;
scanf("%d %d",&a,&b);
* * * * * ***** * **** *
  {

*** * * ***** * * **** * *** ** *** * ** * * j=0;
* ** ***** ** ***** *** *** ** * *** ** ** *
** * ** ** **** ** * * * * ** *** *** * **** ** **
*** ** *** * *** * ***** * ** * *
* *** * * ** * ***** * *** ** * * reminder=i%j;
* *** * ** * * ** * **** * * * ** ** *** *** == 0)
* ** * * * * **** ** * * * *** *
** * ** ** * * * * ** ** * *** ** * ** ** * * ** ****** ** * ** *
** * ** ** ** ** **** * **** * ** ** * * ** ** ** * ***** * *
* ** * * * * **** ** ** ***** ** ****



**** ****** * * *** * ** **** ** **** **** ** **
}
    if (flag==1)
*** **** ** * * *** ****** * * ** * *** ** ****** *** * ",i);
return 0;
}
answered by (-329 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,b,n,first=0;

scanf("%d %d",&a,&b);

for ( n=(a+1);n<b;n++){
****** * ** * * ** *** d;
* * * ** ** **** *** * * (d=2;d<n;d++){
* *** * * ** * **** **** *** ** ** * * * * (n%d==0)
* * * * * * * *** * * **** ** * * * ** * ***** **** * *

** * * ***** * ** *
*** ** * *** * **** *** * * ** *
*** ** *** * * * *** * ******* ** * * *
**** ** ** *** * * * *
** * ***** ** **** *** * * * ** * * ***** *** (first==0)
** * *** *** * *** ** ** * **** *** *** * * *
** ** ** ****** *** *** ** **** ****** ** *
** * * * **** *** * ** *** ** * ** * ******* *** ***** ** ** ** * ********* ");
** ***** *** **** * ** ** ***** * ** * * ** * ** ** *
** *** **** * *** * * * * * * * * ** *** ** **** *
** * * * * *** * ***
}
return 0;
}
answered by (-329 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 a,b,n,first=0;

scanf("%d %d",&a,&b);

for ( n=(a+1);n<b;n++){
** * ** * ******* * d;
* *** * * * * * ** ** (d=2;d<n;d++){
* * ** * ** * * *** * ********* * ** * ** *** (n%d==0)
* *** **** * * * * * * ******* * * * * ***** *** * * ** * ** * * ** ** * *

* ** * **** **** * ** *
* * * *** * * * * ** * *
** * * * * *** ** * * ** ** * * *** ***** *
** * ** * ** * ** *
* ***** ** * * ** * *** ** **** ** * * ** ** (first==0)
* * ** * **** **** **** ***** ** * * ***
* ** ** ** ** * * *** ** * * **** * *** *
* ** *** * ****** *** * ** * * * * * *** *** * * ** * * * ** **** ");
*** * * * ***** * ** ******* **** * ** * ** *** **
* * * * * *** * * * ** ****** * **** * * **** * * **
    }
}
return 0;
}
answered by (-329 points)
0 0
prog.c: In function 'main':
prog.c:6:1: warning: implicit declaration of function 'scanf' [-Wimplicit-function-declaration]
 scanf("%d %d",&a,&b);
 ^~~~~
prog.c:6:1: warning: incompatible implicit declaration of built-in function 'scanf'
prog.c:6:1: note: include '<stdio.h>' or provide a declaration of 'scanf'
prog.c:21:13: warning: implicit declaration of function 'printf' [-Wimplicit-function-declaration]
             printf(" ");
             ^~~~~~
prog.c:21:13: warning: incompatible implicit declaration of built-in function 'printf'
prog.c:21:13: note: include '<stdio.h>' or provide a declaration of 'printf'
prog.c:23:9: warning: incompatible implicit declaration of built-in function 'printf'
         printf("%d",n);
         ^~~~~~
prog.c:23:9: note: include '<stdio.h>' or provide a declaration of 'printf'
0 like 0 dislike
Hidden content!
#include <stdio.h>
int main ()
{
    int a,b,c,d,e,f=0;
    scanf("%d %d",&a,&b);
    for(c=a+1;c<b;c++)

******* * ** * ** * * ** * **** * * * **
***** * * ***** * * *** * ***** * ***** ** * *
*** **** **** ** * ******* * * ** * ** * *** ** * * * ** ***
********* * **** ** * *** * * * ****** * * *
* ** * * * ** *** ** ***** *** ** ** (d==c)
** * * * * * * ****** *** ** * * * ** * ***
**** * ***** ** ** * * * * * * *** ** **** ** **** * * ** **
*** *** * ** *** * * * * **** * * ** * * ** * ** * * * ****
* *** ** ****** *** * *** ** * ** ** * ****** *** * * *** ** * * * **** ** *** ** *
*** * * **** * ** * ** * ** * ** * * * *** ** ***** * * *
** ** * *** ** * ** ** ** ** ****** * * * * * ** * * * ***
* * ** * ** ** * * *** ** * * * * ** * ** * **** * ** ** *** **
** * * ****** ** * ** *** * * * * ** * *** * * **
** * ** *** * * ** ** *** ** * *** *** *** **** ***** * ******* ***
**** *** *** * *** ** * * *** ** * * * ** ** * ** * * * * * * * ** *** * %d",c);
* * * * ** *** * ** * * **** ** * ** ** * ** ***
** * * * * *** ** * * **** *** ** ** *
* * ** * *** ** *** * * ** ** *** * if(e==0)
*** * **** * *** * ** ***** * ** *
* ** ** ** * * *** ** ** * ***** *** * ** * * * * ***
       }
** ****** * * **** ** ** * ** ** * *** **

    }
    return 0;
}
answered by (-229 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,n,e=0;
* **** * * * * * **** * ** *** ** * * ** %d", &a,&b);

    for (n=(a+1); n<b; n++)
    {
* * * * *** * *** **** * ** * * * * * * *** *** ** d;
* **** * ** * ** * *** ** * * * * * * * (d=2; d<n; d++)
* ** * * * * ** * *** * *** * * **** *
** * ** ** ***** ** * * * * * * ** * * * * (n%d==0)
* ** ** * **** ** * ** ** *** * *** * **** ** ** * ** *
   }
*** *** ** ** * * *** * * * * * ** * ** ** * **
*** ** * ** * ** * ** ** ** ** * ** ***
** * ** ** * ****** ** * * * * * * ** * **
*** ******** * *** *** **** ** ** * ** **
** *** ** * ** ** ******* **** * ** * * * * ***** * * ******* (e==0)
** ** * * * *** * ** ** ** * *** ******* ** * * ** ** ** * ** ** * * * ** **** *
* * ****** * * ** ** * *** **** * ** * * **** * * * ** **** * *
*** *** * * *** * * ***** * ****** *** *** ***** * * * *** ** * **** * * ** * * ** * ");
***** ** *** * ***** * ** *** * ** *** ** *** * **** ** * * * *
* *** **** ** * * * * ******* * * *** * * * *** * * * * ***** * ** ** *** ***** *
**** * ***** *** * * * * ** * * **** *****
}
return 0 ;
}
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>
int main()
{
    int n,m,i,j,flag=0,count=0;
    scanf("%d %d",&n,&m);
    for(i = n+1; i<m; i++)
    {
* *** **** ***** * * * ** ** * *** * * ** = 1;
**** *** ** ** * * * ** * **** ** ***** * ** * * ****
* ** * ** * * ** * * * * ***** *** * ** ******* ***** ** *** * * * {
* ** **** ** * ** ***** * * * *** *** * ** * ** **** *** * ** * ** = 0;
** * ** * ****** * ** * * * ******* * ** * **** * ** *** * * * * *** ** ** * *
** * ** * *** * *** ** * *** **** *** * * * ** ****** ***
* *** *** * * ****** ** * * * * ** ****
** * * ** * * * * * ** * ** * ** * * * *** * **** *
* * * * ** * * ** * * ** * * ** * *** ** *** * **** *** *** * *** *
**** **** * * ***** * ***** * ******* * * ** * ******** *
* ** * * **** ******** * * ** ** * ** * ** ** ***
* * * *** *** * * * * ***** * ** ** **** ** * * * * * * ** ** ******** * * *** * ** * ** **** ** ***
** * ** * * * ****** * ******* * * * ** ***** ***** * * *
* * * ** * * ** *** ** * ** * *** ***** **** * * * * * * ** * ***
** * * ** * *** *** * ** * ** * * * *** * ** **** * *** * *
** ** * ** * ** * * ** *** * *** *** * ** ***** * *** * *** * * * * *** %d",i);
* * * ** *** * ** * **** **** **** *** * *** * * ** ** ** *
** ** *** * *** ** * * * *** ** **

    }

    return 0;
}
answered by (-281 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(void)
{
    int n,m,i, flag=0, count=0;

* * **** ** **** ** * ** *** %d",&n,&m);
** * ** ** * ** * * * *** ***
    { flag=0;
    n++;

* * * *** * **** * *** ** * ** ***** ***** * * *
** * * ** * * * ** * * * *** **** *** * ***
* ** * * * * * * * * * * * * ** * ** * * * *** ** ** * * **
** ** * ****** ** * ** ** * * *** *
* * *** ** ** ** ** * * * * * **** * * ** * ** ** ** * * * **
* * * * *** * * *** * ** **** ** ** * ** * *** * * ***
* *** * * * * ** * ** * ******** *** * *
* *** ** * ** * * ** **
* * **** * * * * *** * * **** * * * * **** **
* * * ** ** * * * * *** * * ** * * * *  if(count==0)
* **** * * ****** * *** ** * * ** *** ** ** **** * *** *
* * *** ** ** ** ** *** **** * * ** * ****** * * ** *** * * ** ** ** ** ** * *** * ** * **** * * *
**** * * * ***** * * ** * ****** * *** ** * ** * ** **** * ***

**** * * **** *** * * ** **** *** * * ** ** ** * **
**** * ** * ******* *** ** ** * * ** * * ** * * * **** *** *** * * ******* ** *** * * * %d",n);}

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




    }

    return 0;
}
answered by (-32 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 <math.h>
int main()

{
    int num,m,n,d;
    int a=0;

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

    for (num = m; num <= n; num++)
            {
*** * ** ** **** * *** ** ***** ****** *** ***** * * * * * * * * ****** * *** * = 2; d < num; d++)
** * ** ***** * ***** *** * ** * **** ***** * *** * * * ***** * ****** * * * ****** * * *** * * * * *

** * * * * ** * * * **** ** * ** * *** *** ** * ******** * ******* * ** * ** * ** ******* * **** * (num % d == 0)

** * **** ***** * * ****** *** * * * * * * * * * * * * *** ** * *** * **** * * *** ** ***** *** ** ** * ** * *** ** * *
* * *** *** * * ***** ** ** ******* ** ** ***** * ** * * * * ** **** **** ** ** * * *
* * **** * **** *** ****** ** ** ***** * *** * ** * *** * *** * *** * *** ** ** *** (d<num)
******** ** **** **** * ** ***** * *** * * ***** *** ** * ** ** * ** * ** * * ** * * ** * ** * *
** ** *** ** * * ***** * ***** *** ** * *** * * ******** ** * ** *** **** ** {
*** * * * * * * ** * ** ** **** ** ***** * * ** ****** * * *** * * * *** *** ** * ** * * (a==0)
* **** * * * * * * * **** ** ** ** ** * ** ** * * **** *** * * ** * * * * * ** * *** *** ***** * * * * * ** ** *** *** ***** * *
** * * * * * ********** * * * * * * **** **** * *** ** ** * * ** ***** ** *** * ** * ** * * * ***
** * ** *** * * **** ** * * * * ** ** * * * * * ** * * **** * ***** * ***** ** * * *** * * * * * *** * *** * *** *** * * ");
*** ** * * ***** ** *** ** *** * *** ** * * * ** ***** * *** * * * ** * ***** ** * * * * ** * ** * **
*** * ***** **** * *** ** * *** ** * * **** *** * *** * * ** * ***** ** *** *** * * * * * ** * * * * * ** *** num);
**** ** ***** * ** ** * * * *** ** * * *** * *** ** ** * * * * * * **** ** ** *


            }
* ** * * ** * ** * * * ** * *** *** * * * *** ** ** ******* ****** * * * ** 0 ;

}
answered by (-254 points)
0 0
Case 0: Wrong output
Case 1: Correct output
Case 2: Wrong output
Case 3: Wrong output
0 like 0 dislike
Hidden content!
#include <stdio.h>
#include <math.h>
void main()

{
    int num,m,n,d;
    int a=0;

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

    for (num = m; num <= n; num++)
            {
* * *** * * ** * *** * ** * * * * **** ** * * ** * ** * * * ** = 2; d < num; d++)
* * ** * * **** * ** * **** ** ** * ** ** *** *** * ** * **** ** ** ** * * * * ***

** * ** * ***** * *** *** *** * ** **** **** ***** * * ***** *** ** * ** * ** * ** * * * * * * * (num % d == 0)

* * * * * **** ** *** * ***** * **** * **** **** *** ** ** * * ** ***** ***** * * * *** ** ** * * * * *
*** * ***** * * * * ***** * * ** * * * * *** * **** *** ***** *** ** *** **** * * ** * **** ** *
* * * * ** ** ***** * * ** * * * * * ** *** ***** ******* * **** * * ** * * * * *** (d<num)
* * ** * ** * * * * * *** * *** **** * * ** * * * * ** * * **** ****** * ** ** * * ** **** **** *
* * ** * * **** * * * ** * ** * **** * ** ***** ** * ****** *** * ** * *** * ** ** *** * ** {
* ** * * * * * *** * ** * * * ** * ** * **** ** ** *** **** ****** ** ** * *** * **** **** * ** *** * ** (a==0)
***** ** * ** **** * * **** ** * * ** ** **** * * * ** ** * * * * ** * * * * * ** * ** *** * * ** ** * * *** **** **
* * *** * *** ** * ** ** *** * *** **** * * * ****** ***** * ** * * * ** ** *** *** * * * *** *
* * *** ** * * * * *** * ** ** * *** * ********* ** * * ***** *** **** ** * * *** * *** * * **** * * *** ** * * ** * * ** * * * * ** ** ");
**** ****** ***** ** * * * * * * * *** * ** * * * *** * * ******** * **** ** ****** * ****** ** ** * ** * * **
* *** ** ** * * *** ***** * *** * *** * * *** * ** ** * **** ** * ** * * ** * ** ** * **** * ** **** * num);
******* ** * ** ** * * ** * * * **** *** ** * ** ** ** **** ** * ** ****** ******* * ***


            }
** ** * **** **** ** * * ** * *** ** * * *** ** * *** * *** ** ** *** **** ***** 0 ;

}
answered by (-254 points)
0 0
prog.c: In function 'main':
prog.c:33:22: warning: 'return' with a value, in function returning void
               return 0 ;
                      ^
prog.c:3:6: note: declared here
 void main()
      ^~~~
0 like 0 dislike
Hidden content!
#include <stdio.h>
int main()
{
    int d,n,m;
* * * ** ** ****** *** %d",&n,&m);
    n++;
    do
* * ** * * ** ** * ** ** ** * * ** ** ** * * *

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

* * ** * * ** * * ** ** * *** *** ** ** * * * * * *** ** * ** *
** ** *** * ** * * * ***** ** * * *** ** ***** * *** ** ** * * * * * ******
* * * ** ****** ***** * * * * * * * * * ** * ** ** **
* * * * * * * * * *** ** ** * * * **** ***** * * ** ** (n!=d+1);

    while(n<m)
** * * * ** * ** ** ***** * * * * **

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

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

    return 0;
}
answered by (-196 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.139
©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.2k 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.6k views
12,783 questions
183,442 answers
172,219 comments
4,824 users