# Write a program to find number of integers which has exactly 9 divisors

19 July 2022

Write a program to find number of integers which has exactly 9 divisors

If you are from 2023 batch student, Join our Telegram group for placement preparation and coming placement drive updates : https://t.me/talentbattle2023

# Description

Get a number as input from the user and check within that number how many numbers are there with exactly 9 divisors.

Input

40

Output

1

C Program

#include <stdio.h>

int numberOfDivisors(int num)

{

int c=0;

for(int i=1;i<=num;i++)

{

if(num%i==0)

c +=1;

}

return c;

}

int countNumbers(int n)

{

int c=0;

for(int i=1;i<=n;i++)

{

if(numberOfDivisors(i)==9)

c += 1;

}

return c;

}

int main()

{

int num;

printf("Enter the number: ");

scanf("%d",&num);

printf("%d",countNumbers(num));

return 0;

}

C++ Program

#include <iostream>

using namespace std;

int numberOfDivisors(int num)

{

int c=0;

for(int i=1;i<=num;i++)

{

if(num%i==0)

c +=1;

}

return c;

}

int countNumbers(int n)

{

int c=0;

for(int i=1;i<=n;i++)

{

if(numberOfDivisors(i)==9)

c += 1;

}

return c;

}

int main()

{

int num;

cout<<"Enter the number: ";

cin>>num;

cout<<countNumbers(num);

return 0;

}

Java Program

import java.util.Scanner;

public class Main

{

static int numberOfDivisors(int num)

{

int c=0;

for(int i=1;i<=num;i++)

{

if(num%i==0)

c +=1;

}

return c;

}

static int countNumbers(int n)

{

int c=0;

for(int i=1;i<=n;i++)

{

if(numberOfDivisors(i)==9)

c += 1;

}

return c;

}

public static void main(String[] args) {

Scanner sc = new Scanner(System.in);

System.out.println("Enter a number: ");

int num=sc.nextInt();

System.out.println(countNumbers(num));

}

}

Python Program

def numberOfDivisors(n):

c=0

for i in range(1,n+1):

if n%i==0:

c=c+1

return c

def countNumbers(n):

c=0

for i in range(1,n+1):

if(numberOfDivisors(i)==9):

c=c+1

return c

num=int(input("Enter a number: "))

print(countNumbers(num))

If you are from 2023 batch student, Join our Telegram group for placement preparation and coming placement drive updates : https://t.me/talentbattle2023