C/C++ :: Number Of Zeros In Factorial Number
Aug 9, 2012
It is given an integer "p". I have to find a number "n" for which "n factorial" has "p" numbers of zero at the end. Here is the solution i thought, but i am not sure if it is a solution for this problem. Do i have to make a function to calculate the factorial and another function to get the zeros?
int p;
int count5=0;
int i;
int copy_i;
printf("Enter p: ");
scanf("%d",&p);
for(i=1; ;i++) {
[Code] .....
View 1 Replies
ADVERTISEMENT
Jan 20, 2014
With the loop below, is there a way to display the actual number without the leading zeros (scientific notation) or will it just display 0 since there are so many leading zeros?
num = 1;
while (num > 0){
num /= 2;
}
cout << num;
View 6 Replies
View Related
Mar 26, 2014
I'm trying to run a factorial program but I'm getting the error statement has not effect.
here's the code
#include <iostream>
using namespace std;
int main() {
int fac = 0;
int sum = 0;
[Code] ....
the error happened in the int main section
View 3 Replies
View Related
Aug 28, 2013
I just want to practice in the language so i wrote this simple function that computes the factorial result of a certain number. The problem is that for all numbers > 20, the results are wrong ( < 20 all good).
I already learned that normal "long" type in c is more like 32 bit int and not 64 bit like a long type in java. so I used here a "long long" type.
why am I getting strange results above the number 20? isn't 64 bit enough to hold those numbers?
Code:
long long factorial(int n);
int main() {
long long result = factorial(20);
printf("%lld",result);
[code] ...
for 21 i get: -4249290049419214848
where the right result shoud be: 51,090,942,171,709,440,000
View 8 Replies
View Related
Oct 8, 2014
Write a C++ program that will input from the user a positive number n and find its factorial. Don’t forget to validate the input. The factorial of a positive integer n (denoted by n!) is defines as the product of the integers from 1 to n.
n! = 1* 2 * 3 * ... * (n - 1) * n
You should allow the user to continue working with your program for additional data sets.
Sample output:
Please enter a number: 5
5! = 120
Would you like to continue (Y/N)?Y
Please enter a number: 3
3! = 6
Would you like to continue (Y/N)?N
Good Bye!!
My code for what i think I'm doing is as follows:
#include <iostream>
using namespace std;
int main(){
int i=1;
int n;
[Code] ....
View 1 Replies
View Related
Oct 24, 2014
write a program that computes the factorial of a number and displays it. A factorial of a number (written N!) is defined as N * (N-1) * (N-2) * (N-3) ... *1 In other words, 5! = 5 * 4 * 3 * 2 * 1 = 120 and 3! = 3 * 2 * 1 + 6.
Example of output 15 is 1.30767e+012
Can't get it to display error when user enters a number lower than 2 or higher 60.
// Program to calculate factorial of a number
#include <iostream>
#include <iomanip>
[Code].....
View 13 Replies
View Related
Feb 24, 2013
I was given a question in my programming class to create a program to find the factorial of any number greater than zero and to use Gosper's formula to approximate it.
Code:
#include <stdio.h>
#include <math.h>
#define PI 3.14159265
double equation(int n);
int
[Code] ....
View 2 Replies
View Related
Sep 27, 2014
I started to learn programming through this site two weeks or so ago. I've got a book with exercices and so on, and one of them involves calculating e within a tolerance given by the user.
The formula for calculating e is the summation of 1+(1/i!), where i -> n.
So, here's the code and I'll explain the problem below:
Code:
#include <stdio.h>
int main()
{
float error;
float terme;
float sumatori = 0;
int cicle_euler = 1;
int factorial;
[Code]...
For some reason, when I set factorial to cicle_factorial, factorial remains 0, which I find puzzling; the program always halts when 1 + sumatori is 2.0 no matter what error is.
This must be a common problem and I suspect it has to do with some distinction between variables inside a loop and variables outside it, but as I lack technical vocabulary I can't seem to find anything on Google.
View 10 Replies
View Related
Oct 9, 2013
I was told to use a round function to round a number to give an integer number that is closer to the real value. (for example if the number is 114.67 I need to print an int value of 115 instead of 114)
I am not exactly sure how a round function works, but I am told to include math.h library. What I try doesn't seem to work.
View 1 Replies
View Related
Feb 6, 2014
In this program what i'm doing is to search for a number when the vector is in order, and count how many times that number appears, the problem is that count how many times the number does not appear, but when its appear the program stays in an "standby mode" and the cursor does not move.
int buscarNumOrdenado (int x [MAX]) //MAX is the define {
int num,d, LimiteInferior, LimiteSuperior,mitad;
d=0;
LimiteInferior = 0;
LimiteSuperior = MAX-1;
[Code] ....
View 2 Replies
View Related
Nov 3, 2013
I need to write a program that will allow the user to enter a number "n" and the program tell you that the nth prime number is .....
EXAMPLE
user enters 55
printf("The 55th prime number is %i", variable");
View 1 Replies
View Related
Apr 26, 2013
I need to write a code in c++ , to input decimal number and the output to be number in Scientific notation with 32 bits .
View 1 Replies
View Related
Feb 19, 2014
So I have a template, part of a larger code, that is designed to calculate the number of multiplications it took to reach a certain number. The problem is, whenever I execute the program, mults is always printing out a strange number, perhaps its actual address.
template <class T>
T power3(T x, unsigned int n, unsigned int& mults) {
if (n == 0) return 1;
if (n == 1) return x;
if (n == 2){
[Code] ....
View 10 Replies
View Related
Nov 20, 2014
I am attempting to write code that receives a number from the user and outputs the largest prime number underneath the user's number. There are no errors in my code, but no matter what number is imputed, the program says the largest prime number is 1. I cannot find where the issue is in the code. Here is the code I wrote:
#include <cstdlib>
#include <iostream>
#include <cmath>
using namespace std;
bool isPrime(int num);//function prototype
[Code] ....
View 2 Replies
View Related
Sep 26, 2012
I'm running a game online and designing a program to generate Enemy Stats. Basically, it's supposed to generate 25 numbers between 0 and 7(to represent 8 Attributes on a 25 Point Buy system) and count how many times each number shows up.
Here's what the code looks like:
Code:
#include <iostream>
#include <ctime>
#include <cstdlib>
using namespace std;
int Generate() {
int r= rand();
int s= r%7;
[Code] ....
And here's two outputs.
1: Code:
12133089220 12133089220 12133089220 12133089220 12133089220 12133089220 12133089220 12133089220 12133089220 12133089220 12133089220 12133089220 12133089220 12133089220 12133089220 12133089220 12133089220 12133089220 12133089220 12133089220 12133089220 12133089220 12133089220 12133089220 12133089220 Stats[0]= 25 Stats[1]= 0 Stats[2]= 0 Stats[3]= 0 Stats[4]= 0 Stats[5]= 0 Stats[6]= 0 Stats[7]= 0 Stats[8]= 0 Disallowed system call: SYS_socketcall
2: Code:
14787708434 14787708434 14787708434 14787708434 14787708434 14787708434 14787708434 14787708434 14787708434 14787708434 14787708434 14787708434 14787708434 14787708434 14787708434 14787708434 14787708434 14787708434 14787708434 14787708434 14787708434 14787708434 14787708434 14787708434 14787708434 Stats[0]= 0 Stats[1]= 0 Stats[2]= 0 Stats[3]= 0 Stats[4]= 25 Stats[5]= 0 Stats[6]= 0 Stats[7]= 0 Stats[8]= 0 Disallowed system call: SYS_socketcall
Note that the number does change, but only between runs.
View 3 Replies
View Related
Jul 6, 2013
Code: Complete the program below which converts a binary number into a decimal number. Sample outputs are shown belowComplete the program below which converts a binary number into a decimal number. Sample outputs are shown below.
Sample Output 1:
8-bit Binary Number => 11111111
Decimal Number = 255
Sample Output 2:
8-bit Binary Number => 10101010
Decimal Number = 170
Sample Output 3:
8-bit Binary Number => 101010102
Number entered is not a binary number
#include <iostream>
using namespace std;
int main()
{
int num;
[code]....
View 2 Replies
View Related
Nov 14, 2014
Q. WAP to find the next palindrome number larger than the input number.
for eg:-
Input=25
Output=33
The program is giving correct output for number with all digits '9';
why is it not giving output.
#include<iostream>
#include<string>
using namespace std;
int main() {
int len,flag=1,count=0,num,ind;
[code]....
View 8 Replies
View Related
Apr 15, 2014
I'm taking a C++ computer science course right now, and one of the questions on my latest assignment is this:
"A partition of an integer n is a way of writing n as a sum of positive integers. For example, for n=7, a partition is 1+1+5. Write a program that finds all the partitions of an integer n using r integers. For example, all the partitions of n=7 using r=3 integers are 1+1+5, 1+2+4, 1+3+3, 2+2+3."
I've been struggling with this problem for a couple days now, and how to do it. I understand I need a recursive function to grab variables, and probably an array or vector to store them, but where to begin.
I've been reading documents on partition generating and the concept still eludes me, and any other questions on here or other programming sites using partitions don't seem to have a constraint on them.
View 2 Replies
View Related
Mar 23, 2013
I have to write a program that will ask you to put in a number between 0 and 9 and multiply it by pi. If the number put in is between 0 and 9 then pi is multiplied but if it isnt between 0 or 9, it will say the number is not between 0 and 9 and asks you to put it in again and will repeat until a number between 0 and 9 is put in.
I have got the program working to the extent that it the number is between 0 and 9 it will multiply it by pi but if its not between 0 and 9 it will say the number is not between 0 and 9 and ask to put in a new number.
I can't work out how to get the program to repeat itself if the number entered isnt between 0 and 9.
I have enclosed the code below .....
View 5 Replies
View Related
Nov 21, 2013
I am working with C++ in Visual Studio. It's my first semester doing anything like this ever. Still, I am embarrassed that I am having trouble with this simple "coin flipping" program. The user tells the program how many times to "flip the coin" & then the program tells the user the results of each flip. You'll see I am randomly generating a 1 or a 2 within the function coinFlip to represent heads or tails. However, the problem is that if the user wants more than one coin flip, the "random" number stays the same for all of them, resulting in all heads or all tails. I am thinking this is an issue with the for loop that I have within the function coinFlip.
Code:
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <ctime>
using namespace std;
[Code] .....
View 3 Replies
View Related
Jul 5, 2013
Here's the part of the codes where I tried to use boolean expression:
Code:
#include <iostream>
using namespace std;
int main() {
int num;
cout << "8-bit Binary Number=";
cin >> num;
[Code] .....
How can I get started with the body?
View 7 Replies
View Related
Nov 24, 2013
How to reserved int number and print as float number ?
View 1 Replies
View Related
Mar 9, 2013
The following fuction from a class is supposed to count the number less then the average of all number combined. but it does not do that, now the fun part if you change it to count the number greater then the average it works great.
void IntegerArray::countBelowAverage() {
avrg=calcAverage(avg);
int count=0;
for(int x=0; x<100; x++) {
if (list[x]<avrg)
[Code]...
How do i get this to post in the proper format?
View 1 Replies
View Related
Apr 20, 2015
I want to find number of comparison and number of exchanges from a list or other than a list. My list is this
12 5 11 19 4 7 8 10 9 6 22 2 9 1 32
First, I am looking for number of comparisons from a list of 10 numbers with 21inversions made by selection sort, insertion sort, exchange sort.
Also, I like to find number of exchanges from a list of 10 numbers with 21inversions made by selection sort, insertion sort, exchange sort.
View 6 Replies
View Related
Jul 5, 2013
Here's the part of the codes where I tried to use boolean expression:
#include <iostream>
using namespace std;
int main()
[Code].....
May I know that how can I get started with the body?
View 5 Replies
View Related
Aug 20, 2014
In the c pgm to find number of digits , if I am giving 001 as the input number ,why I am not getting the no. of digits as 3?
View 2 Replies
View Related