1.a.
Enter a number: 15
Code15 1 14
HelloWorld
1.b.
#include <stdio.h>
int main(){
int n;
printf("Enter number: "); scanf("%d",&n);
(n >= 0) ? printf("Positive") : printf("Negative");
return 0;
}
1.c.
- True
- True
- False
- True
- True
1.d.
1.e.
#include <stdio.h>
int main(){
int customerID;
char customerName[100];
int waterUnits;
float bill;
printf("Enter Customer ID: "); scanf("%d",&customerID);
printf("Enter name: "); scanf("%s",customerName);
printf("Enter units of Water consumed: "); scanf("%d",&waterUnits);
if (waterUnits > 150){
bill = (50*1)+(50*1.50)+((waterUnits-150)*2.50);
}
else if (waterUnits > 50 && waterUnits <= 150){
bill = 50 + ((waterUnits-50)*1.50);
}
else{
bill = waterUnits;
}
printf("---Water Bill---\nCustomer ID: %d\nCustomer name: %s\nUnits used: %d\nTotal Bill: %d",customerID,customerName,waterUnits,bill);
return 0;
}
graph LR
subgraph Inputs
A[Input A]
B[Input B]
end
subgraph XOR Gate using NANDs
N1[NAND]
N2[NAND]
N3[NAND]
N4[NAND]
N5[NAND]
end
A --> N1
A --> N2
B --> N1
B --> N2
N1 --> N3
N2 --> N4
A --> N5
B --> N5
N3 --> N5
N4 --> N5
N5 --> Q(Output Q = A XOR B)