C ++ uses the scanf

Recently looked under C ++, c language and in some places still not the same, when I was doing a digital input of an error is found. .

So use scanf () when we need to add the following piece at the top of the header file:

#define _CRT_SECURE_NO_WARNINGS

Seeking primes test code:

#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
using namespace std;

int main()
{
    int i, j;
    int sum;
    cout << "请输入一个数字:\n";
    scanf("%d",&sum);
    cout << "质数为:\n";
    for (i = 2; i<sum; i++) {
        for (j = 2; j <= (i / j); j++) {
            if (i%j==0) {
                 // COUT << << I "is a prime number No \ n-"; 
                BREAK ; // if found, not prime 
            } 
        } 
        
        IF (J> (I / J)) { 
            
            COUT << << I " is a prime number \ n- " ; 
        } 
    } 
    return  0 ; 
}

A key Stud.

Guess you like

Origin www.cnblogs.com/maoye520/p/10985126.html