You are on page 1of 7

Name : MUHAMED HASHIM SADIKI

CSDFE

Qn1: write a code with two integer variables to perform addition

#include<iostream>

using namespace std;

int main(){

int mud;

int sad;

int col;

Mud=20;

Sad=15;

Col=mud+sad;

cout<<"the answer is "<<col;

return 0;

Initially the computer memory

FREE
FREE
FREE
FREE
FREE

Declaring data variables

Mud RESERVED
sad RESERVED
Col RESERVED
FREE
FREE
Storing data to the variables

Mud 20
Sad 15
Col RESERVED
FREE
FREE

Qn2:write a code with three integer variables to perform addition

#include<iostream>

using namespace std;

int main(){

int mud;

int sad;

int ros;

int col;

Mud=23;

Sad=39;

Ros=18;

Col=Mud+Sad+Ros;

cout<<"the answer is"<<Col;

return 0;

Initially the computer memory

FREE
FREE
FREE
FREE
FREE

Declaring data variables

Mud RESERVED
Sad RESERVED
Ros RESERVED
Col RESERVED
FREE

Storing data to the variables

Mud 23
Sad 39
Ros 18
Col RESERVED
FREE

Qn3:write code to perform multiplication of three numbers

#include<iostream>

using namespace std;

int main(){

int mud;

int sad;

int ros;

int col;

Mud=3;

Sad=4;

Ros=7;

Col=mud*sad*ros;

cout<<"the answer is "<<col;

return 0;

Initially the computer memory

FREE
FREE
FREE
FREE
FREE
Declaring data variables

Mud RESERVED
Sad RESERVED
Ros RESERVED
Col RESERVED
FREE

Storing data to the variables

Mud 3
Sad 4
Ros 7
Col RESERVED
FREE

Qn4:write a code to perform subtraction of two numbers

#include<iostream>

using namespace std;

int main(){

int mud;

int sad;

int ros;

Mud=32;

Sad=29;

Ros =mud-sad;

cout<<"the answer is "<<ros;

return 0;

Initially the computer memory

FREE
FREE
FREE
FREE
FREE
Declaring data variables

Mud RESERVED
sad RESERVED
Ros RESERVED
FREE
FREE

Storing data to the variables

Mud 32
sad 29
Ros RESERVED
FREE
FREE

Qn5:modify question 4 such that the answer will always be positive

#include<iostream>

using namespace std;

int main(){

int a;

int m;

int s;

a=12;

m=23;

if(a>m){

s=a-m;}

else{

s=m-a;}

cout<<"the answer is "<<s;

return 0;

Initially the computer memory


FREE
FREE
FREE
FREE
FREE

Declaring data variables

a RESERVED
m RESERVED
s RESERVED
FREE
FREE

Storing data to the variables

a 12
m 23
s RESERVED
FREE
FREE

Qn6:write a code to perform repeated addition of integers from 1 to 10

#include<iostream>

using namespace std;

int main(){

int a=1;

int sum=0;

while(a<=10){

sum=sum+a;

a++;

cout<<"the answer is "<<sum;

return 0;

Initially the computer memory


FREE
FREE
FREE
FREE
FREE

Declaring data variables

a RESERVED
s RESERVED
FREE
FREE
FREE

Storing data to the variables

a 20
s RESERVED
FREE
FREE
FREE

You might also like