#include<iostream>//nodrošina ievad-izvadierīču lietošanu using namespace std;//tiks lietots vārdkopu apgabals std objektiem int savstpirmsk(int sk); int main() { int sk; int *arr; cout << "LD3" << endl; cout << "Programma lauj ievadit skaitlu virkni un izvada visus virknes skaitlus,"<<endl; cout << "kuri ir savstarpeji pirmskaitli"<<endl; cout << endl; cout<<"Cik skaitlus velies ievadit?"<<endl; cin>>sk; arr = new int[sk]; for (int i=0;i<sk;i++) { cout<<"Ievadi "<<i+1<<". skaitli "<<endl; cin>>arr[i];//skaitļu ievade cout<<endl; } cout<<"Savstarpeji pirmskaitlu pari ir "<<savstpirmsk(sk)<<endl; delete[] arr; cout<<endl; system("pause"); return 0; }// main funkcijas beigas int savstpirmsk(int sk) {for (int i=0;i<sk-1;i++) {for (int j=i+1;j<sk-1;j++) {int arr[i]; int arr2[j]; if ((arr[i]*2%arr2[j]!=0)||(arr2[j]*2%arr[i]!=0)) return arr[i]; } } } |
In mathematics, two integers a and b are said to be coprime or relatively prime if they have no common positive factor other than 1 or, equivalently, if their greatest common divisor is 1. |
#include<iostream>//nodrošina ievad-izvadierīču lietošanu using namespace std;//tiks lietots vārdkopu apgabals std objektiem int savstpirmsk(int sk,int arr[]); int main() { bool pirmsk=true; int sk; int *arr; cout << "LD3" << endl; cout << "Programma lauj ievadit skaitlu virkni un izvada visus virknes skaitlus,"<<endl; cout << "kuri ir savstarpeji pirmskaitli"<<endl; cout << endl; cout<<"Cik skaitlus velies ievadit?"<<endl; cin>>sk; arr = new int[sk]; for (int i=0;i<sk;i++) { cout<<"Ievadi "<<i+1<<". skaitli "<<endl; cin>>arr[i];//skaitļu ievade cout<<endl; } {for (int i=0;i<sk;i++) {for (int j=0;j<sk;j++) if (arr[i]<=arr[j]) {for (int i=0;i<sk;i++) {for (int j=0;j<sk;j++) {for (int k=2;k<arr[i];k++) if ((arr[i]%k==0) && (arr[j]%k==0)) {pirmsk=false; break; } } } } cout<<"Savstarpeji pirmskaitlu pari ir "<<savstpirmsk(sk,arr)<<endl; delete[] arr; cout<<endl; system("pause"); return 0; }// main funkcijas beigas int savstpirmsk(int sk,int arr[]) { if (pirmsk) for (int i=0;i<sk;i++) {for (int j=0;j<sk;j++) return arr[i]; } } } |
|
|