Ticker

6/recent/ticker-posts

Adding Two Numbers Without Using The Plus(+) Operator

 // Special Programs in C − Adding Two Numbers Without Using The Plus Operator


1)First Logic

#include <stdio.h>


int main() {

    int a,b,sum;

    printf("enter the numbers\n");

    scanf("%d %d",&a,&b);


    sum=a-~b-1;

    printf("sum of two numbers=%d\n",sum);


    return 0;

}


output:-

enter the numbers

10 20

sum of two numbers=30


2)Second logic

#include <stdio.h>


int main() {

    int x,y;

    printf("enter the two number\n");

    scanf("%d %d",&x,&y);

    while(y != 0)

    {

        x++;

        y--;

    }

    printf("sum of two numbers=%d\n",x);

    return 0;

}


output:-

enter the two number

20 30

sum of two numbers=50

కామెంట్‌ను పోస్ట్ చేయండి

0 కామెంట్‌లు