21 Aralık 2010 Salı

matrisin transpoze' nu bulan c sharp programı

Yorum Bırak

a c program that computes the transpose of a matrix


program.cs  class




using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{

    class Program
    {
        static void Main(string[] args)
        {
             ArrayConverter con=new ArrayConverter();

            Console.WriteLine(" x dimension:");
            int x=int.Parse(Console.ReadLine());
            Console.WriteLine(" y dimension:");
            int y=int.Parse(Console.ReadLine());
            int s;
            int[,] deneme = new int[x, y];
              Random r = new Random();      //randomla sayı atıyoruz
              int e = 0;
              while ( e < x)
              {
                  for (int z = 0; z < y; z++)
                  {
                      s = r.Next(0,10);

                       deneme[e,z]=s;

                  }
                  e++;

              }



             int i =0;
              while( i < x)
              {
                  for (int z = 0; z < y; z++)
                  {
                      Console.Write(deneme[i,z]);
                      Console.Write(" ");
                  }
                  Console.WriteLine("\n");
                  i++;
              }
              Console.WriteLine("the new  array:");
              con.ReverseAndConvertArray(deneme);

              Console.ReadLine();


        }
    }
}


ArrayConverter class



using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class ArrayConverter
    {
        public void ReverseAndConvertArray(int[,] inputArray)
        {
            int a, b;
            a = inputArray.GetLength(0);

            b = inputArray.GetLength(1);
            int[,] jaggedarray = new int[b, a];

            int l = 0 ;
            int y = a - 1;
            if (a != b)
            {

                for (int i = 0; i < a; i++)
                {
                    for (int k = 0; k < b; k++)
                    {
                        jaggedarray[k, l] = inputArray[i, k];

                    }
                    l++;
                }
               int m = 0;
                while ( m < b)
                {
                    for (int z = 0; z < a; z++)
                    {
                        Console.Write(jaggedarray[m, z]);
                        Console.Write(" ");
                    }
                    Console.WriteLine("\n");
                }

            }
            else
            { l = 0;
                int q = 0;
                while (q < a)
                {
                    for (int k = 0; k < b; k++)
                    {
                        jaggedarray[k, l] = inputArray[i, k];

                    }
                    l++;
                    q++;
                }
                for (int i = 0; i < a; i++)
                {
                    for (int z = 0; z < b; z++)
                    {
                        Console.Write(jaggedarray[i, z]);
                        Console.Write(" ");
                    }
                    Console.WriteLine("\n");
                }

            }


        }
    }
}

Yazıyı Oku

c programlamada kullanılan bazı dosya sitemi fonksiyonları

Yorum Bırak
Commonly Used C File-System Functions
bazı dosya okuma yazma vb işlemler için fonksiyonlar...


  1. fopen( )   bir dosyayı açar.(Opens a file.)
  2. fclose( ) açılan dosyayı kapatır (Closes a file.)
  3. putc( ) dosyaya bir karakter yazar (Writes a character to a file.)
  4. fputc( ) yukardaki fonksiyon ile aynı görevi yapar(Same as putc() .)
  5. getc( ) dosyadan bir karakter okur( Reads a character from a file.)
  6. fgetc( ) yukardaki fonksiyon ile aynı görevi yapar Same as getc() .
  7. fgets( ) dosyadan string okur (Reads a string from a file.)
  8. fputs( ) dosyaya string yazar(Writes a string to a file.)
  9. fseek( ) belirtilen byte ı dosyada arar (Seeks to a specified byte in a file.)
  10. ftell( ) mevcut dosya pozisyonunu döndürür(Returns the current file position.)
  11. fprintf( ) Is to a file what printf() is to the console.
  12. fscanf( ) Is to a file what scanf() is to the console.
  13. feof( ) dosyanın sonuna gelindiyse true döndürür( Returns true if end-of-file is reached.)
  14. ferror( ) herhangi bir hata olursa dosya işeminde true döndürür(Returns true if an error has occurred.)
  15. rewind( ) belirteçi dosya başına getirir(Resets the file position indicator to the beginning of the file.)
  16. remove( ) dosyayı siler(Erases a file.)
  17. fflush( ) Flushes a file.
Yazıyı Oku

c programlamada matematik fonksiyonlar

Yorum Bırak
some mathematical functions in c language

acos
#include <cmath>
float acos(float arg);
double acos(double arg);
long double acos(long double arg);
The acos() function returns the arc cosine of arg. The argument to acos() must be in
the range –1 to 1; otherwise a domain error will occur.
Related functions are asin() , atan() , atan2() , sin() , cos() , tan() , sinh() , cosh() ,
and tanh().
asin
#include <cmath>
float asin(float arg);
double asin(double arg);
long double asin(long double arg);
The asin() function returns the arc sine of arg. The argument to asin() must be in
the range –1 to 1; otherwise a domain error will occur.
Related functions are acos() , atan() , atan2() , sin() , cos() , tan() , sinh() , cosh() ,
and tanh() .

atan
#include <cmath>
float atan(float arg);
double atan(double arg);
long double atan(long double arg);
The atan() function returns the arc tangent of arg.
Related functions are asin() , acos() , atan2() , tan() , cos() , sin() , sinh() , cosh() ,
and tanh() .

atan2
#include <cmath>
float atan2(float y, float x);
double atan2(double y, double x);
long double atan2(long double y, long double x);
The atan2() function returns the arc tangent of y/x. It uses the signs of its
arguments to compute the quadrant of the return value.
Related functions are asin() , acos() , atan() , tan() , cos() , sin() , sinh() , cosh() ,
and tanh() .

ceil
#include <cmath>
float ceil(float num);
double ceil(double num);
long double ceil(long double num);

The ceil() function returns the smallest integer (represented as a floating-point
value) not less than num. For example, given 1.02, ceil() would return 2.0. Given –1.02,
ceil() would return –1.
Related functions are floor() and fmod() .

cos
#include <cmath>
float cos(float arg);
double cos(double arg);
long double cos(long double arg);
The cos() function returns the cosine of arg. The value of arg must be in radians.
Related functions are asin() , acos() , atan2() , atan() , tan() , sin() , sinh() , cos() ,
and tanh() .



cosh
#include <cmath>
float cosh(float arg);
double cosh(double arg);
long double cosh(long double arg);
The cosh() function returns the hyperbolic cosine of arg.
Related functions are asin() , acos() , atan2() , atan() , tan() , sin() , cosh() , and
tanh().

exp
#include <cmath>
float exp(float arg);
double exp(double arg);
long double exp(long double arg);
The exp() function returns the natural logarithm base e raised to the arg power.
A related function is log() .

fabs
#include <cmath>
float fabs(float num);
double fabs(double num);
long double fabs(long double num);
The fabs() function returns the absolute value of num.
A related function is abs() .
floor
#include <cmath>
float floor(float num);
double floor(double num);
long double floor(long double num);
The floor() function returns the largest integer (represented as a floating-point
value) not greater than num. For example, given 1.02, floor() would return 1.0. Given
–1.02, floor() would return –2.0.
Related functions are fceil() and fmod() .
fmod
#include <cmath>
float fmod(float x, float y);
double fmod(double x, double y);
long double fmod(long double x, long double y);
The fmod() function returns the remainder of x/y.
Related functions are ceil() , floor() , and fabs() .
frexp
#include <cmath>
float frexp(float num, int *exp);

double frexp(double num, int *exp);
long double frexp(long double num, int *exp);
The frexp() function decomposes the number num into a mantissa in the range 0.5
to less than 1, and an integer exponent such that num = mantissa * 2exp. The mantissa is
returned by the function, and the exponent is stored at the variable pointed to by exp.
A related function is ldexp() .
ldexp
#include <cmath>
float ldexp(float num, int exp);
double ldexp(double num, int exp);
long double ldexp(long double num, int exp);
The ldexp() returns the value of num * 2exp. If overflow occurs, HUGE_VAL
is returned.
Related functions are frexp() and modf() .
log
#include <cmath>
float log(float num);
double log(double num);
long double log(long double num);
The log() function returns the natural logarithm for num. A domain error occurs if
num is negative, and a range error occurs if the argument is zero.
A related function is log10() .
log10
#include <cmath>
float log10(float num);
double log10(double num);
long double log10(long double num);

The log10() function returns the base 10 logarithm for num. A domain error occurs
if num is negative, and a range error occurs if the argument is zero.
A related function is log() .


sqrt
#include <cmath>
float sqrt(float num);
double sqrt(double num);
long double sqrt(long double num);
The sqrt() function returns the square root of num. If it is called with a negative
argument, a domain error will occur.
Related functions are exp() , log() , and pow() .
Yazıyı Oku

c programlamada enum yapısı

Yorum Bırak
using enum in c programming
enum yapısı kendi değişkenimizi belirtmek için kullanılır değişkenin sabit olduğu durumlarda kullanılır.Yapı olarak hemen hemen struct larla aynıdır.

enum tip_adı{değer_1, değer_2, ..., değer_n} değişken_adı;

örnek kullanım:
enum icecekler{su,kola,cay} icecek;
burda su index numarası olarak 0,kola 1 ve cay ise 2 sayısına karşılık gelmektedir.
örneğin;
icecek=kola;
icecek=1 anlamında kullanılmıştır.
örnek program:
a c program that decides wheter the entered number is odd or even using enum 
#include <stdio.h>

enum BOOLEAN{ FALSE, TRUE }; /* 0, 1 */

int tek(int n){ return (n % 2); }

int main()
{
enum BOOLEAN sonuc;
int x;

printf("Bir sayi girin: ");
scanf("%d",&x);

sonuc = tek(x); /* tek mi? */

if( sonuc == TRUE )
puts("Girilen sayi tek ");
else
puts("Girilen sayi cift");

return 0;
}

burda tek isminde bir metod kullanıldı ve geriş dönüş değeri olarak int ayarlandı.Program kullanılan sayının 2 ile bölümünden kalanı bize verecek yani sayının tek mi çift mi olduğunu.
sonuc 1 olursa enumdan TRUE olacak ve girilen sayının tek olduğu yazdırılacak sonuc 0 olursa
 enumdan FALSE olacak ve girilen sayinin çift olduğu yazdırılacak.



Yazıyı Oku

c programlamada struct yapısı

Yorum Bırak
using struct  in c programming
struct ingilizce structures den gelmektedir türkçe olarak yapı manasındadır.Struct değişkenleri tek bir çatı altında toplamak için kullanlır.Bu değişkenler gerektiğinde struct altından çağrılabilir.Genel yapı olarak:
struct isim{
tip yapı_değişken_ismi;
tip yapı_değişken_ismi;
...
};

şeklinde kullanılabilir.Burda isim yazılan yere structure ın adı parantez içindeki yerlere de değişkenlerimizi yazıyoruz.Örnek olarak:

struct deneme{
int a;
         char b;
       double c;
};
daha sonra 
struct deneme ilk;

şeklinde tanımlayabiliriz ve eğer değer atamak istiyorsak:
ilk.a=5;
ilk.b='m';

şeklinde atayabiliriz.Örnek program olarak bir arabanın bilgilerini struct kullanarak girebiliriz:
struct araba{
char ad[10];
double price;

};

int main()
{
struct araba car; /* ogr değişkeni kayit tipinde */

printf("araba ücreti : "); scanf("%ld",&car.price);
printf("araba adi : "); scanf("%s" , car.ad);


printf("\n*** Girilen bilgiler ***");
printf("\nücreti : %ld",car.price);
printf("\nAdi : %s ",car.ad);


return 0;
}

Yazıyı Oku

20 Aralık 2010 Pazartesi

iki matrisin toplamını bulan c programı

Yorum Bırak

a c program that computes the summation of two matrices

#include <stdio.h>

#define SAT 2
#define SUT 3

int main()
{
int a[SAT][SUT] = {5, 3, 7, 0, 1, 2};

int b[SAT][SUT] = {1, 2, 3, 4, 5, 6};
int c[SAT][SUT];
int i, j;

puts("A Matrisi:");
for(i=0; i<SAT; i++){
for(j=0; j<SUT; j++)
printf("%4d",a[i][j]);
printf("\n");
}

puts("B Matrisi:");
for(i=0; i<SAT; i++){
for(j=0; j<SUT; j++)
printf("%4d",b[i][j]);
printf("\n");
}

puts("\nC Matrisi:");
for(i=0; i<SAT; i++){
for(j=0; j<SUT; j++){
c[i][j] = a[i][j] + b[i][j];
printf("%4d",c[i][j]);
}
printf("\n");
}

return 0;
}

not:kodlarla oynayarak matrisi elle girip toplamını öyle de bulablirsiniz
Yazıyı Oku

girilen yazıyı tersine çeviren c programı

Yorum Bırak

a c program that reverses the text that you enter 

#include <stdio.h>

int main(void)
{
char s[40], gecici;
int i, n;

/* diziyi oku */
printf("Bir seyler yazin : ");
gets(s);

/* sonlandırıcı karaktere kadar */
for(n=0; s[n] != '\0'; n++)
;

for(i=0; i<n/2; i++){
gecici = s[n-i-1];
s[n-i-1] = s[i];
s[i] = gecici;
}

printf("Tersi : %s\n",s);

return 0;
}
Yazıyı Oku

char dizisinin uzunluğunu bulan c programı

Yorum Bırak

a c program that finds the lenght of a char array

#include <stdio.h>

int main(void)
{
char s[40];
int k = 0;

/* diziyi oku */
printf("Bir seyler yazin : ");
gets(s);

/* sonlandırıcı karaktere kadar karakterleri say */
while( s[k]!='\0' )
k++;

printf("Dizinin uzunlugu : %d\n",k);

return 0;
}
Yazıyı Oku

10 sayının aritmetik ortalamasını ve standart sapmasını hesaplayan program

Yorum Bırak

#include <stdio.h>
#include <math.h>

#define N 10

int main(void)
{
int i;
float x[N], toplam = 0.0, ort, std_sap = 0.0;

/* ortalama hesabı */
for(i=0; i<N; i++)
{
printf("%d. sayi : ",i+1);
scanf("%f",&x[i]);

toplam += x[i];
}

ort = toplam/N;

/* standart sapma hesabı */
for(toplam = 0.0, i=0; i<N; i++)
toplam += pow(x[i]-ort, 2.0);

std_sap = sqrt( toplam/(N-1) );

printf("Ortalama = %f\n",ort);
printf("Standart sapma = %f\n",std_sap);

return 0;
}
Yazıyı Oku

C / C++ Derleyicileri

Yorum Bırak
bazı c/c++ derleyicileri dev c++ gerçekten güzle bir derleyicidir ve hemen indirip kullanmaya başlayabilirsiniz.
(some c/c++ complier and download links )
Dev-C++
http://www.bloodshed.net/dev/devcpp.html
Salford (Silverfrost FTN95)
http://www.silverfrost.com/32/ftn95/ftn95_personal_edition.asp
Turbo C
http://www1.gantep.edu.tr/~bingul/computer/download/turbo-c/tc201.zip
Yazıyı Oku

19 Aralık 2010 Pazar

c programlamada switch case kullanımına bir örnek

Yorum Bırak
Yazıyı Oku

e sayısının üslerini hesaplayan c programı

Yorum Bırak
a c program that calculates the power of e number

Yazıyı Oku

18 Aralık 2010 Cumartesi

bazı assembly kodları ve açıklamaları

Yorum Bırak
ACALL: Absolute Call
ADD, ADDC: Add Accumulator (With Carry)
AJMP: Absolute Jump
ANL: Bitwise AND
CJNE: Compare and Jump if Not Equal
CLR: Clear Register
CPL: Complement Register
DA: Decimal Adjust

DEC: Decrement Register
DIV: Divide Accumulator by B
DJNZ: Decrement Register and Jump if Not Zero
INC: Increment Register
JB: Jump if Bit Set
JBC: Jump if Bit Set and Clear Bit
JC: Jump if Carry Set
JMP: Jump to Address
JNB: Jump if Bit Not Set
JNC: Jump if Carry Not Set
JNZ: Jump if Accumulator Not Zero
JZ: Jump if Accumulator Zero
LCALL: Long Call
LJMP: Long Jump
MOV: Move Memory
MOVC: Move Code Memory
MOVX: Move Extended Memory
MUL: Multiply Accumulator by B
NOP: No Operation
ORL: Bitwise OR
POP: Pop Value From Stack
PUSH: Push Value Onto Stack
RET: Return From Subroutine
RETI: Return From Interrupt
RL: Rotate Accumulator Left
RLC: Rotate Accumulator Left Through Carry
RR: Rotate Accumulator Right
RRC: Rotate Accumulator Right Through Carry
SETB: Set Bit
SJMP: Short Jump
SUBB: Subtract From Accumulator With Borrow
SWAP: Swap Accumulator Nibbles
XCH: Exchange Bytes
XCHD: Exchange Digits
XRL: Bitwise Exclusive OR
Undefined: Undefined Instruction
Yazıyı Oku

ASCII kod tablosu

Yorum Bırak

Yazıyı Oku

stringler ve bazı string metodlarının kullanımı

Yorum Bırak
 C programlama dilinde direk olarak string tanımlaması yoktur.Char denilen karakter tanımlaması vardır ve char tek bir karakter olarak girilir.Ancak string yani daha uzun bir yazı girmek istiyorsak bunu array lar ile yapmak mümkündür.Array dizi anlamına gelmektedir.Tanımlanması aşağıdaki şekilde yapılabilir.
 karakter  türü  karakter ismi[karakter uzunluğu]
 örneğin; char arr[100]   Bu array 100 karakterden oluşan bir dizi tanımlar.
bazı string metodları
strlen(ch1)=ch1 in uzunluğunu hesaplar
strcpy(ch1,ch2)=ch2 yi ch1 e kopyalar 
strcmp(ch1,ch2)=ch1 e göre ayar çeker eğer ch1 sözlüğe göre önce geliyorsa -1 sonra geliyorsa +1 eşitse 0 döndürür
strcat(ch1,ch2)=ch1 i ch1+ch2 şeklinde yazar ch2 değişmez
 strncat(ch1,ch2,n)=ch 2 nin ilk n karakterini alıp ch1 in sonuna ekler böylece ch1 değişir ama ch 2 değişmez
  strncmp(ch1,ch2,n)=baştan itibaren ilk n karakteri karşılaştırır ama ilki farklıysa geri kalanlara hiç bakmaz ve aradaki karakter farkını sayı değeri olara yazar
strncpy(ch1,ch2,n)=ch2 nin ilk n karakterini ch1 in ilk n karakterinini yerine yazar 2,n)=ch2 nin ilk n karakterini ch1 in ilk n karakterinini yerine yazar
Yazıyı Oku

c programlamada dinamik bellek kullanımı

Yorum Bırak
Örneğin bir array dizisi için 100 karakter uzunluğunda yer ayırıyoruz.Ancak bunun 5 tanesini kullanıyoruz.Kullanılmayan karakterler programın yavaşlamasına ve boş yere zaman harcamaya neden olur.Bu yüzden de kullanmadığımız belleği tekrar program sonunda silmemiz gerekir ki program akışı hızlı olabilsin. Yer ayırmak için malloc adı verilen fonksiyon kullanılır.Kullanımı şu şekildedir: return value malloc(size)
örneğin;
char *p;
p=(char *)malloc(100);
Burada char pointer cinsinden bir değişkene bellekte 100 karakterlik yer ayırdık.Ancak diyelimki bunun 3 adetini kullnıp gerii kalanını hafızdan silmek istiyoruz.O zaman da free() fonksiyonunu kullanmamız gerekir.Kullanımı:
free(değişken);
Örnek bir dinamik bellek ayırma programı ve hafızadan kullanılmayanı silme:
 int *pi = NULL;
pi = (int *)malloc(25 * sizeof(int));   /*  25 integer için bellekte yer ayırdık */
pi[0] = 5;
pi[1] = 2;
free(pi);  /* sadece 2 yer kullandık ve kullanılmayanları free ile sildik */
        
Yazıyı Oku

programlamada döngüler

Yorum Bırak
Bu konuda do while,for ve while döngülerini ve aralarındaki farkları anlatacağım.öncelikle döngülerin basit kod yapısını anlayalım...
WHILE DÖNGÜSÜ
while(expression)
{
...
}

yukarıda da gördüğümüz gibi expression yazan yere kontrol edeceğimiz kodu yerleştiriyoruz mesela x==5 gibi.While döngüsü expression bölümünü kontrol ediyor ve doğruysa parentez içine geçp oradaki kodları döndürüyor.
DO-WHILE DÖNGÜSÜ
do
{
...
}while(expression)

burda da while ile aynı şekilde ancak burda kontrol etmeden önce 1 kez mutlaka parentez içine giriyor ve kodu dödürüyor ondan sonra kontrol edip bakıyor ve ifade doğruysa tekrar döndürmeye devam ediyor.
FOR DÖNGÜSÜ
for(i=0;i<10;i++)
{
...
}

for döngüsü yapı olarak diğerlerinden biraz daha farklı .Burda ilk önce değişkenin değerini 0 olarak girdik daha sonra kontrol ettik değerimiz 10 dan küçükse parentez içindeki kodları uygula diye ve i++ komutuyla da her seferinde i değişkenimizi 1 artırdık.Yani bu dongü 10 kez çalışacak ve for döngüsü içindeki kodları uygulayacak.

Yazıyı Oku