C++ question
Using a for loop, count the number of even numbers between 1 and a number we supply (inclusive). Return 0 if the parameter is less than 1.
#include <iostream>
using namespace std;
// function declaration
int count1(int x);
int main()
{
// local variable declaration:
int N,res;
cout<<"Enter the number
:";
//enter the number upto which u want to find even number..
cin>>N;
// calling a function ...........
res=count1(N);
cout<<"Number of even numbers :"<<res;
}
// function returning the number of even numbers...
int count1(int x){
int count=0;
if(x<1){
//if number<0 return 0.....
return 0;
}
else{
for(int
i=1;i<=x;i++){
//number will be even if it is divisible by 2 .....% means modulus
will give remainder 0..
if (i%2==0){
count++;
//inrement count....
}}}
return count;
}
C++ question Using a for loop, count the number of even numbers between 1 and a...
Using Python. Find the count of all numbers between 1 and 5,000,000 (inclusive) that are divisible by either one of 13, 17, 19, and is at the same time also even.
Using C++ 1. Create a while loop that counts even numbers from 2 to 10 2. Create a for loop that counts by five (i.e. 0, 5, 10, ...) from 0 to 100 3. Ask for a person's age and give them three tries to give you a correct age (between 0 and 100) 4. Use a for loop to list Celsius and Fahrenheit temperatures. The "C" should be from -20 to 20 and the F should be shown correspondingly...
Labview question: Create a VI using a While Loop that continuously generates random numbers between 0 and 1000 until it generates a number that matches a number selected by the user. Determine how many random numbers the VI generated before the matching number. conditions to applied on above problem: 1. Convert the “random number” generator floating point numerical output to integer values to make it easier to find a match. 2. The “user selected number control” should be on the...
Using basic c++ 2. Count the positive and negative numbers using ***while loop*** • Write a program that reads unspecified number of integers , determines how many negative and positive values have been read. Also calculate total and average. Your program will end with input 0. • Output Enter an integer, the input ends if it is 0: 25 34 -89 72 -35 -67 21 48 0 The number of positives is 5 The number of negatives is 3 The...
Create a while loop that prints the EVEN numbers between 2-50. Format these numbers such that one number per line.
using C++
1. Convert the following while loop into a for loop: int count = 0; while (count < 10) x = count + sin(x); y = count + cos(y); count++;
using dr racket
Part I. Functional Paradigm 30 pts. 1. (10)Write the definition of procedure "count-even-digits" where the parameter is any positive number (0 12345 .} the result is a positive number (0 123 4 Evaluates into the number of even digits in a given integer (count-even-digits 2) result is 1; there is only one even digit in number2 (count-even-digits 4) result is 2; there is two even digit in number 4 (count-even-digits 7) result is 3; there is only...
C program. Using do-while loop for this question. Question: write a program to calculate the average of first n numbers. output: Enter the value of n : 18 The sum of first 18 numbers =171 The average of first 18 numbers = 9.00 my code couldn't give me the right avg and sum. Please help. #include<stdio.h> int main() { int num; int count =0; int sum=0; float avg; printf("Enter the value of n: "); ...
C++ and/or using Xcode... Define a class of rational numbers. A rational number is a number that can be represented as the quotient of two integers. For example, 1/2, 3/4, 64/2, and so forth are all rational numbers. (By 1/2, etc., we mean the everyday meaning of the fraction, not the integer division this expression could produce in a C++ program). Represent rational numbers as two values of type int, one for the numerator and one for the denominator. Call...
ProblemGiven a number n between 1 and 12 (inclusive), your job is to find all the pairs of numbers that produce n when summed. For instance, given the number 5, two possible pairs of numbers are1, 4 and 2, 3. Each number in the pair must be unique, meaning that 3, 3 is not a valid pair to sum to 6.You will be writing a method to accomplish this goal.sumOfPairs()Your method will take as a parameter the integer n to...