ANSWERS: 9
  • If you want to add two ints, say x and y, without using an arithmetic operator you'll have to use a unary one and a loop (for loop is easiest). The unary operator to increment a value by one is "++" I'm not going to give you the program, because it's really damned easy (5 lines, tops), but you should be able to figure it out now.
  • DYOHW!
  • 1) Not exactly what you wanted, but maybe it helps you anyway to understand the language. This program does not use the "+" operator, but it uses the "-" arithmetic operator. "This section C++ : Basic Programming contains source codes of many Programs that are the Basics of Programming in C++. If you have not grip on these Basic Topics of C++, in my opinion, you cannot learn Advance Topics of C++." "CPP-143 A C++ Program to add two integers without using "+" operator." Source: http://www.wol.net.pk/mtshome/cppBasicProgramming.html http://www.wol.net.pk/mtshome/cpp/basicProgramming/CPP-143.zip You can also find many other programming examples on that page. 2) Here a very simple program to add two integers (using arithmetic operators): ######################### // Program to add two integers typed by user at keyboard #include <iostream> using namespace std; int main() { int a, b, total; cout << "Enter integers to be added:" << endl; cin >> a >> b; total = a + b; cout << "The sum is " << total << endl; return 0; } ######################### Source: http://www-mdp.eng.cam.ac.uk/CD/engapps/ctutor/editing.html 3) look at "Elise The-Special-One Randolph"'s answer
  • #include<stdio.h> #include<conio.h> void main() { int i,j; j=0; for(i=0;i<3;i++) { j++; } for(i=0;i<5;i++) { j++ } printf("n%d",j); }
  • #include<stdio.h> #include<conio.h> void main() { int m,n,i,j=0; printf("n enter value of m and n"); scanf("%d%d",&m,&n); for(i=0;i<m;i++) { j++; } for(i=0;i<n;i++) { j++; } printf("%d",j); getch(); }
  • Addition can be performed using XOR, AND, OR, and shift operations, in a similar way to how adders work inside of a CPU's ALU. Look up the "full adder" section on the wikipedia's page for "adder (electronic)". Using that, you should be able to write code that performs the same operation as the circuit. It will be much faster than using loops and "++" operators as others have suggested, not to mention that it's quite easy to argue that ++ *is* an arithmetic operator, because x++ is simply a short-hand form of "x = x + 1".
  • a = 3; b = 5; while(b != 0) { c = a ^ b; d = a & b; a = c; b = d << 1; } printf("%dn", a);
  • posted in the wrong place
  • (moved)

Copyright 2023, Wired Ivy, LLC

Answerbag | Terms of Service | Privacy Policy