Question

In: Computer Science

Write a code in two ways to generate all multiple of n: from 0 to 158...

Write a code in two ways to generate all multiple of n: from 0 to 158 included.
1) in procedural style,
2) in Object Oriented style

Input: just a value of n between 11 and 19 included.

Solutions

Expert Solution

1) procedural style :

code :

#include <stdio.h>

int main()
{
int n;
printf("Enter the value of n between 11 and 19 included : ");
scanf("%d", &n); // read the value of n
printf("Result : ");
for(int i = 1; i < 158; i++)
{
if(i % n == 0) // for multiples
{
printf("%d ", i);
}
}

return 0;
}

output :

2) object oriented style :

code :

import java.util.*;

public class Main
{
public static void print(int n)
{
System.out.println("Result : ");
for(int i = 1; i < 158; i++)
{
if(i % n == 0) // for multiples
{
System.out.print(i + " ");
}
}
}
  
   public static void main(String[] args) {
   Scanner s = new Scanner(System.in);
       int n;
System.out.print("Enter the value of n between 11 and 19 included : ");
n = s.nextInt(); // read the value of n
print(n); // call the fucntion
   }
}

output:


Related Solutions

Write a code in two ways to generate all multiple of n: from 0 to 158...
Write a code in two ways to generate all multiple of n: from 0 to 158 included. (this is all the teacher gave me) 1) in procedural style, 2) in Object Oriented style Input: just a value of n between 11 and 19 included. Output : the generated list required. Choose any languages you know. Keep working hard ----------------- To do: 1- Read about Styles of PLs : Procedural Programming Language. ... Object-oriented Programming Language. ... Functional Programming Language. ......
Write Java code to generate 100 random integers ranging from 0..9, inserting each element into an...
Write Java code to generate 100 random integers ranging from 0..9, inserting each element into an ArrayList. Then search for the first instance of the number 3, print the position, and then remove it from the list.
Write the R code First, generate 1000 observations from a binomial distribution with n=30 and p=0.2...
Write the R code First, generate 1000 observations from a binomial distribution with n=30 and p=0.2 Use the 1000 observations you generated: a) Generate poisson, binomial, negative binomial Diagnostic Distribution Plots using distplot. b) Generate a histogram and overlay a kernel estimator of the density (You can use: binom <- rbinom(n=1000,size=30, prob=0.2))
R Simulation:Write an R code that does the following: (a) Generate n samples x from a...
R Simulation:Write an R code that does the following: (a) Generate n samples x from a random variable X that has a uniform density on [0,3]. (b) Now generate samples of Y using the equation: y = α x + β (c) For starters, set α = 1, β = 1.
Given n. Write a program in PYTHON to Generate all numbers with number of digits equal...
Given n. Write a program in PYTHON to Generate all numbers with number of digits equal to n, such that the digit to the right is greater than the left digit (ai+1 > ai). E.g. if n=3 (123,124,125,……129,234,…..789)
Write the code in assembly language to generate two square waves of frequency 1KHZ with 50%...
Write the code in assembly language to generate two square waves of frequency 1KHZ with 50% duty cycle and 10KHZ with 50% duty cycle using P1.0 and P1.1 using timer0 and timer1 simultaneously. Don't use instruction overhead. use timer interrupts to implement the functionality use Xtal=12MHZ
Write the R code to generate five independent uniform random numbers and use that to generate...
Write the R code to generate five independent uniform random numbers and use that to generate 5 independent Bernoulli random variables with probability of success p = 0.4. please use RStudio. please do not use lab nor rbern for calculations.
(C++) Write a nested loop that reads an integer n (n>0) from the keyboard and print...
(C++) Write a nested loop that reads an integer n (n>0) from the keyboard and print out "n" lines as follows: 0 0 1 0 1 2 0 1 2 3 … 0 1 2 3 … n-1
For this problem, you will write a program using two queues. Generate n random numbers between...
For this problem, you will write a program using two queues. Generate n random numbers between 10 and 100 (both inclusive), where n>9. The value of n should be taken as input from the user and n should be >9. The numbers could be duplicated. Enqueue all these numbers to the first queue. The objective is to find the numbers whose sum of digits is odd and enqueue them to the second queue. The remaining numbers (whose sum of digits...
Write a code on Jupytor notebook: On a roulette wheel, the pockets are numbered from 0...
Write a code on Jupytor notebook: On a roulette wheel, the pockets are numbered from 0 to 36. The colors of the pockets are as follows: Pocket 0 is green. For pockets 1 through 10, the odd-numbered pockets are red and the even-numbered pockets are black. For pockets 11 through 18, the odd-numbered pockets are black and the even-numbered pockets are red. For pockets 19 through 28, the odd-numbered pockets are red and the even-numbered pockets are black. For pockets...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT