Question

In: Computer Science

VB console .net framework I am missing something in my code below which will calculate factorials...

VB console .net framework

I am missing something in my code below which will calculate factorials individually into the file to be read by a sub using theis outdated language please Not Sreamwriter or Reader

fact*0, 2fact*0

Fact*1 , 2fact*1

Fact*2, 2fact*2

Fact*3, 2fact*3 (To 9)

Only the first 9 (0-8) but what I have doe calculates only the 9 factorial giving a single value

Public Function Calculate_fact(n_values As Integer) As Long
'calc local variables
Dim fact As Long = 1
Dim fact2n As Long
Dim i As Integer 'loop index
Dim fid1 As Integer = FreeFile()
FileOpen(fid1, "Newfile.dat", OpenMode.Output, OpenAccess.Write) ' open output file
'Calculaions
If n_values = 0 Then
Return fact
Else For i = 1 To n_values

Return fact = fact * i
Return fact2n = (2 * fact) * i
Next i
End If
  
MsgBox(fact, fact2n)
WriteLine(fid1, n_values, fact, fact2n)
FileClose(fid1)

End Function

Solutions

Expert Solution

#include <stdio.h>

int main()

{

    int I , num , fact = 1; //defining factorial as 1 since least value is 1

   printf (“Enter a number to calculate its factorial”);

   scanf (“%d”, &num);

   if (num<0) //if the input is a negative integer

   {

   printf (“Factorial is not defined for negative numbers.”);

   }

   else

   {

   for(i=1;i<= num;i++) //for loop doesn’t gets executed for input 0 as 1>0, therefore fact value remains 1

{

fact = fact * i; // keeps on multiplying and storing in the value of factorial till the input integer is reached

              }

   printf(“Factorial of %d = %dn”, num, fact);

    }

    return 0; //since we have defined the main() method with a return value of integer type

}


Related Solutions

In Python I have a code: here's my problem, and below it is my code. Below...
In Python I have a code: here's my problem, and below it is my code. Below that is the error I received. Please assist. Complete the swapCaps() function to change all lowercase letters in string to uppercase letters and all uppercase letters to lowercase letters. Anything else remains the same. Examples: swapCaps( 'Hope you are all enjoying October' ) returns 'hOPE YOU ARE ALL ENJOYING oCTOBER' swapCaps( 'i hope my caps lock does not get stuck on' ) returns 'I...
Python I am creating a class in python. Here is my code below: import csv import...
Python I am creating a class in python. Here is my code below: import csv import json population = list() with open('PopChange.csv', 'r') as p: reader = csv.reader(p) next(reader) for line in reader: population.append(obj.POP(line)) population.append(obj.POP(line)) class POP: """ Extract the data """ def __init__(self, line): self.data = line # get elements self.id = self.data[0].strip() self.geography = self.data[1].strip() self.targetGeoId = self.data[2].strip() self.targetGeoId2 = self.data[3].strip() self.popApr1 = self.data[4].strip() self.popJul1 = self.data[5].strip() self.changePop = self.data[6].strip() The problem is, I get an error saying:  ...
Here is my fibonacci code using pthreads. When I run the code, I am asked for...
Here is my fibonacci code using pthreads. When I run the code, I am asked for a number; however, when I enter in a number, I get my error message of "invalid character." ALSO, if I enter "55" as a number, my code automatically terminates to 0. I copied my code below. PLEASE HELP WITH THE ERROR!!! #include #include #include #include #include int shared_data[10000]; void *fibonacci_thread(void* params); void parent(int* numbers); int main() {    int numbers = 0; //user input....
This is my code for python. I am trying to do the fourth command in the...
This is my code for python. I am trying to do the fourth command in the menu which is to add an employee to directory with a new phone number. but I keep getting error saying , "TypeError: unsupported operand type(s) for +: 'dict' and 'dict". Below is my code. What am I doing wrong? from Lab_6.Employee import * def file_to_directory(File): myDirectory={}       with open(File,'r') as f: data=f.read().split('\n')    x=(len(data)) myDirectory = {} for line in range(0,199):      ...
I'm getting an error with my code on my EvenDemo class. I am supposed to have...
I'm getting an error with my code on my EvenDemo class. I am supposed to have two classes, Event and Event Demo. Below is my code.  What is a better way for me to write this? //******************************************************** // Event Class code //******************************************************** package java1; import java.util.Scanner; public class Event {    public final static double lowerPricePerGuest = 32.00;    public final static double higherPricePerGuest = 35.00;    public final static int cutOffValue = 50;    public boolean largeEvent;    private String...
I am taking history of psychology the bellow is my question Identify something new that you...
I am taking history of psychology the bellow is my question Identify something new that you learned about Darwin in this unit. For example, beyond his famous theory of evolution, did you know his thoughts on geography or slavery, or were you aware of his five-year voyage? Additionally, use this forum to brainstorm with your professor and classmates on contributions of early theorists, such as how Weber’s two-point threshold speaks to modern neurology.
Working with Python. I am trying to make my code go through each subject in my...
Working with Python. I am trying to make my code go through each subject in my sample size and request something about it. For example, I have my code request from the user to input a sample size N. If I said sample size was 5 for example, I want the code to ask the user the following: "Enter age of subject 1" "Enter age of subject 2" "Enter age of subject 3" "Enter age of subject 4" "Enter age...
I have the following code for my java class assignment but i am having an issue...
I have the following code for my java class assignment but i am having an issue with this error i keep getting. On the following lines: return new Circle(color, radius); return new Rectangle(color, length, width); I am getting the following error for each line: "non-static variable this cannot be referenced from a static context" Here is the code I have: /* * ShapeDemo - simple inheritance hierarchy and dynamic binding. * * The Shape class must be compiled before the...
Below is my source code for file merging. when i run the code my merged file...
Below is my source code for file merging. when i run the code my merged file is blank and it never shows merging complete prompt. i dont see any errors or why my code would be causing this. i saved both files with male names and female names in the same location my source code is in as a rtf #include #include #include using namespace std; int main() { ifstream inFile1; ifstream inFile2; ofstream outFile1; int mClientNumber, fClientNumber; string mClientName;...
I am trying to make a new code that uses functions to make it. My functions...
I am trying to make a new code that uses functions to make it. My functions are below the code. <?php */ $input; $TenBills = 1000; $FiveBills = 500; $OneBills = 100; $Quarters = 25; $Dimes = 10; $Nickels = 5; $Pennies = 1; $YourChange = 0; $input = readline("Hello, please enter your amount of cents:\n"); if(ctype_digit($input)) { $dollars =(int)($input/100); $cents = $input%100;    $input >= $TenBills; $YourChange = (int)($input/$TenBills); $input -= $TenBills * $YourChange; print "Change for $dollars dollars...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT