08-08-2024, 12:52 PM
(This post was last modified: 08-08-2024, 12:56 PM by Kernelpanic.)
The tenary operator was discussed here for some time ago, a bit complicated in Basic. It is quite useful for simple comparisons.
The program uses the tenary operator in C with a triple comparison. It also works with four numbers, but that gets a bit confusing. If one only want to compare two numbers, simply enter 0 for the third number. -- Both files in the same directory.
Save the C program as btenaerDreifach.h
The program uses the tenary operator in C with a triple comparison. It also works with four numbers, but that gets a bit confusing. If one only want to compare two numbers, simply enter 0 for the third number. -- Both files in the same directory.
Code: (Select All)
'Aufruf des tenaeren Operators in C - 8. Aug. 2024
Option _Explicit
Declare Library "D:\Lab\QuickBasic64\Extern-nicht-Basic\Basic-ruft-C\btenaerDreifach"
Function btenaerDreifach& (ByVal Zahl1 As Long, Byval Zahl2 As Long, Byval Zahl3 As Long)
End Declare
Dim As Long zahl1, zahl2, zahl3
Locate 3, 3
Print "Dreifachen tenaeren Operator in C aufrufen"
Locate 4, 3
Print "=========================================="
Locate 6, 3
Input "Zahl 1: ", zahl1
Locate 7, 3
Input "Zahl 2: ", zahl2
Locate 8, 3
Input "Zahl 3: ", zahl3
Locate 10, 3
Print Using "Die groesste Zahl ist: ####"; btenaerDreifach&(zahl1&, zahl2&, zahl3&)
End
Save the C program as btenaerDreifach.h
Code: (Select All)
//Dreifachen tenaeren Operator von Basic aufrufen - 7. Aug. 2024
#include <stdio.h>
#include <stdlib.h>
long btenaerDreifach(long zahl1, long zahl2, long zahl3)
{
long max;
max = (zahl1 > zahl2 ? ((zahl1 > zahl3) ? zahl1 : zahl3) : zahl2);
return(max);
}