- Κώδικας: Επιλογή όλων
#include<stdio.h>
int prwtos(int a);
int prwtos(int k)
{int i;/*Orismos metriti*/
for(i=2;i<=k;i++)
{if(k%i==0){return 0;}/*Afou kanenas diairetis den einai megalyteros tou k/2 ara o prwtos tha diaireitai to polu me k/2*/}
return 1;}
void main()
{int begin,end,i;/*Orismos arhis kai telous tou diastimatos kai enos metriti i*/
do{
printf("Dwse ton prwto arithmo:");
scanf(" %d",&begin);
printf("Dwse ton deutero arithmo:");
scanf(" %d",&end);
}while(begin>end);
for(i=begin;i<=end;i++)
{if(prwtos(i)){printf("%d\n",i);}}
}
Αλλά σε μια εκτέλεση εμφανίζει:
- Κώδικας: Επιλογή όλων
pc_magas@pcmagas:~$ ~/askisi4
Dwse ton prwto arithmo:5
Dwse ton deutero arithmo14
Ενώ έπρεπε να εμφανίζει:
- Κώδικας: Επιλογή όλων
pc_magas@pcmagas:~$ ~/askisi4
Dwse ton prwto arithmo:5
Dwse ton deutero arithmo14
5 7 11 13





