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...
-Draw a flowchart and pseudocode for a program that produces a monthly bill for a cell...
-Draw a flowchart and pseudocode for a program that produces a monthly bill for a cell phone customer. -List at least 10 separate modules that might be included. - For example, one module might calculate the charge for daytime phone minutes used. - -Make a working version of this program using Python. Need all of the above answered including the correct code for program using python
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...
C Program and pseudocode for this problem. Write a C program that plays the game of...
C Program and pseudocode for this problem. Write a C program that plays the game of "Guess the number" as the following: Your program choose the number to be guessed by selecting an integer at random in the rang of 1 to 1000. The program then asks the use to guess the number. If the player's guess is incorrect, your program should loop until the player finally gets the number right. Your program keeps telling the player "Too High" or...
[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 <<...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT