How to write a C Program to Check Prime Use Loop And Recursive in C Programming Language ?
Solution For C Program :
/*Check Prime Use Loop And Recursive*/
#include<stdio.h>
#include<conio.h>
#ifndef title
#define title "\n 1. Chon 1 de Nhap So Nguyen Duong. \n 2. Chon 2 de Hien Thi Cac So Nguyen To Dung Vong Lap. \n 3. Chon 3 de Hien Thi Cac So Nguyen To Dung De Quy. \n 4. Chon 4 de Ket thuc. \n Moi chon: "
#endif
int KiemTraVongLap(int you_number){
int count = 0;
for (int i = 2; i < you_number; i++)
{
if (you_number % i == 0)
{
count = count + 1;
}
}
if (count == 0){
return 1;
}
else {
return 0;
}
}
int InVongLap(int you_number){
for (int i = 2; i < you_number; i++)
{
if (KiemTraVongLap(i))
{
printf("\t\n %d \n", i);
}
}
}
int KiemTraDeQuy(int you_number, int i){
if (i == 1){
return 1;
}
else {
if (you_number % i == 0){
return 0;
}
else {
return KiemTraDeQuy(you_number, i - 1);
}
}
}
int InDeQuy(int you_number){
for (int i = 2; i < you_number; i++){
if (KiemTraDeQuy(i, i / 2)){
printf("\t\n %d \n ", i);
}
}
}
int main(){
int you_choose, you_number;
do
{
printf(title);
scanf_s("%d", &you_choose);
switch (you_choose)
{
case 1:
system("cls");
printf("\n Nhap So Bat Ky: ");
scanf_s("%d", &you_number);
system("cls");
continue;
case 2:
system("cls");
InVongLap(you_number);
continue;
case 3:
system("cls");
InDeQuy(you_number);
continue;
case 4:
system("cls");
printf("\n\n\n\t\t\t\t Ket Thuc.");
break;
default:
system("cls");
printf("\n \t\t\t\t Da Chon Sai. Moi Chon Lai! \n");
continue;
}
} while (you_choose != 4);
_getch();
return 0;
}
Learn More :
Recursive
Prime Number
- PRINT PRIME NUMBERS BETWEEN 1-300 USING BREAK AND CONTINUE IN C
- Check given number is prime number or not using c program.
- C or C++ program to print prime number
- C or C++ Program To Print Prime Number
- C Program For Prime Number or Not
- C Program For Prime Number Using Function
- C Program For Prime Number
- Huge Prime in C Program
- C Program to Detection of a Prime Number
- C Program to print all prime numbers from 1 to 300.
- C Program To Find Prime Number And If Number Is Not Prime Then Find Factors
- C Program to Find Prime Number and Complex Number
- C Program to accept n numbers & store all prime numbers in an array & display this result
Loop
Check
- CHECKING LEAP YEAR USING C PROGRAM.
- Check given number is prime number or not using c program.
- Write a c program to check given string is palindrome number or not.
- C program to Check While packet(s) hasn't been acked
- Given a numerical value, check if at least one of the elements of the vector is equal to the numerical value if so, say where in the negative case, say that there is no.
- C Program To Find The Length, Reverse Of A String And To Check It Is Palindrome or Not
- C Program To Check The Given Value Is Vowel
- C Function to Check Vowel
- C Program To Check Leap Year
- C Program To Check If It Is A Palindrome Numbers Or Not
- C Program to Check if a number is in an array[1000]
- Armstrong Number Checker in C
- C Program to Check Given String is Palindrome or Not
- C Program to Check Whether Number Is Perfect Or Not
- C Program To Alarm Check
- C Program To Read A Parenthesised Infix Expression From The User And Check Whether It Is Well Parenthesised Or Not
- Input a Number and Check if it's Palindrome or not C Program
- Input Number and Check if it's Armstrong C Program
- Input Number and Check if it's Even or Odd C Program