Answers for "prepend 0s c++ to make five digits"

C++
6

how to print a decimal number upto 6 places of decimal in c++

#include <iostream>
#include <iomanip>

int main()
{
    double d = 122.345;

    std::cout << std::fixed;
    std::cout << std::setprecision(2);
    std::cout << d;
}
Posted by: Guest on May-19-2020
1

To add all the digits of a number till you get a single digit.

#include<bits/stdc++.h> 
using namespace std; 
int digSum(int n) 
{ 
	if (n == 0) 
	return 0; 
	return (n % 9 == 0) ? 9 : (n % 9); 
} 
int main() 
{ 
	int n = 9999; 
	cout<<digSum(n); 
	return 0; 
}
Posted by: Guest on August-17-2020

Browse Popular Code Answers by Language