Computer Science, asked by ammarmirza635, 5 months ago

given number in
& Write pseudo code to count occurrence of a given number in
the list for example, consider the following list, if user enters 5 then-
536 8 15
display
"2 times"
because "5" occurs 2 times in the list.

Answers

Answered by lalitnit
1

Answer:

How to write a Pseudo-code?

Arrange the sequence of tasks and write the pseudocode accordingly.

Start with the statement of a pseudo code which establishes the main goal or the aim.

Example:

This program will allow the user to check

the number whether it's even or odd.

The way the if-else, for, while loops are indented in a program, indent the statements likewise, as it helps to comprehend the decision control and execution mechanism. They also improve the readability to a great extent.

Example:

if "1"

print response

"I am case 1"

if "2"

print response

"I am case 2"

Use appropriate naming conventions. The human tendency follows the approach to follow what we see. If a programmer goes through a pseudo code, his approach will be the same as per it, so the naming must be simple and distinct.

Use appropriate sentence casings, such as CamelCase for methods, upper case for constants and lower case for variables.

Elaborate everything which is going to happen in the actual code. Don’t make the pseudo code abstract.

Use standard programming structures such as ‘if-then’, ‘for’, ‘while’, ‘cases’ the way we use it in programming.

Check whether all the sections of a pseudo code is complete, finite and clear to understand and comprehend.

Don’t write the pseudo code in a complete programmatic manner. It is necessary to be simple to understand even for a layman or client, hence don’t incorporate too many technical terms.

Dos and Don'ts in Pseudo Code Writing

Example:

Let’s have a look at this code

// This program calculates the Lowest Common multiple

// for excessively long input values

import java.util.*;

public class LowestCommonMultiple {

private static long

lcmNaive(long numberOne, long numberTwo)

{

long lowestCommonMultiple;

lowestCommonMultiple

= (numberOne * numberTwo)

/ greatestCommonDivisor(numberOne,

numberTwo);

return lowestCommonMultiple;

}

private static long

greatestCommonDivisor(long numberOne, long numberTwo)

{

if (numberTwo == 0)

return numberOne;

return greatestCommonDivisor(numberTwo,

numberOne % numberTwo);

}

public static void main(String args[])

{

Scanner scanner = new Scanner(System.in);

System.out.println("Enter the inputs");

long numberOne = scanner.nextInt();

long numberTwo = scanner.nextInt();

System.out.println(lcmNaive(numberOne, numberTwo));

}

}

Answered by dreamrob
0

Pseudo code

begin

  numeric nList, searchNo, count=0

  display “Enter number of elements in the list”

  accept nList

  create array Arr[nList]

  display “Enter list elements”

  for(int i=0;i<nList;i++)

  begin

     accept elements in the list

  end

  display “Enter number whose occurrence is to be counted”

  accept searchNo

  for(int i=0;i<nList;i++)

  begin

     if(Arr[i]==searchNo)

     begin

        count++

     end

  end

  display count

end

Program in cpp

#include<iostream>

using namespace std;

int main()

{

int nList,searchNo,count=0;

cout<<"Enter number of elements in the list : ";

cin>>nList;

int Arr[nList];

cout<<"Enter list elements:"<<endl;

for(int i=0;i<nList;i++)

{

 cin>>Arr[i];

}

cout<<"Enter number whose occurrence is to be counted : ";

cin>>searchNo;

for(int i=0;i<nList;i++)

{

 if(Arr[i]==searchNo)

 {

  count++;

 }

}

cout<<count<<" times";

}

Similar questions