当前位置:网站首页>Various types of questions judged by prime numbers within 100 (C language)
Various types of questions judged by prime numbers within 100 (C language)
2022-07-05 08:15:00 【chen_ bx】
subject 1: Judge 100 What are the primes within ?
Prime numbers are also called prime numbers , Is greater than 1 Of the natural number , except 1 A natural number that has no other factor than itself .
Use for A nested loop , Traverse
The code is as follows :
#include <stdio.h>
int main()
{
/* Definition of local variables */
int i, j;
printf("100 Prime numbers within \n");
for (i = 2; i < 100; i++) // Determine the scope to find
{
for (j = 2; j <= i; j++)// Range of determining factors
if (i%j ==0) {
break;
} // If you find , Is not a prime number
else if (j ==i-1)// Until the last divisor , I didn't find , So this number i As a prime number
{
printf("%d\t", i);
}
}
return 0;
}
Output results
subject 2: Enter a number to determine whether it is a prime number ?
#include <stdio.h>
int main()
{
int x = 0;
int i = 0;
printf(" Please enter the number of judgments required :");
scanf_s("%d", &x);
if (x < 2)
{
printf(" Please enter the ratio 1 Large number ");
}
else
{
for (int i = 2; i < x; i++)
{
if (x%i == 0) {
printf(" This number is not prime ");
break;
}
else if (i == x - 1)
{
printf("%d Prime number ", x);
}
}
}
}
Output results :
边栏推荐
- C language # and #
- Basic information commands and functions of kernel development
- On boost circuit
- Buildroot system for making raspberry pie cm3
- Basic embedded concepts
- Correlation based template matching based on Halcon learning [II] find_ ncc_ model_ defocused_ precision. hdev
- Problem solving: interpreter error: no file or directory
- My-basic application 2: my-basic installation and operation
- Soem EtherCAT source code analysis attachment 1 (establishment of communication operation environment)
- Stablq of linked list
猜你喜欢
Compilation warning solution sorting in Quartus II
Create inf module in AMI code
How to select conductive slip ring
Some thoughts on extracting perspectives from ealfa and Ebeta
Design a clock frequency division circuit that can be switched arbitrarily
Shell脚本基本语法
C WinForm [get file path -- traverse folder pictures] - practical exercise 6
C, Numerical Recipes in C, solution of linear algebraic equations, LU decomposition source program
Class of color image processing based on Halcon learning_ ndim_ norm. hdev
On boost circuit
随机推荐
Synchronization of QT multithreading
MySQL之MHA高可用集群
UEFI development learning 4 - getting to know variable services
Interview catalogue
【云原生 | 从零开始学Kubernetes】三、Kubernetes集群管理工具kubectl
Altium designer learning (I)
Compilation warning solution sorting in Quartus II
1-stm32 operation environment construction
Installation and use of libjpeg and ligpng
Use indent to format code
Programming knowledge -- assembly knowledge
C WinForm [change the position of the form after running] - Practical Exercise 4
Imx6ull bare metal development learning 1-assembly lit LED
Hardware 1 -- relationship between gain and magnification
Detailed explanation of SQL server stored procedures
Tailq of linked list
Bootloader implementation of PIC MCU
Consul安装
C, Numerical Recipes in C, solution of linear algebraic equations, LU decomposition source program
List of linked lists