Question

In: Computer Science

6. Write a program in C programming (compile and run), a pseudocode, and draw a flowchart...

6. Write a program in C programming (compile and run), a pseudocode, and draw a flowchart for each of the following problems: a) Obtain three numbers from the keyboard, compute their product and display the result. b) Obtain two numbers from the keyboard, and determine and display which (if either) is the smaller of the two numbers. c) Obtain a series of positive numbers from the keyboard, and determine and display their average (with 4 decimal points). Assume that the user types the sentinel value -1 to indicate “end of data entry.”

Solutions

Expert Solution

Pseudocode:

The informal language to develop an algorithm used by the programmer is known as pseudocode. This describes the text-based step by step solution to the given problem that is intended for human reading.

a)

The program source code is given below:


#include <stdio.h>

int main()
{
//variable declaration
int a, b, c, mul;
  
//get user input
printf("Enter three numbers: ");
scanf("%d", &a);
scanf("%d", &b);
scanf("%d", &c);
  
//calculate Multiplication
mul = a*b*c;
  
//display Multiplication
printf("Multiplication is = %d", mul);

return 0;
}

OUTPUT:

Enter three numbers: 5 6 8
Multiplication is = 240

The pseudocode is given below:

Step 1: Declare variable mul, a, b, and c

Step 2: Input three numbers

Step 3: mul = a * b * c

Step 4: Display mul on the computer screen

The flowchart is given below:

b)

The program source code is given below:


#include <stdio.h>

int main()
{
//variable declaration
int a, b;
  
//get user input
printf("Enter two numbers: ");
scanf("%d", &a);
scanf("%d", &b);
  
if(a<b)
printf("%d is smaller than %d", a, b);
else
printf("%d is smaller than %d", b, a);

return 0;
}

OUTPUT:

Enter two numbers: 10 20
10 is smaller than 20

The pseudocode is given below:

Step 1: Declare variable a, b

Step 2: Input two numbers

Step 3: if a<b

Step 3.1: Display "a is smaller than b"

Step 3.2: Else

Step 3.3: Display "b is smaller than a"

Step 4: Stop

The flowchart is given below:

c)

The program source code is given below:


#include <stdio.h>

int main()
{
//array declaration
int arr[100];
int num, size = 0;
float avg=0;
  
//while loop
while(1)
{
//get user input
scanf("%d", &num);
if(num==-1)
break;
  
arr[size++]=num;
  
avg = avg + num;
}
  
//calculate average
avg = (float) avg / size;
  
//display average
printf("Average = %.4f", avg);
  
return 0;
}

OUTPUT:

10
20
30
-1
Average = 20.0000

The pseudocode is given below:

Step 1: Start

Step 2: Declare arr[100], num, size, avg

Step 3: Initialize variable size = 0, avg = 0

Step 4: while(1)

Step 4.1: Input num from the user

Step 4.2: if num == -1

Step 4.2.1: break

Step 4.3: arr[size++] = num

Step 4.4: avg = avg + num

Step 5: avg = (float) avg / size

Step 6: Display avg on the computer screen

Step 7: Stop

The flowchart is given below:


Related Solutions

write pseudocode not c program If- else programming exercises 1.    Write a C program to find...
write pseudocode not c program If- else programming exercises 1.    Write a C program to find maximum between two numbers. 2.    Write a C program to find maximum between three numbers. 3.    Write a C program to check whether a number is negative, positive or zero. 4.    Write a C program to check whether a number is divisible by 5 and 11 or not. 5.    Write a C program to check whether a number is even or odd. 6.    Write...
DESIGN A FLOWCHART IN FLOWGORITHM AND WRITE THE PSEUDOCODE Number Analysis Program Design a program that...
DESIGN A FLOWCHART IN FLOWGORITHM AND WRITE THE PSEUDOCODE Number Analysis Program Design a program that asks the user to enter a series of 20 numbers. The program should store the numbers in an array and then display the following data: The lowest number in the array. The highest number in the array. The total of the numbers in the array. The average of the numbers in the array. PLEASE AND THANK YOU
Write a Python program that: Create the algorithm in both flowchart and pseudocode forms for the...
Write a Python program that: Create the algorithm in both flowchart and pseudocode forms for the following requirements: Reads in a series of positive integers,  one number at a time;  and Calculate the product (multiplication) of all the integers less than 25,  and Calculate the sum (addition) of all the integers greater than or equal to 25. Use 0 as a sentinel value, which stops the input loop. [ If the input is 0 that means the end of the input list. ]...
Draw a structured flowchart or write pseudocode that describes the process of guessing a number between...
Draw a structured flowchart or write pseudocode that describes the process of guessing a number between 1 and 100. After each guess, the player is told that the guess is too high or too low. The process continues until the player guesses the correct number. Pick a number and have someone try to guess it by following your instructions. Submit the flowchart or pseudocode and the results of your test. Create a python program based on your flowchart or pseudocode....
write pseudocode for the following problems not c code Pseudocode only Write a C program to...
write pseudocode for the following problems not c code Pseudocode only Write a C program to print all natural numbers from 1 to n. - using while loop Write a C program to print all natural numbers in reverse (from n to 1). - using while loop Write a C program to print all alphabets from a to z. - using while loop Write a C program to print all even numbers between 1 to 100. - using while loop...
This programming assignment will consist of a C++ program. Your program must compile correctly and produce...
This programming assignment will consist of a C++ program. Your program must compile correctly and produce the specified output. Please note that your programs should comply with the commenting and formatting described in the Required Program Development Best Practices document that has been discussed in class and is posted to the eLearning system. Please see this descriptive file on the eLearning system for more details. The name to use in the main configuration screen text box Name: [ ] in...
[15 marks] Draw the flowchart of the following programming problem: You can draw the flowchart using...
[15 marks] Draw the flowchart of the following programming problem: You can draw the flowchart using a drawing tool, or draw the flowchart on a piece of paper, take a picture, insert it here or save it in the submission folder The program reads an unspecified number of integers until a zero is entered. While the program reads each number it counts the number of positive numbers and the number of negative numbers that have been entered and sum up...
Please write variables and program plan(pseudocode) of this C++ programming code: #include <iostream> using namespace std;...
Please write variables and program plan(pseudocode) of this C++ programming code: #include <iostream> using namespace std; void leapYear(int x); int main() { int x; cout << "Enter a year: "; cin >> x; leapYear (x);   return 0; } void leapYear(int x ) {    if (x % 400 == 0)    {    cout << "This is a leap Year";}    else if    ((x % 4 == 0) && (x % 100 != 0))    {    cout <<...
in C++ Compile and run the program for the following values: r = 2 Cm, h...
in C++ Compile and run the program for the following values: r = 2 Cm, h = 10 Cm. The answer should be: The cross section area of the cylinder is 3.8955634 c The side area of the cylinder is 19.474819 inch-sqr Did you get the same answer? Explain the reason for such an error and fix the problem. Modify the previous program to include a new function called total_area, that computes the total suface area of a cylinder. The...
create flowchart using Flowgorithm and Pseudocode for the following program example:   Design a program for Jones...
create flowchart using Flowgorithm and Pseudocode for the following program example:   Design a program for Jones College. The current tuition is $12,000 per year, and tuition is expected to increase by 5 percent each year. Display the tuition amount for each year over the next five years (use a looping structure).
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT