20 Mart 2013 Çarşamba

Thirth solution of Project Euler






#include "stdafx.h"
#include <iostream>
using namespace std;

int getpow(int i) {
i=i*i*i*i*i;
return i;
}


int check(int dizi[],int i) {
int tot=0;
for(int k=0;k<6;k++) {
if(dizi[k]!=NULL) {
tot+=getpow(dizi[k]);
}
}
if(tot==i) {
return i;
}else {
return 0;
}
}



void make() {
 int result=0;
for(int i=2;i<1000000;i++) {
int * dizi = new int[6],c,k=5;
c=i;
do {
dizi[k]=c%10;
c/=10;
             k--;
}while(k>=0);
result+=check(dizi,i);
}
  cout << "Problem:30\nResult :" << result  << " efekanpulatli.blogspot.com " << endl;
}

int main()
{
make();
   system("pause");
   return 0;
}
 

Fourty fifth solution of Project Euler




                                                 


#include "stdafx.h"
#include <iostream>

using namespace std;

void make() {
 unsigned long tri,penta,hexa;
 bool result=false;
 do {
 for(unsigned long i=0;i<60000;i++) {
  tri = (i*(i+1))/2;
  for(unsigned long k=0;k<i;k++) {
   penta=(k*((3*k)-1))/2;
   if(tri==penta) {
    for(unsigned long l=0;l<k;l++) {
     hexa=l*((2*l)-1);
     if(penta==hexa) {
      result=true;
      if(tri>40775) {
      cout << "Problem:45\nResult :" << tri  << " efekanpulatli.blogspot.com " << endl;
      }
      break;
     }else {
      continue;
     }
    }
   }else {
    continue;
   }
  }
 }
 }while(!result);

}

int main()
{
make();
   system("pause");
   return 0;
}
 

Thirty fourth solution of Project Euler








#include "stdafx.h"
#include <iostream>
using namespace std;
int fakt(int x) {
unsigned long tot=1;
for(;x>0;x--) {
tot*=x;
}
return tot;
};

bool check(int x[],int k,unsigned long y) {
int tot=0,c=0;
do {
tot+=fakt(x[k]);
k--;
}while(k>=0);
if(tot==y) {
return true;
}else {
return false;
}
}



void make() {
int result =0;
for(unsigned long i=10;i<100000;i++) {
int * dizi = new int[15];
int k=0,c=i;
do {
dizi[k] = c % 10;
c/=10;
k++;
}while(c>0);
if(check(dizi,k-1,i)==true) {
result+=i;
cout << i << endl;
}
}
cout << "Result :" << result << " efekanpulatli.blogspot.com" << endl;
}






int main()    {


make();
system("pause");
return 0;
}

19 Mart 2013 Salı

Array to Number && Number to Array




#include "stdafx.h"
#include <iostream>
#include <stdio.h>
using namespace std;
void mainn();
int getpow(int x);
int finddigit(int x);
void numbertoarray(int y);
void arraytonumber(int z[],int size);

void mainn() {            
int a;
 cout << "Enter number:";
 cin >> a;
 numbertoarray(a);
}
int finddigit(int x) {          // to find digit of number
int count=0;
    while(x>1) {
x/=10;
count++;
}
return count;
}
void numbertoarray(int y) {
int size=finddigit(y);
int * seq = new int[finddigit(y)];
int p=finddigit(y)-1;
while(y > 1) {
seq[p] = y % 10;
y/=10;
p--;
}          //now,numbers are inside the seq
cout << "State of number which is inside the array :" << endl;
for(int i=0;i<=(size-1);i++) {
cout << seq[i] << " ";
}
cout << "\n";
arraytonumber(seq,size-1);    //let replace the numbers from array to integral
}

void arraytonumber(int z[],int size) {
int tot=0,i=0;
for(;i<=size;i++) {
tot+=(z[i] * getpow(size-i));
}
cout << "Let's remake it" << endl;
cout << tot;
cout << "\n";
}


int getpow(int x) {
int tot=1;
if(x==0) {
return tot;
}else {
      do {
 tot*=10;
 x--;
 }while(x>0);
  return tot;
}
}

18 Mart 2013 Pazartesi

Guessing game (Challange Program)

Click picture and see more large


---------------------------------------------------efe.h-----------------------------------------------------


#include "stdafx.h"
#include <iostream>
using namespace std;
void process(int min,int max,int tryy);
void lastscreen(int tryy,int tot,int min,int med,bool e);
void screen() {
int min,max,tryy;
cout << "Choose space by entering two numbers(firstly min and then max)" << endl;
cin >> min >> max;
cout << "Hmm your numbers are between " << min << " and " << max << "." << endl;
cout << "Okey,Lets make bet.What is your bet? How many try can I find your number?" << endl;
cin >> tryy;
process(min,max,tryy);
}
void process(int min,int max,int tryy) {
char ans;
int med=(min + max) / 2,tot=0,c;
cout << "Your number is between " << min << " and " << med << " ?\n";
cin >> ans;
bool result=false;


do {
     if(ans=='y') {
if((med-min) == 2) {
 lastscreen(tryy,tot,min,med,true);
 result=true;
 break;
}
tot++;
max=med;
med=(min + max) / 2;
c=med-1;
if(c==min) {   //c never equal min
c+=1;
}
 if((med-min)==1) {
 do {
 
cout << "Is correct answer " << c << " ?" << endl;
cin >> ans;
tot++;
if(ans=='y') {
lastscreen(tryy,tot,c,c,true);
 result=true;
 break;
}
c++;
 }while(result==false);
}
 if(result==false) {
cout << "Your number is between " << min << " and " << med << " ?\n";
cin >> ans;
 }
}else if(ans=='n') {
tot++;
min=med;
med=(min + max) / 2;

 c=min-1;
 if((med-min)==1) {
 do {
  c++;
cout << "Is correct answer " << c << " ?" << endl;
cin >> ans;
tot++;
if(ans=='y') {
lastscreen(tryy,tot,c,c,true);
 result=true;
 break;
}
 }while(result==false);
}
if(result==false) {
 cout << "Your number is between 1111111" << min << " and " << med << " ?\n";
cin >> ans;
  }
}

}while(result==false);

}
void lastscreen(int tryy,int tot,int min,int med,bool e) {
if(tryy<tot) {
cout << "Ahh,You are winner" << endl;
cout << "Answer is " << med << ".I solved it by trying " << tot << " times." << endl;    //answer is med or min it doesn't matter now.
cout << "By the way,You can visit efekanpulatli.blogspot.com" << endl;
}else if(tryy==tot) {
        cout << "What a coincidence,No one is winner!.We are equal.\n";
cout << "Answer is " << med << ".I solved it by trying " << tot << " times."  << endl;          //answer is med or min it doesn't matter now.
cout << "By the way,You can visit you efekanpulatli.blogspot.com" << endl;
}else if(tryy>tot) {
cout << "Ha ha ha get out now!I am the winner!\n";
cout << "Answer is " << med << ".I solved it by trying " << tot << " times."  << endl; //answer is med or min it doesn't matter now.
cout << "By the way,You can visit efekanpulatli.blogspot.com" << endl;
}
}








------------------------------------------------main---------------------------------------------------------





#include "stdafx.h"
#include <iostream>
#include "efe.h"


using namespace std;

int main() {
char anss;
do {
cout << "Hey,Do you wanna play guessing game? y/n" << endl;
cin >> anss;
if(anss == 'n') {
exit (1);
}
}while(anss != 'y') ;
char app='y';
do {
screen();
cout << "\n\nDo you wanna play again? y/n";
cin >> app;
if(app=='y') {
system("cls");
}else {
exit (1);
}
}while(app=='y');
    system("pause");
return 0;
}










Product of 3x2 matrice and 2x3 matrice




#include "stdafx.h"
#include <iostream>
using namespace std;

void giris() {
int seq[3][2],seqn [2][3],k,result[3][3];
    for(int x=0;x<3;x++) {             //dizinin elemanlarına 0 ata
for(int i=0;i<2;i++) {
seq[x][i] = NULL;
   }
}
for(int x=0;x<2;x++) {             //dizinin elemanlarına 0 ata
for(int i=0;i<3;i++) {
seqn[x][i] = NULL;
   }
}

cout << "3x2'lik dizinin elemanlarini girin" << endl;
for(int x=0;x<3;x++) {
for(int i=0;i<2;i++) {
cin >> k;
seq[x][i] = k;
system("cls");
for(int x=0;x<3;x++) {          //ekrani duzenle
for(int i=0;i<2;i++) {
cout << "[" << seq[x][i] << "]" ;

}
cout << endl;
}
   }
}
system("cls");
cout << "Simdi 2x3'lik dizinin elemanlarini girin" << endl;
for(int x=0;x<2;x++) {
for(int i=0;i<3;i++) {
cin >> k;
seqn[x][i] = k;
system("cls");
for(int x=0;x<2;x++) {          //ekrani duzenle
for(int i=0;i<3;i++) {
cout << "[" << seqn[x][i] << "]" ;

}
cout << endl;
}
   }
}
system("cls");







cout << "Bu iki matrisin carpimindan olusan 3x3 luk matris" << endl;
for(int i=0;i<3;i++) {        // [0][x],[1][x],[2][x]
for(int y=0,d=0;y<3;y++,d++)   {
           result[i][y] = (seq[i][0] * seqn[0][d]) + (seq[i][1] * seqn[1][d]);

}
}

for(int i=0;i<3;i++) {    
for(int y=0;y<3;y++)   {
cout << "[" << result[i][y] << "]";

}
cout << endl;
}
}

int main() {
giris();
system("pause");
return 0;
}

8 Mart 2013 Cuma

Twenty fifth solution of Project Euler






#include "stdafx.h"
#include <iostream>
using namespace std;

void findout () {
int x,a[1011],b[1011],tot[1011];
for(int i=0;i<1010;i++) {             //dizilerin elemanlarına 0 koy
a[i] = 0;
b[i] = 0;
tot[i] = 0;
}
a[1009]=1;
a[1010]=3;
b[1009]=2;
b[1010]=1;
for(x=0;x<8888;x++) {
for(int i=1010;i>=0;i--) {
if(a[i] + b[i] <10){
        tot[i] = a[i] + b[i];
}else {   //elde varsa
tot[i] = (a[i] + b[i]) % 10;
a[i-1]+=1;


}
a[i]=b[i];
b[i]=tot[i];
}
if(tot[11]!=0) {
cout << x+9 << " efekanpulatli.blogspot.com" << endl;
break;

}
}

}

int main() {
findout();
system("pause");
return 0;
}