Files
ikcu-yzm/YZM502/vize/main.c
2023-04-01 16:05:06 +03:00

96 lines
2.0 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#include "stdio.h"
void tekCift() {
int sayi;
printf("Bir sayi giriniz: ");
scanf("%d", &sayi);
if (sayi % 2 == 0) {
printf("%d ÇİFTTİR!", sayi);
} else {
printf("%d TEKDİR!", sayi);
}
}
void sirala() {
int sayi[3];
int i,j,tmp;
for (i =0; i < 3; i++) {
printf("%d. Sayı: ", i+1);
scanf("%d", &sayi[i]);
}
for (i=0; i<3; i++) {
for (j=0; j<3-i-1; j++) {
if (sayi[j]>sayi[j+1]) {
tmp = sayi[j];
sayi[j] = sayi[j+1];
sayi[j+1] = tmp;
}
}
}
printf("\n------------------------------\n");
for (i =0; i < 3; i++) {
printf("%d\t", sayi[i]);
}
}
void asal() {
int sayi, i;
printf("Bir sayi giriniz: ");
scanf("%d", &sayi);
for (i=2; i<sayi; i++) {
if (sayi % i == 0) {
printf("%d asal DEĞİLDİR!", sayi);
return;
}
}
printf("%d ASALDIR!", sayi);
}
int menu() {
int secim = 0;
printf("\n\n-------------------------------------------------\n");
printf("(1) Girilen sayının Tek Yada Çift Olduğunu Bulma \n");
printf("(2) Girilen 3 sayıyı büyükten küçüğe sıralama \n");
printf("(3) Girilen Sayının Asal sayı olup olmadığını bulma \n");
printf("ÇIKIŞ İÇİN : -1 \n");
printf("-------------------------------------------------\n\n");
printf("Seçiminizi Giriniz: ");
do {
scanf("%d", &secim);
if ((secim < 1 || secim > 3) && (secim != -1)) {
printf("\nYanlış değer girdiniz tekrar giriş yapınız: ");
}
} while ((secim < 1 || secim > 3) && (secim != -1));
return secim;
}
void main() {
int secim = 0;
do {
secim = menu();
switch (secim) {
case 1:
tekCift();
break;
case 2:
sirala();
break;
case 3:
asal();
break;
}
} while (secim != -1);
}