Question

In: Computer Science

Write code in C please. #1 Write a function multiples() which will take an integer input...

Write code in C please.

#1 Write a function multiples() which will take an integer input and it will print out all the multiples of this number starting from 2 but not including itself. For example, multiples(10) will print 2, 5 and multiples(100) will print 2, 4, 5, 10, 20, 25, 50

#2 Write and test a Fibonacci() function that uses a loop instead of recursion to calculate Fibonacci numbers.

Solutions

Expert Solution

Source Code:

Output:

Code in text format (See above images of code for indentation):

/*include library files*/
#include <stdio.h>

/*main function*/
int main(void)
{
   /*function prototypes*/
   void multiples();
   void Fibonacci();
   /*variables*/
   int n,num;
   /*read a number from user*/
   printf("Enter a number to print multiples: ");
   scanf("%d",&n);
   /*function call*/
   printf("The multiples of %d are\n",n);
   multiples(n);
   /*read a number from user*/
   printf("\nEnter number of terms for fibonacci: ");
   scanf("%d",&num);
   /*function call*/
   Fibonacci(num);
   return 0;
}
/*function definition*/
void multiples(int n)
{
   int i;
   /*using loop print multiples*/
   for(i=2;i<n/2;i++)
   {
       /*check and print*/
       if(n%i==0)
           printf("%d, ",i);
   }
   printf("%d",i);
}
/*function definition*/
void Fibonacci(int num)
{
   int i,f=0,s=1,n;
   /*using for loop print fibonacci series*/
   for(i=0;i<num;i++)
   {
       if(i<=1)
           n=i;
       else
       {
           /*swap for next iteration*/
           n=f+s;
           f=s;
           s=n;
       }
       /*print number*/
       printf("%d ",n);
   }
}



Related Solutions

Please write the code in c++ Write a function with one input parameter that is a...
Please write the code in c++ Write a function with one input parameter that is a vector of strings. The function should count and return the number of strings in the vector that have either an 'x' or a 'z' character in them. For example, when the function is called, if the vector argument contains the 6 string values, "enter", "exit", "zebra", "tiger", "pizza", "zootaxy" the function should return a count of 4. ("exit", "zebra", "pizza", and "zootaxy" all have...
Write a C function called weighted_digit_sum that takes a single integer as input, and returns a...
Write a C function called weighted_digit_sum that takes a single integer as input, and returns a weighted sum of that numbers digits. The last digit of the number (the ones digit) has a weight of 1, so should be added to the sum "as is". The second from last digit (the tens digit) has a weight of 2, and so should be multiplied by 2 then added to the sum. The third from last digit should be multiplied by 1...
C ++ program that uses a function “IsDivisibleBy5” that returns a 1 if the input integer...
C ++ program that uses a function “IsDivisibleBy5” that returns a 1 if the input integer is evenly divisible by 5. Return 0 otherwise. Also include a function “IsOdd()” that returns a 1 if the input integer is odd. Return 0 otherwise.
Please code C# 8. Write a program that prompts the user to enter an integer. The...
Please code C# 8. Write a program that prompts the user to enter an integer. The program then determines and displays the following: Whether the integer is divisible by 5 and 6 Whether the integer is divisible by 5 or 6
IN C++ PLEASE Requirements Write a program that takes in user input of two integer numbers...
IN C++ PLEASE Requirements Write a program that takes in user input of two integer numbers for height and width and uses a nested for loop to make a rectangle out of asterixes. The creation of the rectangle (i.e. the nested for loop) should occur in a void function that takes in 2 parameters, one for height and one for width. Make sure your couts match the sample output (copy and paste from those couts so you don't make a...
Write a C++ program that prompts the user (or “Player 1”) to input an integer value...
Write a C++ program that prompts the user (or “Player 1”) to input an integer value between 1 and 3 (where 1=paper, 2=scissor, and 3=rock). This input should be passed into a string function called player_RPS(), and returns a string value indicating the selection of paper, scissors, or rock (as mentioned above). Next, the returned string value, along with a generated input from the computer, should be passed into a void function called RPS_comparison(), and determines whether the user’s input...
in C please! Write a code that asks user for input N and calculates the sum...
in C please! Write a code that asks user for input N and calculates the sum of the first N odd integers. There should be a "pure" method that calculates the sum separately that Main method should call when printing the output.
Write a C function boolean isPrime (int n), that would take a positive integer n as...
Write a C function boolean isPrime (int n), that would take a positive integer n as a parameter and return true or false whether the number is a prime number. You should check the range of n and print proper message (For example, if n is a genitive number, you should print out an error message).
C++ Only Create a function named PrintStudents, which takes a string input filename and an integer...
C++ Only Create a function named PrintStudents, which takes a string input filename and an integer minimum score value and a string output file name as a parameters. The function will read the student scores and names from the file and output the names of the students with scores greater than or equal to the value given. This function returns the integer number of entries read from the file. If the input file cannot be opened, return -1 and do...
Write a python code to Design and implement a function with no input parameter which reads...
Write a python code to Design and implement a function with no input parameter which reads a number from input (like 123). Only non-decimal numbers are valid (floating points are not valid). The number entered by the user should not be divisible by 10 and if the user enters a number that is divisible by 10 (like 560), it is considered invalid and the application should keep asking until the user enters a valid input. Once the user enters a...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT