Arithmatic Operation

Write and run a program that reads a six digit integer and prints the sum of its six digits. Use the quotient operator(/) and the remainder operator(%) to extract the digit from the integer. For example, if N is the integer 876543 then n/1000%10 is its thousands digit 6.

<< Go to Index Page >>

1. #include
main()
{
int i, j, n=100000, sum=0;
while(scanf("%d", &i)==1)
{
while(i>0)
{
j=i/n;
i=i%n;
n=n/10;
sum+=j;
}
printf("%d\n", sum);
sum=0;
n=100000;
}
return 0;
}

2. Great job.Why didn't use getch();?

3. It is a continuous program. never end if you don't close the exe window. For that reason, getch() is useless.

4. #include"stdio.h"
main(){
int a,i,sum=0,count=0;
scanf("%d",&a);
if(a!=0){
while(a>0){
i=a%10;
a=a/10;
sum+=i;
count++;
}
printf("Sum is %d\n",sum);
printf("Number of digit is %d\n",count);
}
}

5. #include
main()
{
int x,y,k=0;
printf("Enter the number");
scanf("%d",&x);
while(x>0)
{
y=x%10;
k=k+y;
x=x/10;
}
printf("%d",k);
getch();
}

6. NAME:Mahmuda sultana
ID:201330499
#include
using namespace std;
class A
{
public:
int i,sum=0,count=0;
int get_inp(int a)
{
b=a;
}
protected:
int b;
};
class B:public A
{
public:
int arithmatic()
{
if(b!=0)
{
while(b>0)
{
i=b%10;
b=b/10;
sum+=i;
count++;
}
cout<<"Sum is:"<>a;
bb.get_inp(a);
bb.arithmatic();
return 0;
}

7. Summer 2017
ID#201610042

8. ID : 201620195

11. ID:201520552

12. ID 201610456
MD USUF MIA

13. ID 201610456
MD USUF MIA
without using any loop

14. Id= 201710494
https://www.dropbox.com/s/p5u5fzl67jpfnow/prob%207.cpp?dl=0

17. #include

int main()

{

int first, second, add, subtract, multiply;

float divide;

printf("Enter two integers\n");

scanf("%d%d", &first, &second);

subtract = first - second;

multiply = first * second;

divide = first / (float)second; //typecasting

printf("Difference = %d\n", subtract);

printf("Multiplication = %d\n", multiply);

printf("Division = %.2f\n", divide);

return 0;

}

18. #include

int main()

{

int first, second, add, subtract, multiply;

float divide;

printf("Enter two integers\n");

scanf("%d%d", &first, &second);

subtract = first - second;

multiply = first * second;

divide = first / (float)second;

printf("Difference = %d\n", subtract);

printf("Multiplication = %d\n", multiply);

printf("Division = %.2f\n", divide);

return 0;

}

19. Name- Md.Shariat-ullah
ID No- 201811211

#include
int main()
{
int first, second, add, subtract, multiply;
float divide;
printf("Enter two integers\n");
scanf("%d%d", &first, &second);
subtract = first - second;
multiply = first * second;
divide = first / (float)second; //typecasting
printf("Difference = %d\n", subtract);
printf("Multiplication = %d\n", multiply);
printf("Division = %.2f\n", divide);
return 0;
}

20. #include
int main()
{
int first, second, add, subtract, multiply;

float divide;

printf("Enter two integers\n");

scanf("%d%d", &first, &second);

subtract = first - second;

multiply = first * second;

divide = first / (float)second;

printf("Difference = %d\n", subtract);

printf("Multiplication = %d\n", multiply);

printf("Division = %.2f\n", divide);

return 0;

}

21. #include
int main()
{
int first, second, add, subtract, multiply;
float divide;
printf("Enter two integers\n");
scanf("%d%d", &first, &second);
subtract = first - second;
multiply = first * second;
divide = first / (float)second;
printf("Difference = %d\n", subtract);
printf("Multiplication = %d\n", multiply);
printf("Division = %.2f\n", divide);
return 0;

22. ID:201820244
Batch: 58th
section: B
#include
void sub(int);
int main(void) {
int age = 22;
printf("In the main routine, age is %d\n", age);
sub(11);
return 0;
}
void sub(int in ) {
int age = 33;
printf("In the subroutine, you passed in %d, and age is %d\n", in, age);
}

23. #include
void sub(int);
int main(void) {
int age = 22;
printf("In the main routine, age is %d\n", age);
sub(11);
return 0;
}
void sub(int in ) {
int age = 33;
printf("In the subroutine, you passed in %d, and age is %d\n", in, age);
}

24. ID# 201830546

#include
using namespace std;
main()
{
int x, y, n=100000, sum=0;
cout << "Enter a six digit integer number : ";
cin>> x;
while(x==1)
{
while(x>0)
{
y=x/n;
x=x%n;
n=n/10;
sum=sum+y;
}
cout<< “Sum of six digit integer number is : ” sum;
sum=0;
n=100000;
}
return 0;
}

25. Name : Firoj Ahmed
ID : 201820222
Batch : 201820222

1. #include
using namespace std;

class digit
{
public:
int n,d;
int sum()
{
int s=0;
d = 0;
while(n)
{
s += n % 10;
n = n / 10;
d++;
}
return s;
}
};

int main()
{
digit sum;
cout << "Enter a six digit integer number : ";
cin >> sum.n;
cout << "The sum of " << sum.d << " digits is " << sum.sum() << endl;
return 0;
}

26. ID: 201810461
//Arithmetic operations using inheritance//
#include

using namespace std;

class A
{
int num1,num2;
{
cout<<"\n Enter first number:";
cin>>num1;
cout<<"\n Enter second number:";
cin>>num2;
}
};
{
int sum;
{
sum =num1+num2
}
void display()
}
}
};

27. ID: 201810461
#include

using namespace std;

class Test
{
private:
int count;
public:
Test():cout(5){}
void operator ++()
{
count = count+1;
}
void display(){ cout<<"count: "<<count;}
};
int main()
{
Test t;
++t;
t.display();
return 0;
}