Created
October 3, 2015 14:19
-
-
Save cagataycali/1dfb00acea38d37aa8f5 to your computer and use it in GitHub Desktop.
C dilinde verilen sayının asal olup olmadığına bakan program
This file contains hidden or 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> | |
// Verilen sayinin asal olup olmadigina | |
// bakar. Sayi asalsa, geriye 1 aksi hâlde | |
// 0 degeri doner. | |
int sayi_asal_mi( int sayi ) | |
{ | |
int i; | |
for( i = 2; i <= sayi/2; i++ ) { | |
// Sayi asal degilse, i'ye tam olarak | |
// bolunur. | |
if( sayi%i == 0 ) return 0; | |
} | |
// Verilen sayi simdiye kadar hicbir | |
// sayiya bolunmediyse, asaldir ve | |
// geriye 1 doner. | |
return 1; | |
} | |
// main fonksiyonu | |
int main( void ) | |
{ | |
int girilen_sayi; | |
int test_sonucu; | |
do{ | |
printf( "Lütfen bir sayı giriniz> " ); | |
scanf( "%d",&girilen_sayi ); | |
test_sonucu = sayi_asal_mi( girilen_sayi ); | |
if( !test_sonucu ) | |
printf("Girilen sayı asal değildir!\n"); | |
} while( !test_sonucu ); | |
printf( "Girilen sayı asaldır!\n" ); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment