Computer Science, asked by princebharath1p3ym6w, 6 months ago

Write a C function without using if-else construct that does the following. It accepts a
sequence of positive integers between 1 and 9 both inclusive from the keyboard. The
program will stop accepting input once an integer outside the range is entered. The
program will finish by printing the total number multiples of 3 and total number of
even integers entered.
Test data and expected output: Enter integers between 1 & 9 both inclusive, outside
range to stop
Enter integer :0
Total no of even integer entered is 0
Total no of multiples of 3 entered is 0
Enter integers between 1 & 9 both inclusive, outside range to stop
Enter integer :2
Enter integer :4
Enter integer :6
Enter integer :9
Enter integer :3
Enter integer :1
Enter integer :2
Enter integer :0
Total no of even integer entered is 4
Total no of multiples of 3 entered is 3

Answers

Answered by Hokage006
2

Answer:Write a C program without using if-else construct that does the following.

It accepts a sequence of positive integers between 1 and 9 both inclusive from the keyboard. The program will stop accepting input once an integer outside the range is entered.

The program will finish by printing the total number multiples of 3 and total number of

even integers entered.

Test data and expected output:

Enter integers between 1 & 9 both inclusive, outside range to stop

Enter integer :0

Total no of even integer entered is 0

Total no of multiples of 3 entered is 0

Enter integers between 1 & 9 both inclusive, outside range to stop

Enter integer :2

Enter integer :4

Enter integer :6

Enter integer :9

Enter integer :3

Enter integer :1

Enter integer :2

Enter integer :0

Total no of even integer entered is 4

Total no of multiples of 3 entered is 3

2. The equation f(x) ≡ (1 − x) cos x − sin x = 0 has at least one root between a = 0 and

b = 1 since f(a)f(b) < 0. The bisection method of finding the root proceeds as follows:

a. It finds the midpoint r = (a + b)/2.

b. If f(r) = 0, then r is the root. If |b − a| is very small less than , then also we can

take r as the root. In either of the cases, our job is done.

c. If f(r) 6= 0 and f(a)f(r) < 0, then the root lies between a and r.

We assign r to b

and go to step a.

d. If f(r) 6= 0 and f(b)f(r) < 0, then the root lies between r and b. We assign r to a

and go to step a.

e. If the number of iterations is high, we may stop the process with appropriate message.

Write the following functions with the specifications mentioned.

1. Function func takes a real number x as argument and returns the value of f(x).

2. Function cbracket takes two real numbers a and b as arguments and returns 1 if at

least one real root of f(x) lies between a and b, and 0 otherwise.

3. Function rootb that takes three real numbers a, b, eps and an integer Nmax as arguments. This function returns the root of f(x) = 0 using bisection method. If the number

of iteration is more than Nmax then the function terminates with appropriate message.

Write a C program using the above functions. This program accepts a, b, eps and Nmax

from the keyboard and prints out the root (if any).

Test data and expected output:

Answered by jakkalohith
4

Answer:

#include<stdio.h>

main()

{

int n,even_num=0,three_mul=0;

printf("Enter an integer");

scanf("%d",&n);

while(n>0&&n<10)

{

n%2==0?even_num++:printf("");

n%3==0?three_mul++:printf("");

printf("Enter an integer");

scanf("%d",&n);

}

even_num==1?printf("There is an only one even number\n"):printf("There are %d even numbers\n",even_num);

three_mul==1?printf("There is an only one Three multiple number"):printf("There are %d Three multiples",three_mul);

Similar questions