mercredi 21 juin 2017

C:Error using conditional operators .

This is the C code i wrote in NetBeans build 8.2 to get the largest of all three numbers

#include <cstdlib>
#include <stdio.h>
using namespace std;
int main(int argc, char** argv) {
int a,b,c,d;
printf("Gimme 3 numbers");
scanf("%d %d %d",&a,&b,&c);
d=(a>b?(c>a?3:1):(c>b?3:2));
if (d=1)
   printf("%d is largest\n",a);
if (d=2)
   printf("%d is largest\n",b);
if (d=3)
   printf("%d is largest\n",c);

return 0;
}



 The output was :
 Gimme 3 numbers1 2 3
 1 is largest 
 2 is largest
 3 is largest
 Run successful (total time :2seconds)

Any idea why this might be occuring?Complete noob here

Aucun commentaire:

Enregistrer un commentaire