Anasayfa C Dili For Döngüsü

C Dili For Döngüsü

Okan

Döngüler, bir işlemin belli bir koşul altında tekrar edilmesi için kullanılır.

C programlama dilinde

  • For Döngüsü
  • While Döngüsü
  • Do-while Döngüsü

olmak üzere 3 farklı döngü çeşidi vardır. Biz bu dersimiz de for döngülerini inceleyeceğiz. Diğer döngü çeşitler için C Dili While ve Do-While Döngüleri sayfasını ziyaret edebilirsiniz.

FOR DÖNGÜSÜ

For döngüsü, en çok kullanılan döngülerden birisidir. Bir koşula bağlı olarak, belirli bir sayıda ve bir koşul sağlandığı sürece tekrarlayan döngüdür.

For döngüsünün genel yapısı aşağıdaki şekildedir :

for(sayaç, koşul, sayaç artışı)
{
komut1
komut2
...
}

Sayaç: Döngünün kaç defa çalıştığını gösterir. Sayaç daha önceden de tanımlanabilir.

int i = 0;

for(; i < 10; i++)
{
komut1
komut2
...
} 

Yukarıda ‘i’ değişkenini yani sayacı tanımladığımız için for döngüsünün içindeki sayaç kısmını boş bırakıyoruz.

Koşul: Adından da anlaşıldığı üzere döngünün koşulunu kontrol eder ve koşul sağlandığı sürece döngü çalışmaya devam eder.

Sayaç Artışı: Bu bölümde ise sayacın artışını veya azalışını belirleriz. Arttırma ve azaltma işlemlerin detayı için C Dili Operatörler sayfasında arttırma operatörlerini ziyaret edebilirsiniz.

Hemen basit bir örnekte for döngüsünü kullanalım.

#include <stdio.h>

main()
{	
	for(int i = 0; i < 10; i++)
	{
		printf("Kod Bloklari\n");
	}
}

Programda bir yazıyı 10 defa yazdırmak istiyorsak, bunun için 10 tane printf() fonksiyonunu kullanmamıza gerek yok. Yukarıdaki kodda gördüğünüz gibi basit bir for döngüsü ile istediğimiz sayıda döngüyü çalıştırabiliyoruz.

Yukarıdaki kod kısmında önce sayacımızı tanımladık ve 0 dan başlattık. Daha sonra koşul sağlandığı için devam etti , değeri 1 arttırıldı ve döngünün içerisindeki komutu çalıştırdı. Sonrasında şart sağlanmayana kadar ( i = 10 ) oluncaya kadar döngü devam etti. Böylece döngü 10 defa dönmüş oldu.

for döngüsü-kod-1

For döngüsünün en basit hali bu şekildedir.

Şimdi for döngüsünü kullanarak faktöriyel hesaplayalım.

Faktöriyel: 1 den kendisine kadar olan sayıların çarpımıdır.

#include <stdio.h>

main()
{
	int faktoriyel = 1;	
	int sayi;
	
	printf("Bir sayi giriniz: ");
	scanf("%d",&sayi);
	
	for(int i = 1; i <= sayi; i++)
	{
		faktoriyel *= i;         // faktoriyel = faktoriyel * i;
		printf("%d ! = %d\n", i , faktoriyel);    
	}
         //printf("%d ! = %d ", sayi, faktoriyel);
	


}

Örneğin 5! = 5.4.3.2.1 dir. Bizde programımızda faktöriyel hesaplayabilmemiz için döngü değişkenini 1 den başlatıp girdiğimiz sayıya kadar döndüreceğiz. Döngü her döndüğünde de elde ettiğimiz sayıyı çarpacağız.

Sadece girdiğimiz sayının faktöriyelini vermesini istiyorsanız 14.satırı silip 17.satırdaki açıklama bölümünü kaldırabilirsiniz.

for döngüsü-kod-1

For döngüsünü kullanarak çok fazla örnek yapabiliriz. Konuyu örnekler yaparak daha iyi kavramak için  C Programlama Dili Örnekleri sayfasında 13 ‘ den 50. soruya kadar olan örnekleri çözebilirsiniz.

36 Yorum

vorbelutr ioperbir 13 Haziran 2023 - 04:22

I think this website has got some very superb info for everyone. “Philosophy triumphs easily over past evils and future evils but present evils triumph over it.” by La Rochefoucauld.

Cevapla
prestigeautodetailingkc.com 11 Ağustos 2023 - 20:50

I really liked your article.Thanks Again. Really Great.

Cevapla
ERC-20 Token Generator 25 Ağustos 2023 - 05:24

Thanks a lot for sharing this with all of us you actually know what you’re talking about! Bookmarked. Kindly also visit my web site =). We could have a link exchange arrangement between us!

Cevapla
tlover tonet 17 Aralık 2023 - 23:31

Wow, superb blog structure! How lengthy have you ever been blogging for? you make running a blog glance easy. The entire look of your site is fantastic, as smartly as the content!

Cevapla
okan 28 Aralık 2023 - 13:39

kesinlikle çok yalın ve anlaşılır anlatım.harikasınız…

Cevapla
American Charlie panama city beach 9 Ocak 2024 - 18:59

Great ?V I should definitely pronounce, impressed with your site. I had no trouble navigating through all tabs and related info ended up being truly easy to do to access. I recently found what I hoped for before you know it at all. Quite unusual. Is likely to appreciate it for those who add forums or something, site theme . a tones way for your client to communicate. Nice task..

Cevapla
Zemits machine 23 Şubat 2024 - 11:07

Hey very cool site!! Man .. Excellent .. Amazing .. I’ll bookmark your website and take the feeds also?I am happy to find a lot of useful info here in the post, we need develop more techniques in this regard, thanks for sharing. . . . . .

Cevapla
GMB SEO 28 Şubat 2024 - 19:41

What i do not realize is actually how you are not really a lot more neatly-appreciated than you may be right now. You’re very intelligent. You already know thus significantly with regards to this matter, made me in my view consider it from so many varied angles. Its like men and women don’t seem to be fascinated unless it?¦s something to do with Lady gaga! Your own stuffs outstanding. All the time care for it up!

Cevapla
Kate Little 25 Mart 2024 - 11:06

This paragraph will assist the internet visitors for building up new blog oreven a blog from start to end.

Cevapla
hire someone to hack a cell phone 26 Mart 2024 - 03:05

Enjoyed reading through this, very good stuff, regards.

Cevapla
bulantogel 27 Mart 2024 - 20:47

I was very pleased to find this web-site.I wanted to thanks for your time for this wonderful read!! I definitely enjoying every little bit of it and I have you bookmarked to check out new stuff you blog post.

Cevapla
bulantogel 28 Mart 2024 - 09:25

As a Newbie, I am continuously exploring online for articles that can benefit me. Thank you

Cevapla
fr-tec formula 1 Nisan 2024 - 16:22

I always was concerned in this subject and still am, thankyou for posting.

Cevapla
sugar defender 10 Nisan 2024 - 00:59

What Is Sugar Defender? Sugar Defender is a natural blood sugar support formula created by Tom Green. It is based on scientific breakthroughs and clinical studies.

Cevapla
flowforce max review 10 Nisan 2024 - 07:44

What is FlowForce Max? FlowForce Max Advanced Formula is a holistic blend designed to promote optimal prostate health

Cevapla
Tonic Greens 10 Nisan 2024 - 11:15

Very interesting points you have observed, regards for putting up.

Cevapla
Billionaire Brain Wave 14 Nisan 2024 - 03:13

Some truly wonderful content on this website, thanks for contribution. “Gratitude is merely the secret hope of further favors.” by La Rochefoucauld.

Cevapla
zencortex 19 Nisan 2024 - 12:38

Howdy! I know this is kinda off topic but I was wondering which blog platform are you using for this website? I’m getting tired of Wordpress because I’ve had issues with hackers and I’m looking at options for another platform. I would be awesome if you could point me in the direction of a good platform.

Cevapla
lottery defeater review 19 Nisan 2024 - 14:01

Lottery Defeater Software? Lottery Defeater is a software application created to help people win lotteries

Cevapla
Ikaria Lean Belly Juice 25 Nisan 2024 - 18:04

Its wonderful as your other blog posts : D, thankyou for posting.

Cevapla
Sugar Defender 26 Nisan 2024 - 05:30

It’s in point of fact a nice and useful piece of information. I am glad that you just shared this helpful info with us. Please stay us informed like this. Thank you for sharing.

Cevapla
fitspresso 27 Nisan 2024 - 12:28

Great write-up, I am normal visitor of one¦s blog, maintain up the nice operate, and It’s going to be a regular visitor for a lengthy time.

Cevapla
hire a hacker to recover an account 1 Mayıs 2024 - 04:41

I have been absent for some time, but now I remember why I used to love this web site. Thanks, I will try and check back more frequently. How frequently you update your website?

Cevapla
Sugar defender drops 6 Mayıs 2024 - 14:41

I cling on to listening to the newscast speak about getting free online grant applications so I have been looking around for the best site to get one. Could you advise me please, where could i acquire some?

Cevapla
Leanbiome 7 Mayıs 2024 - 20:18

I do love the way you have framed this specific problem and it does indeed give me personally some fodder for thought. Nevertheless, from what I have personally seen, I simply trust when other reviews pack on that individuals stay on point and in no way get started on a soap box associated with the news of the day. Still, thank you for this excellent piece and whilst I can not necessarily concur with the idea in totality, I regard the viewpoint.

Cevapla
Sugar defender drops 8 Mayıs 2024 - 01:42

Good – I should definitely pronounce, impressed with your web site. I had no trouble navigating through all tabs as well as related info ended up being truly easy to do to access. I recently found what I hoped for before you know it at all. Reasonably unusual. Is likely to appreciate it for those who add forums or anything, site theme . a tones way for your customer to communicate. Excellent task.

Cevapla
hire a hacker reviews 14 Mayıs 2024 - 21:58

I couldn’t resist commenting

Cevapla
sugar defender 18 Mayıs 2024 - 04:02

I really appreciate this post. I have been looking everywhere for this! Thank goodness I found it on Bing. You’ve made my day! Thank you again

Cevapla
Champyx 22 Mayıs 2024 - 00:26

Enjoyed studying this, very good stuff, regards.

Cevapla
external signs for businesses 22 Mayıs 2024 - 06:50

Thanks for making me to acquire new suggestions about desktops. I also have the belief that one of the best ways to maintain your notebook computer in excellent condition is with a hard plastic-type material case, as well as shell, which fits over the top of your computer. Most of these protective gear tend to be model distinct since they are made to fit perfectly over the natural housing. You can buy all of them directly from owner, or through third party places if they are for your notebook, however not every laptop could have a covering on the market. Again, thanks for your guidelines.

Cevapla
Flagged as scammer 23 Mayıs 2024 - 19:46

Heya i am for the first time here. I found this board and I in finding It really useful & it helped me out a lot. I am hoping to provide one thing back and help others like you aided me.

Cevapla
Fitspresso 24 Mayıs 2024 - 02:23

Thank you, I’ve recently been searching for info approximately this subject for a while and yours is the best I have came upon till now. But, what about the conclusion? Are you sure in regards to the supply?

Cevapla
fortnitehacks 27 Mayıs 2024 - 02:45

Another important issue is that if you are an older person, travel insurance with regard to pensioners is something that is important to really take into account. The more mature you are, a lot more at risk you are for making something negative happen to you while in foreign countries. If you are not covered by quite a few comprehensive insurance cover, you could have several serious challenges. Thanks for discussing your ideas on this weblog.

Cevapla
Alpha tonic 27 Mayıs 2024 - 21:06

Good post. I be taught one thing tougher on different blogs everyday. It’ll at all times be stimulating to read content material from other writers and follow slightly one thing from their store. I’d desire to use some with the content material on my weblog whether you don’t mind. Natually I’ll offer you a link on your net blog. Thanks for sharing.

Cevapla
Ikaria Lean Belly Juice reviews 30 Mayıs 2024 - 11:45

I like this website very much so much great info .

Cevapla

Yorum Yap

Bu web sitesi deneyiminizi geliştirmek için çerezler kullanmaktadır. Kabul Et Tamamını Oku

Gizlilik Politikası