adam4 Posted January 11, 2016 Share Posted January 11, 2016 (edited) Arkadaşlar C'de bir program yazmaya çalışıyorum. 20 sayı isteyecek benden ve bu yazdığım sayıların 5 ile tam bölünenleri ekrana basacak bir program yazmam gerekiyor. Biliyorum biraz acemice ama daha 1.sınıfım yapacak bişey yok. Bişeyler yaptım ama sadece son girdiğim sayının 5'e bölünüp bölünmediğine bakıyor. Beynim durdu iyice yardımcı olabilirmisiniz. #include<stdio.h> #include<conio.h> int main() { int sayi,j; for(j=1;j<=20;j++) { printf("sayigir");scanf("%d",&sayi); } if( sayi%5==0) { printf("5'e bolunen sayilar sirasiyla- %d\n",sayi); } else { printf("5'e tam bolunen sayi yok"); } getch(); } Bu şuanda benim yazdığım hatalı kod. Edited January 11, 2016 by adam4 Quote Link to comment Share on other sites More sharing options...
Mycrosoft Posted January 12, 2016 Share Posted January 12, 2016 Dizi kullanman gerek. 5 e bölünen sayıları diziye kaydedersin mesela şöyle: for(i=1 ; i<=20 ; i++) { printf("%d. sayiyi giriniz:");scanf("%d",&sayi); if( sayi%5==0) {sayi=dizi[i-1];} } Not: Ben de 1. sınıf öğrencisiyim ve denemedim şu an bunu :D Quote Link to comment Share on other sites More sharing options...
nezcafe Posted January 12, 2016 Share Posted January 12, 2016 Yapmak istediğin sırayla girilecek 20 sayının 5 e bölünüp bölünmediğini kontrol etmekse dizi kullanmadan, döngünün her bir adımında yapman mümkün. Şu şekilde yani; for(i=0;i<20;i++) { scanf("%d",&sayi); if(sayi%5 == 0) printf("%d 5 e bolunur",sayi); else printf("%d 5 e bolunmez",sayi); } Quote Link to comment Share on other sites More sharing options...
HalilYanar Posted January 12, 2016 Share Posted January 12, 2016 #include <stdio.h> #include <conio.h> void main () { int i; int sayi[20]; for(i=0;i<20;i++) { printf("%d. Sayiyi giriniz : ", i+1); scanf("%d", &sayi[i]); } printf("\n"); for(i=0;i<20;i++) { if(sayi[i]%5==0) { printf("%d. girdiğiniz sayi (%d) 5 e bolunur.\n", i+1,sayi[i]); } } getch(); } Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.