|
| 1 | +/** |
| 2 | +* P71 : چاپ میانگین مقسوم علیه های اول یک عدد |
| 3 | +* |
| 4 | +* @author Gholamali Nejad Hajali Irani |
| 5 | +* @version 1.0 |
| 6 | +* @since 2021年01月19日 |
| 7 | +* @Team gClassAcademy |
| 8 | +* @Website https://www.youtube.com/c/gClassAcademy |
| 9 | +* |
| 10 | +*/ |
| 11 | + |
| 12 | +import java.util.Scanner; |
| 13 | + |
| 14 | +public class P71 |
| 15 | +{ |
| 16 | + public static void main(String[] args) |
| 17 | + { |
| 18 | + Scanner input=new Scanner (System.in); |
| 19 | + |
| 20 | + System.out.println("Enter n:"); |
| 21 | + int n=input.nextInt(); // عددی که از کاربر گرفته می شود |
| 22 | + |
| 23 | + |
| 24 | + int allcount=0; //تعداد مقسوم علیه های اول |
| 25 | + int sum=0; //جمع مقسوم علیه های اول |
| 26 | + |
| 27 | + for (int x=1;x<=n;x++) |
| 28 | + if (n%x==0) // اگر x مقسوم علیه بود |
| 29 | + { |
| 30 | + // بررسی اول بودن x |
| 31 | + int count=0; |
| 32 | + for (int y=1;y<=x;y++) |
| 33 | + if (x%y==0) |
| 34 | + count++; |
| 35 | + |
| 36 | + if (count==2) //x اول هست |
| 37 | + { |
| 38 | + System.out.println(x); |
| 39 | + allcount++; |
| 40 | + sum+=x; |
| 41 | + } |
| 42 | + |
| 43 | + }//end of if n%x==0 |
| 44 | + |
| 45 | + System.out.println("Count of Primes is: " + allcount); |
| 46 | + System.out.println("Sum of Primes is: " + sum); |
| 47 | + if (allcount==0) |
| 48 | + System.out.println("تعداد مقسوم علیه های اول صفر است هااا"); |
| 49 | + else |
| 50 | + System.out.println("Avg of Primes is: " + 1.0*sum/allcount); |
| 51 | + |
| 52 | + |
| 53 | + |
| 54 | + }// end of main |
| 55 | +}// end of class |
| 56 | + |
| 57 | + |
| 58 | + |
| 59 | + |
| 60 | + |
| 61 | + |
| 62 | + |
| 63 | + |
| 64 | + |
0 commit comments