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 >>

<< Go to Index Page >>

#include

ReplyDeletemain()

{

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;

}

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

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

ReplyDelete#include"stdio.h"

ReplyDeletemain(){

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);

}

}

#include

ReplyDeletemain()

{

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();

}

NAME:Mahmuda sultana

ReplyDeleteID: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;

}

Summer 2017

ReplyDeleteID#201610042

Answer to Question No 7:

https://drive.google.com/file/d/0B99eePh0LV8gLVY0YndXQmdPMzg/view?usp=drivesdk

ID : 201620195

ReplyDeletehttps://drive.google.com/open?id=0B9K31ospCyFjVkdHOXE3Y001a1k

https://drive.google.com/open?id=0BzTqZMBWR6eObXRtaW5JOWhiQjA

ReplyDeletehttps://drive.google.com/open?id=0B8369pAqjVVpdHBPMnhLZ2RIb3M

ReplyDeleteID:201520552

ReplyDeletehttps://drive.google.com/open?id=0B5pG0kIjzgEKU2c1N010dloyWEk

ID 201610456

ReplyDeleteMD USUF MIA

https://drive.google.com/open?id=0B_PIGnOMR0K2Nk9UbU90NjFmN3M

ID 201610456

ReplyDeleteMD USUF MIA

without using any loop

https://drive.google.com/open?id=0B_PIGnOMR0K2RUh0TW5GZ3d4c1k

Id= 201710494

ReplyDeletehttps://www.dropbox.com/s/p5u5fzl67jpfnow/prob%207.cpp?dl=0

https://drive.google.com/open?id=0Byxq3aat_mNSd19RWWdTNlZIQU0

ReplyDeletehttps://drive.google.com/open?id=0B3bVD5Ppt_STUjJJcmEydTBJbEU

ReplyDelete#include

ReplyDeleteint main()

{

int first, second, add, subtract, multiply;

float divide;

printf("Enter two integers\n");

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

add = first + second;

subtract = first - second;

multiply = first * second;

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

printf("Sum = %d\n", add);

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

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

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

return 0;

}

#include

ReplyDeleteint main()

{

int first, second, add, subtract, multiply;

float divide;

printf("Enter two integers\n");

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

add = first + second;

subtract = first - second;

multiply = first * second;

divide = first / (float)second;

printf("Sum = %d\n", add);

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

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

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

return 0;

}

Name- Md.Shariat-ullah

ReplyDeleteID No- 201811211

#include

int main()

{

int first, second, add, subtract, multiply;

float divide;

printf("Enter two integers\n");

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

add = first + second;

subtract = first - second;

multiply = first * second;

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

printf("Sum = %d\n", add);

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

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

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

return 0;

}

#include

ReplyDeleteint main()

{

int first, second, add, subtract, multiply;

float divide;

printf("Enter two integers\n");

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

add = first + second;

subtract = first - second;

multiply = first * second;

divide = first / (float)second;

printf("Sum = %d\n", add);

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

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

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

return 0;

}

#include

ReplyDeleteint main()

{

int first, second, add, subtract, multiply;

float divide;

printf("Enter two integers\n");

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

add = first + second;

subtract = first - second;

multiply = first * second;

divide = first / (float)second;

printf("Sum = %d\n", add);

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

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

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

return 0;

ID:201820244

ReplyDeleteBatch: 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);

}

#include

ReplyDeletevoid 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);

}

ID# 201830546

ReplyDelete#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;

}

Name : Firoj Ahmed

ReplyDeleteID : 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;

}

ID: 201810461

ReplyDelete//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()

}

cout<<"\n Addition of two numbers:"<<sum;

}

};

ID: 201810461

ReplyDeleteOverloading

#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;

}