Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

write a c++ program by using out txt file to ( #include <fstream> ) to determine

ID: 3773312 • Letter: W

Question

write a c++ program by using out txt file to ( #include <fstream> ) to determine whether an integer is divisible by 9 .an integer N is divisible by 9 if the sum of the digits is divisible by 9 if the sum of the digits is divisible by 9. Determine whether the following number are divisible by 9 which the nuber are :

N = 154368

N = 621594

N = 123456

---------------------------------------------------------------------------------------------------------

for example :N = 1+5+4+3+6+8 = 27 . 27 / 9 =0 . so it is divisble by 9.

Explanation / Answer

#include <iostream>
#include <fstream>
using namespace std;

int main () {
ifstream myfile;
myfile.open("out.txt");
int a,t=0,s=0;
    cout<<"enter the number";
    cin>>a;
    while(a>0)
    {
     t=a%10;
     s=t+s;
    a=a/10;
    }
if(s%9==0)
cout<<"divisible by 9";
else
cout<<"not divisible by 9";
myfile.close();
return 0;
}