Furthermore, printf command is used to instruct the computer to perform an action. While, %d is a conversion specifier which means that an integer must be printed out on the screen. In this program, it shows how to use the printf and %d commands. It will simply call the integers declared at the top and there will be no need to get inputs from the user. Check out the codes below.
#include<stdio.h> #include<conio.h> main() { int var1 = 9, var2 = 10, var3 = 9; if(var1!=var2) printf("\n%d", var1); if(var1!=var3) printf("\n\n%d", var1); printf("\n%d", var2); printf("\n%d", var3); getch(); }
In the sample program, there are three (3) variables declared with their respective values. In the first if statement, variable 1 is compared to variable 2 with a not equal to symbol (!=). If variable 1 satisfies the argument then it will print var1. After that, it will jump to the next if statement if it satisfies the argument then it will print either var1, var2 or var3. Then program terminates. Check out the sample output below.
Hope you learned something. Feel free to leave a comment below. Thanks!
No comments:
Post a Comment
Please do leave a comment. It's gonna be a friendly conversation between programmers. Hope you do find our blog helpful. Thank you!