SlideShare a Scribd company logo
1 of 8
Download to read offline
2.Ders : Çok Boyutlu Diziler
C Programlama Çok Boyutlu Diziler (Multidimensional Arrays)
Bu makalede, çok boyutlu dizilerle çalışmayı öğreneceksiniz
(iki boyutlu ve üç boyutlu dizi).
2 boyutlu bir dizi
C programlamada, çok boyutlu dizi olarak bilinen bir dizi
dizisi oluşturabilirsiniz. Örneğin,
float x[3][4];
Burada, x iki boyutlu (2d) bir dizidir. Dizi 12 eleman
tutabilir. Diziyi 3 satırlı tablo olarak düşünebilirsiniz ve
her satırın 4 sütunu vardır.
3 boyutlu bir dizi
Benzer şekilde, üç boyutlu (3d) bir dizi de
tanımlayabilirsiniz. Örneğin:
float y[2][4][3];
Burada, y dizisi 24 öğeyi tutabilir.
Bu örneği şöyle düşünebilirsiniz: Her 2 öğenin 4 öğesi vardır,
bu da 8 öğeyi oluşturur ve her 8 öğenin 3 öğesi olabilir.
Dolayısıyla, toplam eleman sayısı 24’tür.
Çok boyutlu bir dizi nasıl
başlatılır?
Çok boyutlu bir diziyi başlatmak için birden fazla yol var.
İki boyutlu bir dizinin başlatılması
// İki boyutlu diziyi başlatmanın farklı yolları
int c[2][3] = {{1, 3, 0}, {-1, 5, 9}};
int c[][3] = {{1, 3, 0}, {-1, 5, 9}};
int c[2][3] = {1, 3, 0, -1, 5, 9};
Yukarıdaki kod, iki boyutlu bir diziyi başlatmak için üç
farklı yoldur.
Üç boyutlu bir dizinin başlatılması.
Üç boyutlu bir diziyi iki boyutlu bir diziye benzer şekilde
başlatabilirsiniz. İşte bir örnek:
int test[2][3][4] = {
{ {3, 4, 2, 3}, {0, -3, 9, 11}, {23, 12,
23, 2} },
{ {13, 4, 56, 3}, {5, 9, 3, 5}, {3, 1, 4,
9} }
};
Örnek 1: Değerleri saklamak ve yazdırmak için İki Boyutlu Dizi
// bir hafta boyunca iki şehrin sıcaklığını depolamak ve
görüntülemek için C programı.
#include <stdio.h>
const int CITY = 2;
const int WEEK = 7;
int main()
{
int temperature[CITY][WEEK];
for (int i = 0; i < CITY; ++i) {
for(int j = 0; j < WEEK; ++j) {
printf("Şehir %d, Gün %d: ", i+1, j+1);
scanf("%d", &temperature[i][j]);
}
}
printf("nGösterilen Değer : nn");
for (int i = 0; i < CITY; ++i) {
for(int j = 0; j < WEEK; ++j)
{
printf("Şehir %d, Gün %d = %dn", i+1, j+1,
temperature[i][j]);
}
}
return 0;
}
Çıktısı :
Şehir 1, Gün 1: 33
Şehir 1, Gün 2: 34
Şehir 1, Gün 3: 35
Şehir 1, Gün 4: 33
Şehir 1, Gün 5: 32
Şehir 1, Gün 6: 31
Şehir 1, Gün 7: 30
Şehir 2, Gün 1: 23
Şehir 2, Gün 2: 22
Şehir 2, Gün 3: 21
Şehir 2, Gün 4: 24
Şehir 2, Gün 5: 22
Şehir 2, Gün 6: 25
Şehir 2, Gün 7: 26
Gösterilen Değer :
Şehir 1, Gün 1: 33
Şehir 1, Gün 2: 34
Şehir 1, Gün 3: 35
Şehir 1, Gün 4: 33
Şehir 1, Gün 5: 32
Şehir 1, Gün 6: 31
Şehir 1, Gün 7: 30
Şehir 2, Gün 1: 23
Şehir 2, Gün 2: 22
Şehir 2, Gün 3: 21
Şehir 2, Gün 4: 24
Şehir 2, Gün 5: 22
Şehir 2, Gün 6: 25
Şehir 2, Gün 7: 26
Örnek 2: İki boyutlu dizileri kullanarak iki matrisin toplamı
// 2*2 iki matrisin toplamını bulmak için C programı
#include <stdio.h>
int main()
{
float a[2][2], b[2][2], c[2][2];
int i, j;
// iç içe geçmiş döngü kullanarak giriş alma
printf("1. matris elemanlarını girinn");
for(i=0; i<2; ++i)
for(j=0; j<2; ++j)
{
printf("Gir a%d%d: ", i+1, j+1);
scanf("%f", &a[i][j]);
}
// iç içe geçmiş döngü kullanarak giriş alma
printf("2. matris elemanlarını girinn");
for(i=0; i<2; ++i)
for(j=0; j<2; ++j)
{
printf("Gir b%d%d: ", i+1, j+1);
scanf("%f", &b[i][j]);
}
// iki dizinin karşılık gelen elemanlarını ekleme
for(i=0; i<2; ++i)
for(j=0; j<2; ++j)
{
c[i][j] = a[i][j] + b[i][j];
}
// Toplamı görüntüleme
printf("nMatris Toplamı:");
for(i=0; i<2; ++i)
for(j=0; j<2; ++j)
{
printf("%.1ft", c[i][j]);
if(j==1)
printf("n");
}
return 0;
}
Çıktısı :
1. matris elemanlarını girin
Gir a11: 2;
Gir a12: 0.5;
Gir a21: -1.1;
Gir a22: 2;
2. matris elemanlarını girin
Gir b11: 0.2;
Gir b12: 0;
Gir b21: 0.23;
Gir b22: 23;
Matris Toplamı:
2.2 0.5
-0.9 25.0
Örnek 3: Üç Boyutlu Dizi
// Kullanıcı tarafından girilen 12 değeri kaydeden ve yazdıran
C programı
#include <stdio.h>
int main()
{
int i, j, k, test[2][3][2];
printf("12 adet değer girin: n");
for(i = 0; i < 2; ++i) {
for (j = 0; j < 3; ++j) {
for(k = 0; k < 2; ++k ) {
scanf("%d", &test[i][j][k]);
}
}
}
// Uygun indeks ile değerleri yazdırma.
printf("nDeğerleri gösteriliyor.:n");
for(i = 0; i < 2; ++i) {
for (j = 0; j < 3; ++j) {
for(k = 0; k < 2; ++k ) {
printf("test[%d][%d][%d] = %dn", i, j, k,
test[i][j][k]);
}
}
}
return 0;
}
Çıktısı :
12 adet değer girin:
1
2
3
4
5
6
7
8
9
10
11
12
Değerleri gösteriliyor.:
test[0][0][0] = 1
test[0][0][1] = 2
test[0][1][0] = 3
test[0][1][1] = 4
test[0][2][0] = 5
test[0][2][1] = 6
test[1][0][0] = 7
test[1][0][1] = 8
test[1][1][0] = 9
test[1][1][1] = 10
test[1][2][0] = 11
test[1][2][1] = 12

More Related Content

Featured

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by HubspotMarius Sescu
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTExpeed Software
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsPixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 

Featured (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 

Cok boyutlu-diziler

  • 1. 2.Ders : Çok Boyutlu Diziler C Programlama Çok Boyutlu Diziler (Multidimensional Arrays) Bu makalede, çok boyutlu dizilerle çalışmayı öğreneceksiniz (iki boyutlu ve üç boyutlu dizi). 2 boyutlu bir dizi C programlamada, çok boyutlu dizi olarak bilinen bir dizi dizisi oluşturabilirsiniz. Örneğin, float x[3][4]; Burada, x iki boyutlu (2d) bir dizidir. Dizi 12 eleman tutabilir. Diziyi 3 satırlı tablo olarak düşünebilirsiniz ve her satırın 4 sütunu vardır.
  • 2. 3 boyutlu bir dizi Benzer şekilde, üç boyutlu (3d) bir dizi de tanımlayabilirsiniz. Örneğin: float y[2][4][3]; Burada, y dizisi 24 öğeyi tutabilir. Bu örneği şöyle düşünebilirsiniz: Her 2 öğenin 4 öğesi vardır, bu da 8 öğeyi oluşturur ve her 8 öğenin 3 öğesi olabilir. Dolayısıyla, toplam eleman sayısı 24’tür. Çok boyutlu bir dizi nasıl başlatılır? Çok boyutlu bir diziyi başlatmak için birden fazla yol var. İki boyutlu bir dizinin başlatılması // İki boyutlu diziyi başlatmanın farklı yolları int c[2][3] = {{1, 3, 0}, {-1, 5, 9}}; int c[][3] = {{1, 3, 0}, {-1, 5, 9}}; int c[2][3] = {1, 3, 0, -1, 5, 9};
  • 3. Yukarıdaki kod, iki boyutlu bir diziyi başlatmak için üç farklı yoldur. Üç boyutlu bir dizinin başlatılması. Üç boyutlu bir diziyi iki boyutlu bir diziye benzer şekilde başlatabilirsiniz. İşte bir örnek: int test[2][3][4] = { { {3, 4, 2, 3}, {0, -3, 9, 11}, {23, 12, 23, 2} }, { {13, 4, 56, 3}, {5, 9, 3, 5}, {3, 1, 4, 9} } }; Örnek 1: Değerleri saklamak ve yazdırmak için İki Boyutlu Dizi // bir hafta boyunca iki şehrin sıcaklığını depolamak ve görüntülemek için C programı. #include <stdio.h> const int CITY = 2; const int WEEK = 7; int main() { int temperature[CITY][WEEK]; for (int i = 0; i < CITY; ++i) { for(int j = 0; j < WEEK; ++j) { printf("Şehir %d, Gün %d: ", i+1, j+1); scanf("%d", &temperature[i][j]); } }
  • 4. printf("nGösterilen Değer : nn"); for (int i = 0; i < CITY; ++i) { for(int j = 0; j < WEEK; ++j) { printf("Şehir %d, Gün %d = %dn", i+1, j+1, temperature[i][j]); } } return 0; } Çıktısı : Şehir 1, Gün 1: 33 Şehir 1, Gün 2: 34 Şehir 1, Gün 3: 35 Şehir 1, Gün 4: 33 Şehir 1, Gün 5: 32 Şehir 1, Gün 6: 31 Şehir 1, Gün 7: 30 Şehir 2, Gün 1: 23 Şehir 2, Gün 2: 22 Şehir 2, Gün 3: 21 Şehir 2, Gün 4: 24 Şehir 2, Gün 5: 22 Şehir 2, Gün 6: 25 Şehir 2, Gün 7: 26 Gösterilen Değer : Şehir 1, Gün 1: 33 Şehir 1, Gün 2: 34 Şehir 1, Gün 3: 35 Şehir 1, Gün 4: 33 Şehir 1, Gün 5: 32 Şehir 1, Gün 6: 31 Şehir 1, Gün 7: 30 Şehir 2, Gün 1: 23 Şehir 2, Gün 2: 22
  • 5. Şehir 2, Gün 3: 21 Şehir 2, Gün 4: 24 Şehir 2, Gün 5: 22 Şehir 2, Gün 6: 25 Şehir 2, Gün 7: 26 Örnek 2: İki boyutlu dizileri kullanarak iki matrisin toplamı // 2*2 iki matrisin toplamını bulmak için C programı #include <stdio.h> int main() { float a[2][2], b[2][2], c[2][2]; int i, j; // iç içe geçmiş döngü kullanarak giriş alma printf("1. matris elemanlarını girinn"); for(i=0; i<2; ++i) for(j=0; j<2; ++j) { printf("Gir a%d%d: ", i+1, j+1); scanf("%f", &a[i][j]); } // iç içe geçmiş döngü kullanarak giriş alma printf("2. matris elemanlarını girinn"); for(i=0; i<2; ++i) for(j=0; j<2; ++j) { printf("Gir b%d%d: ", i+1, j+1); scanf("%f", &b[i][j]); } // iki dizinin karşılık gelen elemanlarını ekleme for(i=0; i<2; ++i) for(j=0; j<2; ++j) { c[i][j] = a[i][j] + b[i][j];
  • 6. } // Toplamı görüntüleme printf("nMatris Toplamı:"); for(i=0; i<2; ++i) for(j=0; j<2; ++j) { printf("%.1ft", c[i][j]); if(j==1) printf("n"); } return 0; } Çıktısı : 1. matris elemanlarını girin Gir a11: 2; Gir a12: 0.5; Gir a21: -1.1; Gir a22: 2; 2. matris elemanlarını girin Gir b11: 0.2; Gir b12: 0; Gir b21: 0.23; Gir b22: 23; Matris Toplamı: 2.2 0.5 -0.9 25.0 Örnek 3: Üç Boyutlu Dizi // Kullanıcı tarafından girilen 12 değeri kaydeden ve yazdıran C programı
  • 7. #include <stdio.h> int main() { int i, j, k, test[2][3][2]; printf("12 adet değer girin: n"); for(i = 0; i < 2; ++i) { for (j = 0; j < 3; ++j) { for(k = 0; k < 2; ++k ) { scanf("%d", &test[i][j][k]); } } } // Uygun indeks ile değerleri yazdırma. printf("nDeğerleri gösteriliyor.:n"); for(i = 0; i < 2; ++i) { for (j = 0; j < 3; ++j) { for(k = 0; k < 2; ++k ) { printf("test[%d][%d][%d] = %dn", i, j, k, test[i][j][k]); } } } return 0; } Çıktısı : 12 adet değer girin: 1 2 3 4 5 6
  • 8. 7 8 9 10 11 12 Değerleri gösteriliyor.: test[0][0][0] = 1 test[0][0][1] = 2 test[0][1][0] = 3 test[0][1][1] = 4 test[0][2][0] = 5 test[0][2][1] = 6 test[1][0][0] = 7 test[1][0][1] = 8 test[1][1][0] = 9 test[1][1][1] = 10 test[1][2][0] = 11 test[1][2][1] = 12