+ 1
Using Do While Loop,
Using do while loop Find and display all prime numbers in a collection of N numbers in the function Prime_Nos. Get the value of N before scanning each value in the collection of N numbers in the main program. All prime numbers should be displayed on the same line but separated by two spaces. The value of N must be a positive number.
8 odpowiedzi
0
hello world
+ 2
The code what you made I done worked. Now you can continue.
https://sololearn.com/compiler-playground/ckOJrj7s41SF/?ref=app
+ 1
First will be needed your attempt better link to code on playground.
+ 1
I see. But if you want learn to code try to solve that first.
After your new try can be again helped.
0
The output should be like this
2 3 5
0
#include<stdio.h>
int Prime_Nos(int N);
int main() {
int N, num, ctr;
printf("\n\tEnter N num: ");
scanf("%d", &N);
Prime_Nos(N);
printf("\n\n\n");
return 0;
}
int Prime_Nos(int N){
int ctr = 0, prm_count= 0, divisor, is_prime, num;
do {
printf("\n\tEnter a number: ");
scanf("%d", & num);
if(num > 1){
is_prime = 1;
divisor = 2;
while (divisor < num) {
if (num % divisor == 0) {
is_prime = 0;
break;
}
divisor++;
}
if (is_prime) {
if(prm_count > 0){
printf(" ");}
0
printf ("%d", num);
prm_count++;
}
}
ctr++;
}
while (ctr < N);
//printf ("%d", prm_count);
}
0
Thanks bro but output isn't answer the problem asked, the output should be displayed same line but separated two spaces