Index-1              Index-2              Home Page

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

27 comments:

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

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

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

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

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

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

    ReplyDelete
  7. Summer 2017
    ID#201610042

    Answer to Question No 7:
    https://drive.google.com/file/d/0B99eePh0LV8gLVY0YndXQmdPMzg/view?usp=drivesdk

    ReplyDelete
  8. ID : 201620195
    https://drive.google.com/open?id=0B9K31ospCyFjVkdHOXE3Y001a1k

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

    ReplyDelete
  10. https://drive.google.com/open?id=0B8369pAqjVVpdHBPMnhLZ2RIb3M

    ReplyDelete
  11. ID:201520552
    https://drive.google.com/open?id=0B5pG0kIjzgEKU2c1N010dloyWEk

    ReplyDelete
  12. ID 201610456
    MD USUF MIA
    https://drive.google.com/open?id=0B_PIGnOMR0K2Nk9UbU90NjFmN3M

    ReplyDelete
  13. ID 201610456
    MD USUF MIA
    without using any loop
    https://drive.google.com/open?id=0B_PIGnOMR0K2RUh0TW5GZ3d4c1k

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

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

    ReplyDelete
  16. https://drive.google.com/open?id=0B3bVD5Ppt_STUjJJcmEydTBJbEU

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


    }

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

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

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

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

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

    return 0;


    }

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

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

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

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

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

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

    return 0;


    }

    ReplyDelete
  21. #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;
    printf("Sum = %d\n", add);
    printf("Difference = %d\n", subtract);
    printf("Multiplication = %d\n", multiply);
    printf("Division = %.2f\n", divide);
    return 0;

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

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

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

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

    ReplyDelete
  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()
    }
    cout<<"\n Addition of two numbers:"<<sum;
    }
    };

    ReplyDelete
  27. ID: 201810461
    Overloading
    #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;
    }

    ReplyDelete