I want to write this program by only using if-else, else if instead of while or for
and when the user writes the largest number twice, it should show the second-largest number as the largest number too like;
Enter five numbers: 53 -99 53 14 22
The largest number is: 53
The second-largest number is: 53
What I have tried:
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
int sayi =0 ;
int sayac = 1;
printf("Sayiyi Girin:");
scanf("%d",&sayi);
int enbuyuk = sayi ;
int ikinci_buyuk = sayi;
while (sayac != 5)
{
sayac++;
printf("Sayiyi Girin:");
scanf("%d",&sayi);
if (sayi > enbuyuk )
{
ikinci_buyuk = enbuyuk;
enbuyuk = sayi;
}
else if (sayi < enbuyuk)
{
if ((sayac == 2))
{
ikinci_buyuk = sayi;
}
else if (sayi > ikinci_buyuk)
{
ikinci_buyuk = sayi;
}
else if (enbuyuk == ikinci_buyuk)
{
ikinci_buyuk = enbuyuk;
}
}
}
printf("sayac: %d\n",sayac);
printf("En buyuk sayi: %d\n",enbuyuk);
printf("İkinci en buyuk sayi: %d\n",ikinci_buyuk);
if( enbuyuk % ikinci_buyuk !=0) {
printf("%d %d nin tam kati degildir.is not the multiple of",enbuyuk,ikinci_buyuk);
}
else{
printf(" %d %d nin tam katidir.is the multiple of",enbuyuk,ikinci_buyuk);
}
if ( enbuyuk != ikinci_buyuk) {
printf(" %d ve %d birbirine esit degildir.not equal each other",enbuyuk,ikinci_buyuk);
}
else {
printf(" %d ve %d birbirine esitir.equal each other",enbuyuk,ikinci_buyuk);
}
if (enbuyuk %2 != 0) {
printf("%d tek sayidir.odd number",enbuyuk);
}
else {
printf("%d cift sayidir.even number",enbuyuk);
}
system("pause");
return 0;
}