Summarize the purpose of the format strings (like %s, %d, %c) that are’ commonly used within the printf function, with an example for each.10m Jun2006

By | June 13, 2014

Summarize the purpose of the format strings (like %s, %d, %c) that are’ commonly used within the printf function, with an example for each.10m Jun2006

If printf function format includes format specifiers (subsequences beginning with %), the additional arguments following format are formatted and inserted in the resulting string replacing their respective specifiers. It can optionally contain embedded format specifiers that are replaced by the values specified in subsequent additional arguments and formatted as requested.

 A format specifier follows this prototype: %[flags][width][.precision][length]specifier

 Where the specifier character at the end is the most significant component, since it defines the type and the interpretation of its corresponding argument:

s           String of characters

d          Signed decimal integer

c          Character

 Example:

#include <stdio.h>
void main()
{
   printf (“%s \n”, “A string”);
   printf (“Decimals: %d \n”, 1977);
   printf (“Characters: %c %c \n”, ‘a’, 65);
   getch();
}

Output:

A string
Decimal: 1977
Characters: a A

 

 When can two matrices of order a x b and c x d be subtracted? Also write a program in C to find the difference of two such matrices. 10m Jun2006

 To be able to add or subtract two matrices, they must be of the same size. If they are not the same size (if they do not have the same “dimensions”), then the addition is “not defined” (doesn’t make mathematical sense).

 Solved program can be found on this link http://cssimplified.com/c-programming/an-interactive-c-program-to-add-two-matrices-or-subtract-two-matrices

Leave a Reply