Saturday, June 1, 2019


Multiply two integers without using multiplication, division and bitwise operators.

To multiply x and y, recursively add x y times.



#include<stdio.h>
/* function to multiply two numbers x and y*/
int multiply(int x, int y)
{
   /* 0  multiplied with anything gives 0 */
   if(y == 0)
     return 0;
  
   /* Add x one by one */ 
   if(y > 0 )
     return (x + multiply(x, y-1));
   
  /* the case where y is negative */ 
   if(y < 0 )
     return -multiply(x, -y);
}
  
int main()
{
  printf("\n %d", multiply(5, -11));
  getchar();
  return 0;
}

Trigraph characters in C language

  1. C supports the following 9 trigraph characters.

Trigraph sequenceEqual character
??=#
??([
??)]
??/\
??<{
??>}
??!|
??’^
??-~
We need to write a simple hello world program in the following way in the platform which doesn’t support #, {} and \ characters.
1
2
3
4
5
6
??=include<stdio.h>
int main()
??<
printf("Hello??/nWorld");
return 0;
??>
The trigraphs pre-processor changes the above code as
1
2
3
4
5
6
#include<stdio.h>
int main()
{
printf("Hello\nWorld");
return 0;
}
Trigraphs are not commonly supported by all the compilers. Some compilers support an option to turn recognition of trigraphs on. Some issues warnings when they encounter trigraphs in the source files.

Please write comments if you find any of the above code/algorithm incorrect, or find better ways to solve the same problem.
bhoopesh@ Web Developer

No comments:

Post a Comment

Programming in C

         What is C ?    C programming language is the basic and first level procedural oriented programming language. Those who wa...