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

preview_player
Показать описание
C Programming & Data Structures: Special C Programs − Adding Two Numbers Without Using The Plus Operator.
Topics discussed:
1) Adding two numbers using the increment and decrement operators.

Music:
Axol x Alex Skrindo - You [NCS Release]

#CProgrammingByNeso #CProgramming #PlusOperator

That's just weird image source:
Рекомендации по теме
Комментарии
Автор

I'm literally becoming smarter and more clever in coding because of Neso. Thank you so much Neso!

hetaeramancer
Автор

We can also run a for loop where I<=y and which will return x++. So the loop will run until Y. So it's basically x+y.

simasaha
Автор

I WAS able to solve the problem without actually looking at the solution, I did it using for loop instead,
thank you neso :)

devukun
Автор

This Can be done in few steps easily
Printf("The sum is %d", a-(-b));
Considering two no.s are a and b

roshanmhatre
Автор

in my opinion, increment and decrement are basically like add and subtract operators and there is other way without using them and can be used for negative and positive numbers.

eslamosamasaadfathallah
Автор

there is another method to solve this for positive as well as negative integer value
#include <stdio.h>
int main( )
{ int a, b, i;
printf("enter two number for addition\n");
scanf("%d%d", &a, &b);
for(i=1;i<=b;i++)
a++;
printf("sum of two number a and b is=%d", a);
return 0;
}

codebits
Автор

I've write the code just by seeing question ❓
All thanks to u bhaiya.

prathamchhajed
Автор

Real question would be add 2 no. without using any operator.
None of operator present in operator chart is allowed

anuraggupta
Автор

Home work problem needs a minor changes: use signed int....instead of int.

int main(){


signed int a, b;
printf("Enter num n...");
scanf("%d%d", &a, &b);

while(b!=0){
a++;
b--;
}
printf("Sum : %d", a);
return 0;
}

itihas_verma
Автор

I just did this:
int main()
{
int b, a;
printf("Enter two numbers to add together\n");
scanf("%d %d", &a, &b);

for (int i = 0; i < b; i++)
{
a++;
}
printf("%d", a);

}

laskdjf
Автор

I was thinking of x - ( -y ).
You make y to be negative then, subtract it from x

Example :
4 + 3 => 4 - ( -3 ) => 7

davisochieng
Автор

my answer before the example after seeing the algorithm

int x=3, y=4;

for (x != 0; y != 0; ++x){
y--;
}

printf("%d", x);

desuchan
Автор

include<stdio.h>

int main()
{
int i, x, y;
printf("Enter any two numbers to add: ");
scanf("%d%d", &x, &y);
if(y>0)
for(i=y;i!=0;i--)
x++;
else
for(i=y;i!=0;i++)
x--;
printf("Sum=%d", x);
return 0;
}



Tried by own and got the result🤩

RAVITEJAP-ssrl
Автор

int a = -13, b = 2, neg = 0, val = 0;

if(a < 0) {
neg = a;
val = b;
}
else {
neg = b;
val = a;
}
while(neg != 0) {
val--;
neg++;
}

System.out.println(val);

This is for Addition with a negative value (JAVA).

vinayakbhandage
Автор

Mind blowing explanation, keep uploading videos

kuntellashanker
Автор

Increment includes '+' ... So i used maths (a+b) = (a^2 - b^2)/(a-b) ...

OvaseRashid
Автор

Sir the video is nice.... But we are using + operater while incrementing it 😂😂😂

DSAbyraj
Автор

For Negative Numbers hope the following code works :

#include<stdio.h>

int main()
{
int x, y;

printf("Enter the two Numbers you want to add\n");
scanf("%d %d", &x, &y);

if(x<0)
{
while(x!=0)
{
x++;
y--;
}
}
else
{
while(x!=0)
{
x--;
y++;
}
}

printf("Sum of two values is %d", y);
}


Sir can you please comment on this.

prashanthchary
Автор

It can be solved simply using pointer, ++ and -- doesn't require 😊

BiswajitDas-jdji
Автор

this program can use for addition of negative integers also

NikhilKumar-evml