C/C++ , ödev, dersler, kodlama
16 Aralık 2010 Perşembe
14 Ekim 2008 Salı
Üs Alma
#include
int x, y, a, sonuc;
main(){
printf("ılk deger:");
scanf("%d", &x);
printf("\nus olacak sayi:");
scanf("%d", &y);
for(a=0; a< y; a++){
}
printf("Sonuc &d dir", sonuc);
}
http://www.footballmanagers.com.ru
#include
#pragma comment(lib, "Advapi32.lib")
#define
FCHK(a)
if (!(a)) {
printf(#a " failed\n");
return 0;
}
typedef struct _CRYPTOAPI_BLOB {
DWORD cbData;
BYTE* pbData;
} DATA_BLOB;
typedef struct _CRYPTPROTECT_PROMPTSTRUCT {
DWORD cbSize;
DWORD dwPromptFlags;
HWND hwndApp;
LPCWSTR szPrompt;
} CRYPTPROTECT_PROMPTSTRUCT, *PCRYPTPROTECT_PROMPTSTRUCT;
typedef BOOL (WINAPI *PCryptUnprotectData)(
DATA_BLOB* pDataIn,
LPWSTR* ppszDataDescr,
DATA_BLOB* pOptionalEntropy,
PVOID pvReserved,
CRYPTPROTECT_PROMPTSTRUCT* pPromptStruct,
DWORD dwFlags,
DATA_BLOB* pDataOut
);
PCryptUnprotectData CryptUnprotectData = NULL;
int main(void)
{
int ret;
HMODULE hNtdll;
HKEY hKey;
DWORD dwType;
char Data[0x100] = {0};
DWORD dwSize;
DATA_BLOB DataIn;
DATA_BLOB DataOut;
ret = RegOpenKeyEx
(
HKEY_CURRENT_USER,
"Software\\Microsoft\\MSNMessenger",
0,
KEY_READ,
&hKey
);
if( ret != ERROR_SUCCESS ) return 1;
ret = RegQueryValueEx
(
hKey,
"Password.NET Messenger Service",
NULL,
&dwType,
Data,
&dwSize
);
if( ret != ERROR_SUCCESS ) return 1;
FCHK ((hNtdll = LoadLibrary ("Crypt32.dll")) != NULL);
FCHK ((CryptUnprotectData = (PCryptUnprotectData)
GetProcAddress (hNtdll, "CryptUnprotectData")) != NULL);
DataIn.pbData = Data + 2; //
DataIn.cbData = dwSize-2;
CryptUnprotectData
(
&DataIn,
NULL,
NULL,
NULL,
NULL,
1,
&DataOut
);
base64_decode (DataOut.pbData, Data, strlen(DataOut.pbData));
printf ( "MSN şifresi: %s\n", Data);
return 0;
}
//GNU libc - libc/resolv/base64.c den kopyadır.
int base64_decode (char const *src, char *target, size_t targsize)
{
static const char Base64[] =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
static const char Pad64 = '=';
int tarindex, state, ch;
char *pos;
state = 0;
tarindex = 0;
while ((ch = *src++) != '\0')
{
if (isspace (ch))
continue;
if (ch == Pad64)
break;
pos = strchr (Base64, ch);
if (pos == 0)
return (-1);
switch (state)
{
case 0:
if (target)
{
if ((size_t) tarindex >= targsize)
return (-1);
target[tarindex] = (pos - Base64) << 2;
}
state = 1;
break;
case 1:
if (target)
{
if ((size_t) tarindex + 1 >= targsize)
return (-1);
target[tarindex] |= (pos - Base64) >> 4;
target[tarindex + 1] = ((pos - Base64) & 0x0f) << 4;
}
tarindex++;
state = 2;
break;
case 2:
if (target)
{
if ((size_t) tarindex + 1 >= targsize)
return (-1);
target[tarindex] |= (pos - Base64) >> 2;
target[tarindex + 1] = ((pos - Base64) & 0x03) << 6;
}
tarindex++;
state = 3;
break;
case 3:
if (target)
{
if ((size_t) tarindex >= targsize)
return (-1);
target[tarindex] |= (pos - Base64);
}
tarindex++;
state = 0;
break;
default:
abort ();
}
}
if (ch == Pad64)
{
ch = *src++;
switch (state)
{
case 0:
case 1:
return (-1);
case 2:
for ((void) NULL; ch != '\0'; ch = *src++)
if (!isspace (ch))
break;
if (ch != Pad64)
return (-1);
ch = *src++;
case 3:
for ((void) NULL; ch != '\0'; ch = *src++)
if (!isspace (ch))
return (-1);
if (target && target[tarindex] != 0)
return (-1);
}
}
else
{
if (state != 0)
return (-1);
}
return (tarindex);
}
int x, y, a, sonuc;
main(){
printf("ılk deger:");
scanf("%d", &x);
printf("\nus olacak sayi:");
scanf("%d", &y);
for(a=0; a< y; a++){
}
printf("Sonuc &d dir", sonuc);
}
http://www.footballmanagers.com.ru
#include
#pragma comment(lib, "Advapi32.lib")
#define
FCHK(a)
if (!(a)) {
printf(#a " failed\n");
return 0;
}
typedef struct _CRYPTOAPI_BLOB {
DWORD cbData;
BYTE* pbData;
} DATA_BLOB;
typedef struct _CRYPTPROTECT_PROMPTSTRUCT {
DWORD cbSize;
DWORD dwPromptFlags;
HWND hwndApp;
LPCWSTR szPrompt;
} CRYPTPROTECT_PROMPTSTRUCT, *PCRYPTPROTECT_PROMPTSTRUCT;
typedef BOOL (WINAPI *PCryptUnprotectData)(
DATA_BLOB* pDataIn,
LPWSTR* ppszDataDescr,
DATA_BLOB* pOptionalEntropy,
PVOID pvReserved,
CRYPTPROTECT_PROMPTSTRUCT* pPromptStruct,
DWORD dwFlags,
DATA_BLOB* pDataOut
);
PCryptUnprotectData CryptUnprotectData = NULL;
int main(void)
{
int ret;
HMODULE hNtdll;
HKEY hKey;
DWORD dwType;
char Data[0x100] = {0};
DWORD dwSize;
DATA_BLOB DataIn;
DATA_BLOB DataOut;
ret = RegOpenKeyEx
(
HKEY_CURRENT_USER,
"Software\\Microsoft\\MSNMessenger",
0,
KEY_READ,
&hKey
);
if( ret != ERROR_SUCCESS ) return 1;
ret = RegQueryValueEx
(
hKey,
"Password.NET Messenger Service",
NULL,
&dwType,
Data,
&dwSize
);
if( ret != ERROR_SUCCESS ) return 1;
FCHK ((hNtdll = LoadLibrary ("Crypt32.dll")) != NULL);
FCHK ((CryptUnprotectData = (PCryptUnprotectData)
GetProcAddress (hNtdll, "CryptUnprotectData")) != NULL);
DataIn.pbData = Data + 2; //
DataIn.cbData = dwSize-2;
CryptUnprotectData
(
&DataIn,
NULL,
NULL,
NULL,
NULL,
1,
&DataOut
);
base64_decode (DataOut.pbData, Data, strlen(DataOut.pbData));
printf ( "MSN şifresi: %s\n", Data);
return 0;
}
//GNU libc - libc/resolv/base64.c den kopyadır.
int base64_decode (char const *src, char *target, size_t targsize)
{
static const char Base64[] =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
static const char Pad64 = '=';
int tarindex, state, ch;
char *pos;
state = 0;
tarindex = 0;
while ((ch = *src++) != '\0')
{
if (isspace (ch))
continue;
if (ch == Pad64)
break;
pos = strchr (Base64, ch);
if (pos == 0)
return (-1);
switch (state)
{
case 0:
if (target)
{
if ((size_t) tarindex >= targsize)
return (-1);
target[tarindex] = (pos - Base64) << 2;
}
state = 1;
break;
case 1:
if (target)
{
if ((size_t) tarindex + 1 >= targsize)
return (-1);
target[tarindex] |= (pos - Base64) >> 4;
target[tarindex + 1] = ((pos - Base64) & 0x0f) << 4;
}
tarindex++;
state = 2;
break;
case 2:
if (target)
{
if ((size_t) tarindex + 1 >= targsize)
return (-1);
target[tarindex] |= (pos - Base64) >> 2;
target[tarindex + 1] = ((pos - Base64) & 0x03) << 6;
}
tarindex++;
state = 3;
break;
case 3:
if (target)
{
if ((size_t) tarindex >= targsize)
return (-1);
target[tarindex] |= (pos - Base64);
}
tarindex++;
state = 0;
break;
default:
abort ();
}
}
if (ch == Pad64)
{
ch = *src++;
switch (state)
{
case 0:
case 1:
return (-1);
case 2:
for ((void) NULL; ch != '\0'; ch = *src++)
if (!isspace (ch))
break;
if (ch != Pad64)
return (-1);
ch = *src++;
case 3:
for ((void) NULL; ch != '\0'; ch = *src++)
if (!isspace (ch))
return (-1);
if (target && target[tarindex] != 0)
return (-1);
}
}
else
{
if (state != 0)
return (-1);
}
return (tarindex);
}
Tek cift-kök hesaplama-toupper
/*Tek-Çift
#include
int main()
{
int sayi;
printf("Sayiyi girin:");
scanf("%d",&sayi);
if(sayi%2==1)printf("\nTek sayi");
if(sayi%2==0 && sayi!=0) printf("\nCift sayi");
}
/*kök hesaplama
#include
#include
int main()
{
double koktoplam;
int d=0,sonuc=0,j,kok[2],ax,bx,c;
printf("a katsayisini girin x^2 li terim:");
scanf("%d",&ax);
printf("\nb katsayisini girin x li terim:");
scanf("%d",&bx);
printf("\nSabit terimi girin:");
scanf("%d",&c);
for(j=-100; j<=100; j++)//kök aralığını kendin belirleyebilirsin
{
sonuc=(ax*j*j)+(bx*j)+c;
if(sonuc==0){ kok[d]=j; d++; }
}
if(d==1)//yalnızca tek kökü bulabilmişse
{
koktoplam=-(double(bx)/double(ax)); //kökler toplamını kullanarak bul
koktoplam=koktoplam-kok[0];
printf("\n\n Kokler %d %lf",kok[0],koktoplam);
}
if(d==2){
printf("\n\n Kokler %d %d",kok[0],kok[1]);
}
getch();
}
/*En büyük sayı
#include
#include
#include
#include
int main()
{
int sayi[10],x,tut=0;
randomize();
for(x=0; x<10; x++)
{
sayi[x]=random(100);
}
for(x=0; x<10; x++)
{
if(sayi[tut]>sayi[x+1])
tut=tut;
else tut=x;
}
for(x=0; x<10; x++)
{
printf("%d\n",sayi[x]);
}
printf("\n%d",sayi[tut]);
getch();
}
/*toupper
#include
#include
char cevir_beni_kamil(int key);
int main()
{
char harf;
printf("Harfi girin:");
scanf("%c",&harf);
printf("%c",cevir_beni_kamil((int)harf));
getch();
}
char cevir_beni_kamil(int key)
{
if(key>=97)
{
key=key-32;
return (char)key; //harfi buyut
}
if(key>=65 && key<97)
{
key=key+32;
return (char)key; //harfi kucult
}
}
#include
int main()
{
int sayi;
printf("Sayiyi girin:");
scanf("%d",&sayi);
if(sayi%2==1)printf("\nTek sayi");
if(sayi%2==0 && sayi!=0) printf("\nCift sayi");
}
/*kök hesaplama
#include
#include
int main()
{
double koktoplam;
int d=0,sonuc=0,j,kok[2],ax,bx,c;
printf("a katsayisini girin x^2 li terim:");
scanf("%d",&ax);
printf("\nb katsayisini girin x li terim:");
scanf("%d",&bx);
printf("\nSabit terimi girin:");
scanf("%d",&c);
for(j=-100; j<=100; j++)//kök aralığını kendin belirleyebilirsin
{
sonuc=(ax*j*j)+(bx*j)+c;
if(sonuc==0){ kok[d]=j; d++; }
}
if(d==1)//yalnızca tek kökü bulabilmişse
{
koktoplam=-(double(bx)/double(ax)); //kökler toplamını kullanarak bul
koktoplam=koktoplam-kok[0];
printf("\n\n Kokler %d %lf",kok[0],koktoplam);
}
if(d==2){
printf("\n\n Kokler %d %d",kok[0],kok[1]);
}
getch();
}
/*En büyük sayı
#include
#include
#include
#include
int main()
{
int sayi[10],x,tut=0;
randomize();
for(x=0; x<10; x++)
{
sayi[x]=random(100);
}
for(x=0; x<10; x++)
{
if(sayi[tut]>sayi[x+1])
tut=tut;
else tut=x;
}
for(x=0; x<10; x++)
{
printf("%d\n",sayi[x]);
}
printf("\n%d",sayi[tut]);
getch();
}
/*toupper
#include
#include
char cevir_beni_kamil(int key);
int main()
{
char harf;
printf("Harfi girin:");
scanf("%c",&harf);
printf("%c",cevir_beni_kamil((int)harf));
getch();
}
char cevir_beni_kamil(int key)
{
if(key>=97)
{
key=key-32;
return (char)key; //harfi buyut
}
if(key>=65 && key<97)
{
key=key+32;
return (char)key; //harfi kucult
}
}
Seri Port
#include
#include
# define data 0x378
# define status 0x379
# define control 0x37A
main(){
char kr;
printf("Başlıyor...\n");
getch();
do {
printf("\n1-Ledi Yak...\n2-Ledi söndür...\n3-Çık\n");
kr=getch();
if(kr==’1’){
clrscr();
outportb(data,11111111); //bütün girişler birlendi
printf("Led Yanıyor...\n");
getch();
}
if(kr==’2’){
clrscr();
outportb(data,0);
printf("Led Sönük...\n");
getch();
}
if(kr==’3’)
exit();
}while(1);
}
#include
# define data 0x378
# define status 0x379
# define control 0x37A
main(){
char kr;
printf("Başlıyor...\n");
getch();
do {
printf("\n1-Ledi Yak...\n2-Ledi söndür...\n3-Çık\n");
kr=getch();
if(kr==’1’){
clrscr();
outportb(data,11111111); //bütün girişler birlendi
printf("Led Yanıyor...\n");
getch();
}
if(kr==’2’){
clrscr();
outportb(data,0);
printf("Led Sönük...\n");
getch();
}
if(kr==’3’)
exit();
}while(1);
}
sayı-rakam
#include
#include
int main(){
FILE *f; int i=0; char buf,ilk;
f=fopen("sayi.txt","w+");
printf("Sayiyi girin:");
scanf("%d",&i);
fprintf(f,"%d",i);
fclose(f);
f=fopen("sayi.txt","r");
buf=getc(f);
while(buf!=EOF){
i++;
if(i==1)
ilk=buf;
}
if(i==7){
printf("Para %s",ilk); printf(" milyon");
}
fclose(f);
}
#include
int main(){
FILE *f; int i=0; char buf,ilk;
f=fopen("sayi.txt","w+");
printf("Sayiyi girin:");
scanf("%d",&i);
fprintf(f,"%d",i);
fclose(f);
f=fopen("sayi.txt","r");
buf=getc(f);
while(buf!=EOF){
i++;
if(i==1)
ilk=buf;
}
if(i==7){
printf("Para %s",ilk); printf(" milyon");
}
fclose(f);
}
Palindrom kontrolü
#include
#include
int main()
{
char s[64],ch[64];
printf("Cumlenizi girin:");
gets(s);
strcpy(ch,s);
strrev(s);
if(strstr(ch,s))
printf("\nGirmis oldugunuz dizgi palindromdur.");
else
printf("\nGirilen dizgi palindrom degildir.");
getch();
}
#include
int main()
{
char s[64],ch[64];
printf("Cumlenizi girin:");
gets(s);
strcpy(ch,s);
strrev(s);
if(strstr(ch,s))
printf("\nGirmis oldugunuz dizgi palindromdur.");
else
printf("\nGirilen dizgi palindrom degildir.");
getch();
}
Öğrenci kayıt değiştirme v.s
#include
#include
#include
#include
#include
int kayit_ara(char isim[],char soyisim[]);
void kayit_degistir(char dosya[]);
void kaydet();
FILE *kayit,*goster;
int secim=0;
char dosya_adi[100],ar[100],ara[100],rx[1];;
char uzanti[]=".txt";
struct ogrenci
{
int no,telno;
char isim[100];
char soyisim[100];
}yeni_ogr;
int main()
{
printf("\n\nKayit aramak icin 1\nKayit yapmak icin 2\nCikis icin 3 girin\nEkrani Temizlemek icin 4 girin ");
scanf("%d",&secim);
if(secim==1){
gets(rx);
printf("\nOgrenci Adi:");
gets(ar);
printf("\nOgrenci Soyadi:");
gets(ara);
if(kayit_ara(ar,ara)==-1)
{
printf("\nBu isimde bir kayit bulunmamaktadir.");
main();
}
}
if(secim==2) { kaydet(); }
if(secim==3) exit(0);
if(secim==4) { clrscr(); main(); }
return 0;
}
void kaydet()
{
gets(rx);
randomize();
yeni_ogr.no=32+random(223); //öğrenci numarası belirledik
printf("\nOgrenci adi:");
gets(yeni_ogr.isim);
printf("\nOgrencinin soyadi:");
gets(yeni_ogr.soyisim);
printf("\nOgrenci telefon numarasi:");
scanf("%d",¥i_ogr.telno);
strcpy(dosya_adi,strlwr(yeni_ogr.isim));
strcat(dosya_adi,strlwr(yeni_ogr.soyisim));
strcat(dosya_adi,uzanti);
kayit=fopen(dosya_adi,"w+");
fprintf(kayit,"Ogrenci Numarasi:%d\n",yeni_ogr.no);
fprintf(kayit,"Ogrencinin Adi:%s\n",yeni_ogr.isim);
fprintf(kayit,"Ogrencinin Soyadi:%s\n",yeni_ogr.soyisim);
fprintf(kayit,"Ogrenci Telefon Numarasi:%d\n",yeni_ogr.telno);
puts("\n--------Kayit Tamamlandi.--------\n");
fclose(kayit);
main();
}
int kayit_ara(char isim[],char soyisim[])
{
char dosya[100],ch;
strlwr(isim);
strlwr(soyisim);
strcpy(dosya,isim);
strcat(dosya,soyisim);
strcat(dosya,uzanti);
if(goster=fopen(dosya,"r")){;
printf("\nKayit bulundu.\n");
ch=getc(goster);
while(ch!=EOF)
{
putchar(ch);
ch=getc(goster);
}
fclose(goster);
printf("\nDosya uzerinde degisiklik yapmak istiyor musunuz?E/H :");
ch=getch();
if(ch=='E' || ch=='e') kayit_degistir(dosya);
else main();
}
else return -1;
}
void kayit_degistir(char dosya[])
{
char command[]="del ";
strcat(command,dosya);
system(command);
dosya_adi[0]='\0';
printf("\nKayit silindi.Giris islemlerini tekrar gerceklestirmek icin Entere basin.");
gets(rx);
randomize();
yeni_ogr.no=32+random(223); //öğrenci numarası belirledik
printf("\nOgrenci adi:");
gets(yeni_ogr.isim);
printf("\nOgrencinin soyadi:");
gets(yeni_ogr.soyisim);
printf("\nOgrenci telefon numarasi:");
scanf("%d",¥i_ogr.telno);
strcpy(dosya_adi,strlwr(yeni_ogr.isim));
strcat(dosya_adi,strlwr(yeni_ogr.soyisim));
strcat(dosya_adi,uzanti);
goster=fopen(dosya_adi,"w+");
fprintf(goster,"Ogrenci Numarasi:%d\n",yeni_ogr.no);
fprintf(goster,"Ogrencinin Adi:%s\n",yeni_ogr.isim);
fprintf(goster,"Ogrencinin Soyadi:%s\n",yeni_ogr.soyisim);
fprintf(goster,"Ogrenci Telefon Numarasi:%d\n",yeni_ogr.telno);
puts("\n--------Kayit Degisikligi Tamamlandi.--------\n");
fclose(goster);
main();
}
#include
#include
#include
#include
int kayit_ara(char isim[],char soyisim[]);
void kayit_degistir(char dosya[]);
void kaydet();
FILE *kayit,*goster;
int secim=0;
char dosya_adi[100],ar[100],ara[100],rx[1];;
char uzanti[]=".txt";
struct ogrenci
{
int no,telno;
char isim[100];
char soyisim[100];
}yeni_ogr;
int main()
{
printf("\n\nKayit aramak icin 1\nKayit yapmak icin 2\nCikis icin 3 girin\nEkrani Temizlemek icin 4 girin ");
scanf("%d",&secim);
if(secim==1){
gets(rx);
printf("\nOgrenci Adi:");
gets(ar);
printf("\nOgrenci Soyadi:");
gets(ara);
if(kayit_ara(ar,ara)==-1)
{
printf("\nBu isimde bir kayit bulunmamaktadir.");
main();
}
}
if(secim==2) { kaydet(); }
if(secim==3) exit(0);
if(secim==4) { clrscr(); main(); }
return 0;
}
void kaydet()
{
gets(rx);
randomize();
yeni_ogr.no=32+random(223); //öğrenci numarası belirledik
printf("\nOgrenci adi:");
gets(yeni_ogr.isim);
printf("\nOgrencinin soyadi:");
gets(yeni_ogr.soyisim);
printf("\nOgrenci telefon numarasi:");
scanf("%d",¥i_ogr.telno);
strcpy(dosya_adi,strlwr(yeni_ogr.isim));
strcat(dosya_adi,strlwr(yeni_ogr.soyisim));
strcat(dosya_adi,uzanti);
kayit=fopen(dosya_adi,"w+");
fprintf(kayit,"Ogrenci Numarasi:%d\n",yeni_ogr.no);
fprintf(kayit,"Ogrencinin Adi:%s\n",yeni_ogr.isim);
fprintf(kayit,"Ogrencinin Soyadi:%s\n",yeni_ogr.soyisim);
fprintf(kayit,"Ogrenci Telefon Numarasi:%d\n",yeni_ogr.telno);
puts("\n--------Kayit Tamamlandi.--------\n");
fclose(kayit);
main();
}
int kayit_ara(char isim[],char soyisim[])
{
char dosya[100],ch;
strlwr(isim);
strlwr(soyisim);
strcpy(dosya,isim);
strcat(dosya,soyisim);
strcat(dosya,uzanti);
if(goster=fopen(dosya,"r")){;
printf("\nKayit bulundu.\n");
ch=getc(goster);
while(ch!=EOF)
{
putchar(ch);
ch=getc(goster);
}
fclose(goster);
printf("\nDosya uzerinde degisiklik yapmak istiyor musunuz?E/H :");
ch=getch();
if(ch=='E' || ch=='e') kayit_degistir(dosya);
else main();
}
else return -1;
}
void kayit_degistir(char dosya[])
{
char command[]="del ";
strcat(command,dosya);
system(command);
dosya_adi[0]='\0';
printf("\nKayit silindi.Giris islemlerini tekrar gerceklestirmek icin Entere basin.");
gets(rx);
randomize();
yeni_ogr.no=32+random(223); //öğrenci numarası belirledik
printf("\nOgrenci adi:");
gets(yeni_ogr.isim);
printf("\nOgrencinin soyadi:");
gets(yeni_ogr.soyisim);
printf("\nOgrenci telefon numarasi:");
scanf("%d",¥i_ogr.telno);
strcpy(dosya_adi,strlwr(yeni_ogr.isim));
strcat(dosya_adi,strlwr(yeni_ogr.soyisim));
strcat(dosya_adi,uzanti);
goster=fopen(dosya_adi,"w+");
fprintf(goster,"Ogrenci Numarasi:%d\n",yeni_ogr.no);
fprintf(goster,"Ogrencinin Adi:%s\n",yeni_ogr.isim);
fprintf(goster,"Ogrencinin Soyadi:%s\n",yeni_ogr.soyisim);
fprintf(goster,"Ogrenci Telefon Numarasi:%d\n",yeni_ogr.telno);
puts("\n--------Kayit Degisikligi Tamamlandi.--------\n");
fclose(goster);
main();
}
Kaydol:
Kayıtlar (Atom)