当前位置:网站首页>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 :

边栏推荐
- UEFI development learning 5 - simple use of protocol
- Measurement fitting based on Halcon learning [III] PM_ measure_ board. Hdev routine
- Naming rules for FreeRTOS
- How to select conductive slip ring
- [trio basic tutorial 17 from getting started to mastering] set up and connect the trio motion controller and input the activation code
- QEMU demo makefile analysis
- Interview catalogue
- [untitled] record the visual shock of the Winter Olympics and the introduction of the display screen
- C language enhancement -- pointer
- Some tips for using source insight (solve the problem of selecting all)
猜你喜欢

Carrier period, electrical speed, carrier period variation

More than 90% of hardware engineers will encounter problems when MOS tubes are burned out!
![Measurement fitting based on Halcon learning [i] fuse Hdev routine](/img/91/34c92065e797c87d6ce5ea13903993.jpg)
Measurement fitting based on Halcon learning [i] fuse Hdev routine
![C WinForm [exit application] - practice 3](/img/25/30c795cc3fa6931eb1d733719d4ad0.jpg)
C WinForm [exit application] - practice 3

How to select conductive slip ring

Stablq of linked list
![Shape template matching based on Halcon learning [viii] PM_ multiple_ models. Hdev routine](/img/13/22a1915329f58acd54c40176f6f301.jpg)
Shape template matching based on Halcon learning [viii] PM_ multiple_ models. Hdev routine

UEFI development learning 6 - creation of protocol

On boost circuit

Talk about the function of magnetic beads in circuits
随机推荐
C, Numerical Recipes in C, solution of linear algebraic equations, LU decomposition source program
STM32 outputs 1PPS with adjustable phase
1-stm32 operation environment construction
UEFI development learning 2 - running ovmf in QEMU
Communication standard -- communication protocol
Relationship between line voltage and phase voltage, line current and phase current
Use indent to format code
Consul安装
DCDC circuit - function of bootstrap capacitor
Drive LED -- GPIO control
Explain task scheduling based on Cortex-M3 in detail (Part 1)
My-basic application 2: my-basic installation and operation
Talk about the circuit use of TVs tube
Basic information commands and functions of kernel development
Soem EtherCAT source code analysis attachment 1 (establishment of communication operation environment)
导电滑环磨损快的原因
Step motor generates S-curve upper computer
Network communication process
[cloud native | learn kubernetes from scratch] III. kubernetes cluster management tool kubectl
Sql Server的存储过程详解