//Adding two numbers using pointers
#include<stdio.h>
void main()
{
int *a,*b,c,n1,n2;
scanf("%d %d",&n1,&n2);
a=&n1;
b=&n2;
c=*a+*b;
printf("Added value is:%d",c);
}
#include<stdio.h>
#include<conio.h>
main()
{
int sum(int a,int b,int c);/*function prototype*/
int x,y,z;
clrscr();
printf("enter two values to perform addition:");
scanf("d,&x,&y);
sum(x,y,z);
printf("addition result: %d",sum(x,y,z));
getch();
return 0;
}
int sum(int a,int b,int c)
{
c=a+b;
return c;
}
Algorithm in C Language:
int *a,*b; //Declaraction of the two pointers
int sum;
scanf("%d%d",a,b); //Reading values of the 2 variables
sum=*a+*b;
printf("SUM = %d",sum);
Not possible. Let's not forget than in C the followings are all operators:+, -+=, -=++, --=&, *, []function-call
int main() { int a=10,b=20; while(a--) b++; printf("%d",b); } or: a -= -b;
It is very easy. The program begins here..... /*Program to sum and print numbers without creating variables*/ #include<stdio.h> main() { clrscr(); printf("%d+%d=%d",5,2,5+2); getch(); } /*Program ends here*/ Now just by changing the numbers in the "printf" statement we can add, subtract, multiply and divide the numbers without using variables. Hence the problem is solved..........
#include<iostream.h> #include<conio.h> void main() { int a, b, c; clrscr(); cout<<"enter the two numbers"; cin>>a; cin>b; c=a+b; cout<<"Addition of two numbers="<<c; getch(); }
Add the five numbers; divide the result by 5.
Write a program using the ADI instruction to add the two hexadecimal numbers 3AH and 48H and store the result in memory location 2100H
If you simply add numbers the answer is the sum of those numbers.
int* a = new int(40); int* b = new int(2); int x = *a + *b; // x = 42 delete b; delete a;
You can easily add together lots of numbers, create graphs, and compute things using formulas on large amounts of data.
Using the additive property (+).
Not possible. Let's not forget than in C the followings are all operators:+, -+=, -=++, --=&, *, []function-call
The best method is to add the numbers, using arithmetic.
Add the numbers into one variable as you read them in. But if you prefer, you can read the numbers into an array and then use a loop to add the numbers together.
you ADD all the #s
USING STRING LITERAL VALUES TO ADD 2 NUMBERS If you just want to show the outcome of two numbers you have: PRINT 4 + 5 This will print '9' the answer to 4 + 5. If you want to show the addition: PRINT "4 + 5 = "; 4 + 5 This will show the question and then calculate the answer. If you want the user to input numbers to add, use variables and then add them the same way. ====== COLLECTING USER INPUT FROM THE KEYBOARD/USING NUMERIC VARIABLES In the following example, the end user can get to interact with the program by typing in their numbers at the keyboard; then, pressing the [Enter] key. CLS PRINT "PROGRAM: Add 2 numbers" PRINT INPUT "Enter the 1st number: ", number1 INPUT "Enter the 2nd number: ", number2 PRINT sumTotal=number1+number2 PRINT "The sum total is: "; sumTotal PRINT INPUT "Again, Y/N"; yesNo$ IF UCASE$(LEFT$(yesNo$,1))="Y" THEN RUN END ====== CREATE FUNCTION/THEN, MAKE A FUNCTION CALL TO ADD 2 NUMBERS Another way to write this program is to create a function/then, make a function call... '*** PROGRAM: Add 2 numbers... '*** Variable declaration list... number1=7 '...initialise numeric variable 1 number2=3 '...initialise numeric variable 2 '*** Main program... CLS '...(CL)ear the (S)creen PRINT add(number1,number2) '...make function call/passing in 2 numbers to add END '...END of program/halt program code execution '*** Function(s)... FUNCTION add(num1,num2) '...this line marks the start of the Function add=num1+num2 '...this line returns the sum total of the 2 numbers END FUNCTION '...this line marks the end of the Function
add them all together and then divide the answer by the number of numbers.
Mov a.#000ff, mov b,#0008f add a,b