Take integer and find divisors,prime? & how many divisors

  • Thread starter Thread starter Md. Abde Mannaf
  • Start date Start date
  • Tags Tags
    Integer
AI Thread Summary
The discussion focuses on creating a C program that calculates all divisors of an integer, checks if the number is prime, and counts the total number of divisors. The initial code provided successfully prints the divisors but lacks the functionality to determine if the number is prime and to count the divisors. Suggestions include combining the two separate programs into one cohesive program and optimizing the prime-checking process by only iterating up to the square root of the number. Additionally, there is a reminder to format code properly for better readability in future posts. The main goal is to create a single program that efficiently performs all required tasks: finding divisors, checking for primality, and counting the total number of divisors.
Md. Abde Mannaf
Messages
20
Reaction score
1
write a c programs Take integer and find all divisors/Factors , print is it prime or not? and how many divisors contain print it?
how to solve in one program and how many divisors/Factors
contains

my code:
C:
#include<stdio.h>
#include<conio.h>
#include<math.h>
int main()
{
    int number,i;
    printf("This program calculate Divisors\n ");
    printf("enter number= ");
    scanf("%d",&number);
    printf("Divisors are= ");
    for(i=1;i<=number;i++)
{
    if (number%i==0 )
        {
            printf("%4d",i);
        }
}
    getch();
    return 0;
}

and

#include<stdio.h>

main()
{
int n, c = 2;

printf("Enter a number to check if it is prime\n");
scanf("%d",&n);

for ( c = 2 ; c <= n - 1 ; c++ )
{
if ( n%c == 0 )
{
printf("%d is not prime.\n", n);
break;
}
}
if ( c == n )
printf("%d is prime.\n", n);

return 0;
}
 
Last edited by a moderator:
Technology news on Phys.org
What are the problems you are having?
Also in the future when posting code please use the
Code:
 ['code'] ['/code'] (without the ') tags

it makes the code easier to read
 
Just a comment: You do not have to check further than the square root of n. But since that probably is not an integer use:
Code:
int maxcheck = ceil(sqrt(n));
 
cpscdave said:
What are the problems you are having?
Also in the future when posting code please use the
Code:
 ['code'] ['/code'] (without the ') tags

it makes the code easier to read
how to combine two program in one & how many number of divisor ?? print in program.
 
Thread 'Star maps using Blender'
Blender just recently dropped a new version, 4.5(with 5.0 on the horizon), and within it was a new feature for which I immediately thought of a use for. The new feature was a .csv importer for Geometry nodes. Geometry nodes are a method of modelling that uses a node tree to create 3D models which offers more flexibility than straight modeling does. The .csv importer node allows you to bring in a .csv file and use the data in it to control aspects of your model. So for example, if you...
I tried a web search "the loss of programming ", and found an article saying that all aspects of writing, developing, and testing software programs will one day all be handled through artificial intelligence. One must wonder then, who is responsible. WHO is responsible for any problems, bugs, deficiencies, or whatever malfunctions which the programs make their users endure? Things may work wrong however the "wrong" happens. AI needs to fix the problems for the users. Any way to...
Back
Top