Wednesday, December 31, 2014

Basic input & output(2)

1:
#include<stdio.h>
///***formatted output:
int main( )
{
printf("%d",12345);
return 0;
}

output: 12345

2:
#include<stdio.h>
///***formatted output:
int main( )
{
printf("%5d",123);
return 0;

}

output:  123
///***it will show two space before 123





3:

#include<stdio.h>
///***formatted output:
int main( )
{
printf("%-5d %-5d",123,456);
return 0;

}

output:123  456

4:
#include<stdio.h>
///***formatted output:
int main( )
{
printf("%05d%5d",123,456);
return 0;

}

output: 00123  456

5:
#include<stdio.h>
///***formatted output:
int main( )
{
printf("%6.2f",12.0);
return 0;

}


output:  12.00  ///***one space before 12.00


 6:
#include<stdio.h>
///***formatted output:
int main( )
{
printf("%*.2f",6,12.0);
return 0;

}

output:  12.00

7:
#include<stdio.h>
///***formatted output:
int main( )
{
printf("%10.*f",2,12.0);
return 0;

}

output:     12.00 ///***five space before 12.00




 

No comments:

Post a Comment