Simple "printf" command

Wednesday, 1 May 2013

In making C/C++ programs we always encounter these commands: printf and %d. Both of these commands are vital in making programs because both of it are useful especially in printing integers for mathematical purposes. So, I thought of making a simple program to showcase the printf and %d commands.

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!

Related Posts Plugin for WordPress, Blogger...