# Write a program to find the Factors of a number

15 May 2022

Write a program to find the Factors of a number

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 an input from the user and find the factors of the number.

Input

4

Output

1,2,4

# C Program

#include <stdio.h>

int main()

{

int num;

printf("Enter the number: ");

scanf("%d",&num);

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

{

if(num%i==0)

printf("%d,",i);

}

return 0;

}

# C++ Program

#include <bits/stdc++.h>

using namespace std;

int main()

{

int num;

cout<<"Enter a number: ";

cin>>num;

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

{

if(num%i==0)

cout<<i<<" ";

}

}

# Java

import java.util.Scanner;

public class Main

{

public static void main(String[] args) {

Scanner sc=new Scanner(System.in);

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

int num=sc.nextInt();

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

{

if(num%i==0)

System.out.print(i+" ");

}

}

}

# Python

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

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

if num%i==0:

print(i, end=" ")

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