Answer to Question #188262 in C++ for m abdulah hassan

Question #188262

Write a program to read from “data.txt” that contains more than 1 digit of integers. Then you have to find the number which have same digits like (444, 3333, 11). You should make as many functions as you can with proper naming convention.


1
Expert's answer
2021-05-02T18:13:45-0400


#include<iostream>
#include <stdio.h>
#include <string>
using namespace std;


main(void)
{
	fstream infile; 
	int x,Sum;
	string Name = "H:\\Data.txt";
	infile.open(Name.c_str());
    if (!infile) 
	{
	    cout << "Unable to open file: "<<Name;
        exit(1); // terminate with error
    }
	else
	{
		while(infile >> x)
		{
			string str; // a variable of str data type
			stringstream ss;  
		  	ss<< x;  ss >> str;  	
		  	Sum=0;
		  	for(int r=0;r<str.length();r++) Sum = Sum + str[r]-str[0];
		  	if(Sum==0) cout<<x<<endl;
		}
		infile.close();
	}
}


Input File





Output:





Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS