Notes![what is notes.io? What is notes.io?](/theme/images/whatisnotesio.png)
![]() ![]() Notes - notes.io |
using namespace std; // Use the standard namespace to avoid writing 'std::' repeatedly
int main() {
int num; // Declare an integer variable to store the number input by the user
int count = 0; // Initialize a counter to count the number of divisors
cout << "Enter a number: "; // Prompt the user for input
cin >> num; // Take the number input from the user
// Loop through all numbers from 1 to the given number
for (int i = 1; i <= num; i++) {
// Check if 'i' divides 'num' without leaving a remainder
if (num % i == 0) {
count++; // If it divides evenly, increment the count
}
}
// Display the total number of divisors
cout << "The number of divisors of " << num << " is: " << count << endl;
return 0; // End of the program
}
#include <iostream>
using namespace std;
bool isPrime(int num) {
if (num <= 1) return false;
for (int i = 2; i * i <= num; i++) {
if (num % i == 0) return false;
}
return true;
}
void generatePrimes(int limit) {
cout << "Prime numbers up to " << limit << ": ";
for (int i = 2; i <= limit; i++) {
if (isPrime(i)) {
cout << i << " ";
}
}
cout << endl;
}
int main() {
int limit;
cout << "Enter the limit: ";
cin >> limit;
generatePrimes(limit);
return 0;
}
#include <iostream> // This header file allows us to use input-output streams like cin and cout.
using namespace std; // This allows us to use standard C++ functions like cout without having to prefix them with std::.
void primeFactorization(int num) { // Function to find and print the prime factors of 'num'.
// Step 1: Check for the number of 2s that divide 'num'.
while (num % 2 == 0) { // While 'num' is divisible by 2, keep dividing it by 2.
cout << 2 << " "; // Print 2 as one of the prime factors.
num /= 2; // Divide 'num' by 2.
}
// Step 2: Now, 'num' must be odd at this point, so we can skip even numbers.
for (int i = 3; i * i <= num; i += 2) { // Start from 3 and check all odd numbers up to the square root of 'num'.
while (num % i == 0) { // While 'num' is divisible by 'i', keep dividing it by 'i'.
cout << i << " "; // Print 'i' as one of the prime factors.
num /= i; // Divide 'num' by 'i'.
}
}
// Step 3: If 'num' is still greater than 2, then 'num' must be a prime number.
if (num > 2) {
cout << num << " "; // Print the remaining prime factor (if any).
}
}
int main() {
int num; // Declare an integer variable 'num' to store the input number.
cout << "Enter a number: "; // Prompt the user to enter a number.
cin >> num; // Read the input number from the user.
cout << "Prime factors of " << num << " are: "; // Print the message indicating the start of prime factorization.
primeFactorization(num); // Call the function to perform prime factorization.
cout << endl; // Print a newline after the prime factors for better formatting.
return 0; // Return 0 to indicate the successful completion of the program.
}
#include<bits/stdc++.h>
using namespace std;
bool isPrime(int num){
if(num<=1){
return false;
}
for(int i=2;i*i<=num;i++){
if(num%i==0){
return false;
}
}
return true;
}
int main(){
int num;
cin>>num;
if(isPrime(num)){
cout<<num<<"is a prime number:"<<endl;
}
else{
cout<<num<<"is not prime number:"<<endl;
}
return 0;
}
#include<bits/stdc++.h>
using namespace std;
int main(){
int num;
cin>>num;
for(int i=1;i<=num;i++){
if(num%i==0){
cout<<i<<endl;
}
}
return 0;
}
![]() |
Notes is a web-based application for online taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000+ notes created and continuing...
With notes.io;
- * You can take a note from anywhere and any device with internet connection.
- * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
- * You can quickly share your contents without website, blog and e-mail.
- * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
- * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.
Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.
Easy: Notes.io doesn’t require installation. Just write and share note!
Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )
Free: Notes.io works for 14 years and has been free since the day it was started.
You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;
Email: [email protected]
Twitter: http://twitter.com/notesio
Instagram: http://instagram.com/notes.io
Facebook: http://facebook.com/notesio
Regards;
Notes.io Team