Programming C : printf stdio.h ex4

using printf arguments

  
#include <stdio.h>

int main( )
{
 char   psz1[]   =   "this is a test",
        psz2[]   =   "string text.";
 
 
 printf("%*.*s",19,6,psz1); 
}

width 10, 8 to right of '.'

  
#include <stdio.h>

int main( )
{

 double dPi      =   3.14159265;
 
 printf("%10.8f",dPi); 
}

width 20, 2 to right-justify

  
#include <stdio.h>

int main( )
{
 double dPi      =   3.14159265;
 
 printf("%20.2f",dPi); 
}

4 decimal places, left-justify

  
#include <stdio.h>

int main( )
{
 double dPi      =   3.14159265;
 
 printf("%-20.4f",dPi); 
}

decimal places, right-justify

  
#include <stdio.h>

int main( )
{
 double dPi      =   3.14159265;
 
 printf("%20.4f",dPi); 
}
  

width 20, scientific notation

  
#include <stdio.h>

int main( )
{
 double dPi      =   3.14159265;
 
 printf("%20.2e",dPi);
 
}

printf %s for string

  
#include <stdio.h>
int main()
{
   printf("%s","hello world\n");

   char *phrase = "Hello again!\n";
   printf("%s",phrase);

   return 0;
}

printf %d for integer

  
#include <stdio.h>
int main()
{
   int x = 5;
   printf("%d\n",x);

   return 0;
}
  

printf %ld for long integer number

  
#include <stdio.h>
int main()
{
   char *phraseTwo = "Here's some values: ";
   char *phraseThree = " and also these: ";
   int y = 7, z = 35;
   long longVar = 98456;
   float floatVar =  8.8;

   printf("%s %d %d %s %ld %f\n",phraseTwo,y,z,phraseThree,longVar,floatVar);

   return 0;
}