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!
#include <stdio.h>
#include <stdlib.h>

int main()
{
    int x, y, flag, i;

* * ** * * * * ** * ** * *** %d", &x, &y);

* ** *** ** ** *** ***** ** ***** *
    {
*** * ** *** ** ***** *** * ***** * * * * * *

** ** * *** ** ** ** *** * * ** * * * * ** * * * i <= x/2; i++)
** *** **** * * * * ** *** ***** * **
* * *** *** * ** ** *** * **** * * *** * * ** *** **** * * * **** ** * * == 0)
* ** * * * * ***** *** ** * * ** ** * * **
* * * ** * * * * *** *** ** * ***** ** ** *** ************ * ** ** *** * * * *
* ** * * * *** *** * * * *** * * ** *** **** ***** **** * *** **** *
** * ** *** ***** ******* * * * * ** ***** * ** **** * ** * * ****
* * * * * *** ** ** *** * **** * *** ** **
** ***** ** ** ** ** * *** * * * *** ** * * **
* * * * ** ** * ** ** *** * **** * * ** **** *** * ****** **** ", x);
** * * ** * ** * * * * *** *
    }
**** ** ** * * * *** * 0;
answered by (-168 points)
0 like 0 dislike
Hidden content!
#include <stdlib.h>
#include <stdio.h>
int prime(int i)
{
* ** * * ** * ****** k;

** **** *** *** * * * * ** ** ** *
    {
* * * * ** * ** * * * ***** *** * *** ** * * **
* ** *** * * * ** * * * ** **** * * ******* 0;
    }
** * * ** *** * * * 1;

}

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

** ***** *** * ** * i,first;
** * * ** **** * * **** * ***** *
** ** * ***** ** **** * * *** ** * ** * ** **
**** **** ** * * * **** ** * ** * *

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

** * * ** * * * * w=first+1;

* ** * ** *** * * * *** * * ** ***
* * ** * * ** ** * * *** *** ** * ** * * * * *
* * * * * * * ** ** *** ** ***** * * * * ** * *** *** * * * * %d",w);





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

}
answered by (-16 points)
edited by
0 0
Case 0: Wrong output
Case 1: Wrong output
Case 2: Wrong output
Case 3: Correct output
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
Case 0: Correct output
Case 1: Correct output
Case 2: Correct output
Case 3: Correct output
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Correct output
Case 3: Correct output
0 0
Case 0: Wrong output
Case 1: Wrong output
Case 2: Wrong output
Case 3: Wrong output
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Correct output
Case 3: Correct output
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 i,n1,n2,c=0;

    //enter the two number intervals
    scanf("%d %d",&n1,&n2);

***** * * **** *** * ** * ** **
    {
***** * ** * ** * * * * * ** *** * ** ** * * j;
** * * * ** *** *** ******** * * * * ** * * * * ** ** * ** **
** * * ** ** * * ** * ** *** * *** * ** * *
* **** ** *** * * ** * ****** * *
********** ** ** * * * ** ** * ** * ** ** ******* *** ** **
* ** *** ***** **** ** **** *** * ** * ** ****
*** * ** * ** * *** ** ***** * * ***** * ***** *
* * *** ** *** ** *** * ** * *** * ** ** **
* ***** ***** * ** * * **** * ** ***** * ** ** ** * * * **
* * **** ** ***** ** * * *** * * *** * ******* ** * *** ** * * ****
** *** ** * * *** * * ** *** * ***** **** ** *** ** * ** ** * * * ** * ****** ******** * ** * * ** *
** * ** * * ** *** * * * * ** * * * ** * *** *** ** **** * ** * ** * * * ** ** * * ** ** ** * *** ** ** * ** * **
* * * * * ** ** * * *** * ** ** *** * *** * * * ** * * ** *** **
* * * *** * ******** ** ** ** * * * * ***** * ** * ** ** * * *** * * ** **
** * * * ***** * * * * ** ** ** ***** * ** * ** *** ****** *** *****
**** *** * * ** ** ** *** * * * * * * * *** *** *** * ** ** ** * * ***** * %d",i);
* * * ** **** * * *** * **** * ** * * *** ** * * ****** **
* ** ** * * ** * *** * **** * * ** *** * ***
    }
    return 0;
}
answered by (-167 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>

void main()

{
    
* ** ** ** * *** * ** num,m,n,d;
    
** *** ** ** ** * *** * *
    
* * * ** * * * * * ** ** * ** the Range Between m,n ");
* * *** * * * ** ***
*** * ** * * *** * ** * ** *** * * ** * ** &m,&n);
* * * ** * * * *
* ** ** * *** * * * * * (num = m; num <= n; num++)
    
** * ***** * * * *****
* * * * ** * * * * * * * ***** * * ** **
*** * *** ** * * * * *** * **** ** * ***** * = 2; d < num; d++)
* * ** ** ** ** * * * ** ** *
* * *** **** ** ** * ** * ***** ** * ** * *
*** *** *** * *** ******* ** **** * * * *** * * *** ** *
** * *** ** ***** * **** ** * **** *** **** ** ***** ** * * *** ***** ** (num % d == 0)
** ** ** *** ****** ** **** * * *** * * ** * * * **** * ** * * * * * **
** **** * *** **** ** ****** *** ******* * * * * ** * * * * **** * ***
** ** * *** **** * * *** * *** * *** ** **** * ****** *
* ** **** *** ** *** * * * ** *** * ** ** ** *
* ** * * ** * * * * ** * * ** * ** ** ** * ****
**** ** ** * *** * ** * * * * * *** *** * ** (d == num)
** * * *** * ******* * *** * * ** * * **
** * * ** ** **** *** ** ** * ** * * ** ** ** ", num);
* ** * * *** * * * * * * **
* * * *** ** ** * *
*** * * * * ** ** ** *
* * * * ** * * *** *** * *
** * * ******* *** *** 0;
    
}
answered by (-108 points)
0 0
prog.c: In function 'main':
prog.c:11:5: warning: implicit declaration of function 'clrscr' [-Wimplicit-function-declaration]
     clrscr();
     ^~~~~~
prog.c:37:5: warning: implicit declaration of function 'getch' [-Wimplicit-function-declaration]
     getch();
     ^~~~~
prog.c:38:12: warning: 'return' with a value, in function returning void
     return 0;
            ^
prog.c:5:6: note: declared here
 void main()
      ^~~~
/tmp/cchS0WoB.o: In function `main':
prog.c:(.text+0x1d): undefined reference to `clrscr'
prog.c:(.text+0x9a): undefined reference to `getch'
collect2: error: ld returned 1 exit status
0 like 0 dislike
Hidden content!
#include <stdio.h>

#include <math.h>

void main()

{
    
* * *** ** ** * num,m,n,d;
    
********* **** *** * **
    
** ** * * * ********* ** *** *** ******** the Range Between m,n ");
****** ** **** ** ** ** *
** ** ** * ** * * *** ** ** * * ** ** &m,&n);
* ** * ** ** ****
** ** * * * * ** * * ** (num = m; num <= n; num++)
    
* * ** * * * * * * *
* *** * * * ** ** *** * ** ***
** *** * * * * ***** ** *** * ** * ** ** *** * * **** = 2; d < num; d++)
* * * * ***** * * * ** *** ** * * ** *
****** * * *** *** * ** *** * **
* * * * * ** ** **** * *** ** * **** * * ***** **** **
* *** *** * * ** * * ** * * **** ** * ** * * * ** ** ** * * * * *** (num % d == 0)
* * *** * * ** *** * **** * ** * ** * * * ** **** * *
* *** * * *** ** * *** ** ** *** * * ** *** * * * * * **
** *** *** * * ** * * *** ** ** * ** ** *** * **** * * **** ** **
*** *** ** * * * ****** * * ** **
* * * *** * * * * ** ** * *** * ** * * **
* **** ** ** ** * * * **** ** * ***** (d == num)
* **** *** ** ** ** * * * * **** ***** ** * *
* *** *** ** ** ** ***** **** * ** ** * ** **** * ", num);
* ***** * ** * * * ** * * *** *** *
* ** * ** ***** * * *
*** ***** **** * ****
* **** *** *** **** ***
* *** *** * ** ****** * 0;
    
}
answered by (-108 points)
0 0
prog.c: In function 'main':
prog.c:11:5: warning: implicit declaration of function 'clrscr' [-Wimplicit-function-declaration]
     clrscr();
     ^~~~~~
prog.c:37:5: warning: implicit declaration of function 'getch' [-Wimplicit-function-declaration]
     getch();
     ^~~~~
prog.c:38:12: warning: 'return' with a value, in function returning void
     return 0;
            ^
prog.c:5:6: note: declared here
 void main()
      ^~~~
/tmp/ccb4hr0F.o: In function `main':
prog.c:(.text+0x1d): undefined reference to `clrscr'
prog.c:(.text+0x9a): undefined reference to `getch'
collect2: error: ld returned 1 exit status
0 like 0 dislike
Hidden content!
#include <stdio.h>

#include <math.h>

void main()

{
    
* *** *** ** ** num,m,n,d;
    
* *** ** ** * *** *** * *
    
*** **** ***** * *** ** * **** *** * * * the Range Between m,n ");
* ** ** * * * ** *
*** *** * * ** * * * * *** * ** * **** * * &m,&n);
***** * ** ** ** * *** ***
* **** * * ** ***** * (num = m; num <= n; num++)
    
** *** ** * ** **
** ** * * * * *** * ********* *** ** * ** ****
* ** * **** *** *** * ** * * * * * * ** ** = 2; d < num; d++)
* * ** * ** ** ** * *** * * **** *
** *** * * * * * * ****** **** * ********
**** * ** * * ****** * ** ***** ** * * * ** * ** ** * * * **** * *** *
* * * * ** ******* * ** ***** *** **** *** ** ******** *** * ** * *** *** (num % d == 0)
* ***** * **** * * *** * * ** * ***** *** * ** * ** ** * * *
* ** * ** ** ******* *** *** * ** * * *** ** * * ** *
** ***** * *** ** * ** ** * **** * **** ** **** ** ** *
** * ***** * **** * * * * *
** * * *** * * ** * ** ** ** * ****
****** ** *** ** ** * * * * ** ***** (d == num)
* **** ** ***** **** **** * * * * * ** *
** ** * ** ** * * ** * ** * * *** *** * ****** * ** ** ", num);
* * ** * ** * * * * ** ** * *** ** *
* ** * *** * *** ***
** * * *** *** * * ** *****
* * * * ** ***** ** * * **
**** * ***** ** * * ** 0;
    
}
answered by (-233 points)
0 0
prog.c: In function 'main':
prog.c:11:5: warning: implicit declaration of function 'clrscr' [-Wimplicit-function-declaration]
     clrscr();
     ^~~~~~
prog.c:37:5: warning: implicit declaration of function 'getch' [-Wimplicit-function-declaration]
     getch();
     ^~~~~
prog.c:38:12: warning: 'return' with a value, in function returning void
     return 0;
            ^
prog.c:5:6: note: declared here
 void main()
      ^~~~
/tmp/ccmKIGDf.o: In function `main':
prog.c:(.text+0x1d): undefined reference to `clrscr'
prog.c:(.text+0x9a): undefined reference to `getch'
collect2: error: ld returned 1 exit status
0 like 0 dislike
Hidden content!
#include<stdio.h>
int num_is_prime(int x)
{
** * ** ***** ** ** *** y;
** * ****** *** ** ** *** ****** *
    {
** ** **** ** * *** ** * ** *
** ** ** * *** * ** * *** *** *** * **** *** * * * **
**** * * * * **** * **** *** * * * * * * * * *** *** * *** ** ** * * ** * *
    }
** ** *** ** * * * ****
    {
* * * ** * * * ** ******* ** ** *** * ** ** 1;
    }
** ******* * * ***** *
    {
***** * *** **** ***** * * *** ** * ***** * **** 0;
    }
}
int main()
{
*** ** *** * ** * **** a,b,f=1;
* ** *** * ** * * * * * **** **** * %d",&a,&b);
** * * * * * * *** * * *
* * ***** *** *
* * ***** ** *** * ** * **** * * * * ****** * ***
* **** *** ** * *** ***** ** * * * * * **** *
* * * *** **** * ** ** * * * *** ** ** *
** * * **** ** * * ** * * * ** ** * *** * ** * * ** * * * * *** *
* *** ** * * ** * * * *** ****** ** ** * *** **** * ***** **** ***
* * * * * * * *** **** * * * * * * * ** ** * * *** * * * ****** *** ** * ** ********** ** ** ** * ");
*** ** * * * * * * * * * **** ** ** * *** ** ** * **** ***** *
* * ** * * ************ * * ** * ** **** * * * **** * * ** ** * * **** ***
* * * * ** *** ** *** ** * **** *** **** * * * * * *** *
** ** ** * *** ** **** ****** * * *** * *
    }
}
answered by (-255 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 num_is_prime(int x)
{
* *** ** * * * ** * ** * y;
** * * ** **** *** ** ******
    {
* *** ** ******* **** * * * * **** **** * *
**** * ** ** ***** * ** *** ****** ** ***** *
*** *** * ** ** *** * *** * * ******* * ******* ** **** * ** * * *
    }
* *** ****** * ** *** ****
    {
* * ** * **** * *** *** **** * * ** ** * ** * 1;
    }
* *** * * ** *** * ** *****
    {
*** ** * **** *** * ***** **** * * *** * * ** ** * 0;
    }
}
int main()
{
* *** *** * ** ** a,b,f=1;
* ** * * ** * *** * * * * * ** %d",&a,&b);
*** * * * * ** *** * ** *
    {
*** * * *** *** * * ** *** * * ** ** ****** *** ** *
** * **** ******** **** * ** ** *** * ** * * * * ***** *
**** ** ** * ** * * *** * **** * * *
**** *** * * **** ** * * ** * ** ** * * * * ** * * * *** **** * * ***
* ** * ** ** ** ** * * **** * * * ** * * * *** ** * *
** * **** ** * * * ** * * *** ***** * * * * ** * * ** * ******** * ** * * ** * * * * * * * *
** ** * * *** * * * * **** * * **** * * * * * * * * ** ***
***** ** ** ***** * ** ******* * * *** * * ** * * ******* ** *** ** * ***** ** * * *
**** *** *** * ** *** ***** * ** * * **** ** ****** ** * * * *
****** ** * ** ** * **** * * *** **** * ** * **
    }
}
answered by (-255 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 i;
    int n;
    int m;
    int flag;
    int count=1;
   
    scanf("%d%d",&n,&m);
    
    if (n<m)
    {
        for(n=n+1;n<m;n++)
        {
* ***** ** * * * ** * * * ** ****** *** **** *** * *** ** * * ** ** * *
* *** * ** * * * ** ** * **** * *** ** * *** *** **** *
* *** * ** *** ** ** ****** ** * ** * **** ** * *** ** * * ** **** * * * * *** * ** * ** *** * ** * * **
* ** * * ** * *** * *** *** ** **** *** *** *** *** ** **** ** * * * * ** * * * *
** * * ** ** * ** ** * ** * * * *** * *** ** * ** ** * * * * * ** * ** ** * **** * *** ** (flag==0 && n==i)
*** ** ** ** * *** * * ** * ** ** * *** ********* * ** * ******* * * * ** *** * *** *** * * **
** * * *** * * * * * *** * **** **** ** * ** * ***** ** * * * * * ** ***** *** * * * **** *** * ****** * * * == 1)
** ***** * * * * *** *** * *** * * * ** ** ***** ******* * ****** **** **** *** * * * * *** * ** * ****** *** * * * *
* ****** *** ** * *** * *** ** * * ** ** * * ** *** * **** *** **** **** * * **** * ** *** ****** *** * ** ** * *** * *** * **** *** ****** n);
*** * * * * ** ** ** * ** * * ** * * ** ** ****** * * ** * * **** * * ** * ** * * *** * ** ***** * * * * * ****** *** * **** ** * **
******** * *** * ** * **** * * * * *** ** *** * * ** ***** *** **** *** ** ** *** * * ** * ** *
** ** ** ** ** * ** * * ******* * ****** *** * * * ** *** *** * * ** * * ** * ** *** * * * *** ****
* ** ** * * **** ** ** * * *** ** * * * *** * * * **** * * * * ** ** * * ***** * * **** *
**** ** * * *** ** *** ****** * **** ** ** ** ** ** * * * * * **** *** ** ***** * ** * * ** *** * * * * * ***** ***** ** ** * ** * ** *** * %d", n);
*** ** * *** * * * * * * * * *** * * * * ****** * * ** * *** * * * ** ** ** * * ** *** * * * ** *** ***** *** * * * ** *** * * * * ** *** * *** * *
** * * * *** ** * ** * **** ** * ** ** *** **** ***** * ** *** ** * * ** * * * * *** ***** ** * *** **** * * * * * * * **
* ** *** * * ** * * * * ** *** * *** *** ** ** *** * ** ** * * * * **** ** * ** ** * *** ** * ** * ****
*** **** * ** * * ** ** * **** * * * * * *** ** ** *** *** *** * *** ** * * * ** *** ** * * *** ***
* * ** ** * ** * * * **** ** ** * ** ***** * **** * *** ** ***** * * *
* * ** ** *** ** * ** * * ** * ** * *** ** ** * ** ***** * * * * * * * * * * *** * (flag==0 && n!=i)
*** ** * * * ** *** * ** ** * * * *** *** * *** * *** * ** *** ** * * ** * * ** *** * **** *
* * * ** * ** **** ***** * * * ** * * ********* * **** **** **** * * * * ** ** * * ** **** *
* *** * *** ** ** * ** **** **** ** ** * ** *** * **** ** ** * * * * ********* ** **** * * * * * ** ***
** ** ** * ***** * * * * ** *** ** * ** * ****** * * ***** * **** * * * *** ** * * *
***** ** ** * ** **** * **** * **** ** ** ** * ** **** * *
        }
    }
    
   
   
    return 0;
}
answered by (-284 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 i;
    int n;
    int m;
    int flag;
    int count=1;
   
    scanf("%d%d",&n,&m);
    
    if (n<m)
    {
        for(n=n+1;n<m;n++)
        {
** *** ** * ** ** ** ** *** ** * * * * * * ** * ** ** ** *** ******
* * * * * **** **** * ** *** * ******** **** * * * * * * ***
*** ** * * ** * *** ***** ** * * ********* *** * ** ** ** **** * * * *
** * **** * ** * ** **** * ** *** *** **** * ** *** * **** * * * *
* ******* ** ** * ****** * *** * ** * * ** * * ** **** ** * ** ** ** * * *** ** * ** * (flag==0 && n==i)
* *** * **** ** * ***** * * **** **** * * * ** ***** *** * * *** ***** * *** ** ** * *
** ***** ** *** * * *** * **** * ** * *** **** * * ** * ** * * * ** * ** * * ** * * ** * ***** * * * == 1)
* ** ** * *** *** ** * ** * ** * *** * * ** *** * ** **** * * ** ** * ** * * * * * * ** * ** **** ** *** *
*** ** * * * * * * * * *** *** * ** *** **** * * ** * * ***** ***** * **** ** * * ** ** * * ** ** ** * ** * *** *** * * * * ** * *** *** ***** ** ***** n);
* * * *** ** *** ******** * ** *** * * ** * * * * * * * *** ** * ** *** * * * * * * **** *** * * * * * **** * * ** ** *
* * *** * * ** ** * * * * * * * ** ** * * * * **** *** * ** * * ** ** ** * ** ***** *
** ** ** * ** ***** *** ** ** *** ** *** ***** *** * * ** ***** ** * * *** * * * * * ***** * * *** *
* * * ** *** ****** * ** *** ** * **** ** * ** ***** * * * * * * ** ** ** *** ** ** * * ******* * * ***** * **
* * *** * * ** ** ** * **** ** * * * * *** * * * ** * ** * *** * * * *** **** ** * * * ** ** ** * ** **** **** *** ** * * %d", n);
* *** **** *** ** * * *** * * * * ** * ** **** *** ** ** *** * ** *** * * ***** * * **** * ** * * ** ** ****** ** * * * *** ** * **
** * * ** * *** * ** ** *** * *** * * * ** * * ** * * * ** * * * ** * *** * *** ** * * ** * ** ** * ***** * * * ***
* ** ** ** * * ** *** * * *** **** * * ** * ** * * * * * ***** * * * *** * *** *** ** *** * * *
* ** * ** ** * *** * *** ************ ** * * *** * * * **** * ** ** ** * **** *** *** * * **
* * ***** * * * * * * *** * ** * ** * * * ** *** *** ** * ***** * * *** * ** * ** * *
* * ****** * * ** ** * * * ** *** * * *** ** * * ** ** ** * * ** **** **** ** * * * ** (flag==0 && n!=i)
* * * * * * ** ** * **** * ** * * ** ******* *** * * **** *** * * * ** *
* * ** *** * * * ****** **** ******* *** ****** * * * ** * * * * ** ** * * **** *** * * ********
*** * * *** * ** * ** ****** *** ** * *** ***** ** **** * *** * ** * ** * *** * * ** * * *** * *** * * **
** * * ** * ** * ** ******* * * *** *** * ** * ** * ** ** ** * ** * *
* ********** * ***** * *** * * * * ** * ** *** * ** * * * *** * *
        }
    }
    
   
   
    return 0;
}
answered by (-193 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.80.233
©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
| 14.8k views
12,783 questions
183,442 answers
172,219 comments
4,824 users