Pagini recente » Cod sursa (job #1355071) | Cod sursa (job #1093906) | Profil bubblegumix | Cod sursa (job #2188850) | Cod sursa (job #681738)
Cod sursa(job #681738)
#include<iostream>
#include<fstream>
using namespace std;
int cmmdc(int x,int y){
while(x!=y){
if(x>y)
x=x-y;
else
y=y-x;
}
if(x==1)
return 1;
else return 0;
}
int main(){
unsigned int n;
ifstream in_file;
ofstream out_file;
in_file.open("fractii.in");
out_file.open("fractii.out");
unsigned int i;
unsigned int j;
unsigned int counter=0;
if(!out_file.is_open()){
cout<<"error at opening outfile"<<endl;
return 0;
}
if(!in_file.is_open()){
cout<<"error at opening infile"<<endl;
system("PAUSE");
return 0;
}
in_file>>n;
cout<<n;
for(i=1;i<=n;i++)
for(j=1;j<=n;j++)
if(cmmdc(i,j)){
counter++;
}
out_file<<counter<<endl;
system("PAUSE");
return 0;
}