Like us on google+

Friday, 25 October 2013

Widgets

PROGRAM TO ADD TWO NON ZERO POSITIVE INTEGERS WITHOUT USING OPERATORS.

#include<stdio.h>
int add(int x,int y);
int main(){
   
    int a,b;
    int sum;
    printf("Enter two non zero positive integers: ");
    scanf("%d%d",&a,&b);
    sum=add(a,b);
     printf("Sum : %d",sum);

    return 0;
}

int add(int x,int y)
{
    int value=printf("%*c%*c",x,' ',y,' ');
    return value;  

}
------------------------------------------------------
Sample output:Enter two non zero positive integers:5 6
              Sum:11 

------------------------------------------------------
Description:
Two non zero positive integers are taken as input from the user and these values are passed as an argument to the add function.( 5 and 6 are passed as argument.)

int add(int x,int y) :x has the value 5 and y has the  value 6.

int value=printf("%*c%*c",x,' ',y,' '); 
printf counts the number of characters printed and the count is stored int the integer variable value which is nothing but the sum of x and y. 

Note in %*c :specified width is being substituted in place of *.
-------------------------------------------------------
Any queries don't hesitate to ask.... I hope this post was helpful. 

SHARE THIS POST   

  • Facebook
  • Twitter
  • Myspace
  • Google Buzz
  • Reddit
  • Stumnleupon
  • Delicious
  • Digg
  • Technorati
About us:
Hi guys Sandesh and Rajesh here ... studing engineering in PESIT started this blog as a google contest and also we love blogging ...Hope u like it ...Encourage us by liking us on g+... Any queries dont hesitate to ask Read More →

0 comments: