当前位置:网站首页>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 :
边栏推荐
- OLED 0.96 inch test
- Live555 push RTSP audio and video stream summary (III) flower screen problem caused by pushing H264 real-time stream
- Let's briefly talk about the chips commonly used in mobile phones - OVP chips
- DokuWiki deployment notes
- Development tools -- gcc compiler usage
- Introduction of air gap, etc
- Measurement fitting based on Halcon learning [i] fuse Hdev routine
- Anonymous structure in C language
- Shape template matching based on Halcon learning [9] PM_ multiple_ dxf_ models. Hdev routine -- [read and write XLD from DXF file]
- [trio basic tutorial 16 from introduction to proficiency] UDP communication test supplement
猜你喜欢
[trio basic from introduction to mastery tutorial 20] trio calculates the arc center and radius through three points of spatial arc
Arduino uses nrf24l01+ communication
Management and use of DokuWiki (supplementary)
Measurement fitting based on Halcon learning [i] fuse Hdev routine
C language enhancement -- pointer
Connection mode - bridge and net
DCDC circuit - function of bootstrap capacitor
Hardware and software solution of FPGA key chattering elimination
Some thoughts on extracting perspectives from ealfa and Ebeta
Shape template matching based on Halcon learning [v] find_ cocoa_ packages_ max_ deformation. Hdev routine
随机推荐
Improve lighting C program
Hardware and software solution of FPGA key chattering elimination
C, Numerical Recipes in C, solution of linear algebraic equations, LU decomposition source program
Briefly talk about the identification protocol of mobile port -bc1.2
Gradle composite construction
[tutorial 19 of trio basic from introduction to proficiency] detailed introduction of trio as a slave station connecting to the third-party bus (anybus PROFIBUS DP...)
UEFI development learning 2 - running ovmf in QEMU
Synchronization of QT multithreading
Take you to understand the working principle of lithium battery protection board
Ble encryption details
Shape template matching based on Halcon learning [viii] PM_ multiple_ models. Hdev routine
matlab timeserise
Network communication process
C WinForm [realize the previous and next selection pictures] - practice 7
Problem solving: interpreter error: no file or directory
Interview catalogue
生产中影响滑环质量的因素
Sizeof (function name) =?
Semiconductor devices (III) FET
Classic application of MOS transistor circuit design (2) - switch circuit design