Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
#include <stdio.h>
#include <stdlib.h>
int altamenteComposto(int n, int *d);
int contaDivisori(int n);
int main()
{
int k, d;
scanf("%d", &k);
if(altamenteComposto(k, &d) == 0) {
printf("\nIl numero %d è altamente composto, avendo %d divisori\n", k, d);
} else {
printf("\nIl numero %d NON è altamente composto pur avendo %d divisori\n", k, d);
}
return 0;
}
int altamenteComposto(int n, int *d) {
int flag = 1;
*d = contaDivisori(n);
for(int i = n; i >= 1; i--) {
if(contaDivisori(n) >= contaDivisori(i)) {
flag = 0;
} else { break; }
}
return flag;
}
// Funzione che conta il numero di divisori di un intero N
int contaDivisori(int n) {
int counter = 0;
for(int i = 1; i <= n; i++) {
if(n%i == 0)
counter++;
}
return counter;
}
Advertisements
We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.
AcceptLearn more