Created
January 25, 2019 18:03
-
-
Save emirozturk/012f2457e9b52b883a26513e93d0cf6f to your computer and use it in GitHub Desktop.
C ile Programlama 1. Hafta Uygulaması 2 2016
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
int mukemmelMi(int sayi) | |
{ | |
int toplam = 0; //Parametre olarak alinan sayinin bölenlerinin toplamini saklamak için | |
for (int i = 1; i < sayi; i++) //1'den sayiya kadar tüm sayi degerleri için döngü | |
if (sayi % i == 0) //Eger döngünün siradaki degeri (i) sayi'yi tam bölüyorsa | |
toplam += i; //toplam degerine bölen sayi (i) eklenir. | |
if (toplam == sayi) //Döngü tamamlandiginda eger toplam degeri sayi degerine esitse sayi mükemmeldir. | |
return 1; //Sayi mükemmelse 1 döndürülür. | |
else | |
return 0; //Sayi mükemmel degilse 0 döndürülür | |
} | |
int main() | |
{ | |
for (int i = 1; i < 1000; i++) //1'den 1000'e kadar olan sayilar için döngü | |
if (mukemmelMi(i)) //Siradaki sayi için mukemmelMi() fonksiyonu çagirilir. Mükemmel ise 1 dönecegi için true olur. | |
printf("%d ", i); //Siradaki sayi (i) mükemmel ise printf kullanilarak ekrana yazdirilir. | |
getchar(); //Program çalismayi bitirdiginde konsol ekraninin kapanmamasi için | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment