Jump to content

C Ile Ilgili Bir Soru


adam4
 Share

Recommended Posts

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 by adam4
Link to comment
Share on other sites

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
Link to comment
Share on other sites

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);

}

Link to comment
Share on other sites

 

#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();
}

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...