Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1.Getting string input 2.Designing and implementing a counted loop 3.Designing a

ID: 639368 • Letter: 1

Question

1.Getting string input

2.Designing and implementing a counted loop

3.Designing and implementing a post-test loop

4.Keeping track of a previous value

5.Implementing data validation.

   1.Write a program to calculate Fibonacci

       1.Display the program title and programmer's name. Then get the                  user's name, and greet the user.

       2.Prompt the user to enter the number of Fibonacci terms to be displayed. Advise the user to enter an integer in the range [1 .. 46]

       3.Get and validate the user input (Calculate and display all of the Fibonacci numbers up to and including the nth term. The results should be displayed 5 terms per line with at least 5 spaces between terms.

       4.Display a parting message that includes the user's name, and terminate the program.

Requirements

  1.The programmer's name and the user's name must appear in the output.

  2.The loop that implements data validation must be implemented as a post-test loop.

  3.The loop that calculates the Fibonacci terms must be implemented using the counted loop instruction.

  4.The main procedure must be modularized into at least the following sections (procedures are not required this time):

     1.introduction

     2.user_instructions

     3.get_user_data

     4.display_fibs

     5.farewell

  5.Recursive solutions are not acceptable for this assignment. This one is about iteration.

  6.The upper limit should be defined and used as a constant.

  7.The usual requirements regarding documentation, readability, user-friendliness, etc., apply.

2.Write and test a nasm program to perform the following tasks:

1.Display the program title and programmer's name.

2.Get the user's name, and greet the user.

3.Display instructions for the user.

4.Repeatedly prompt the user to enter a number. Validate the user input to be less than or equal to 100. Count and accumulate the valid user numbers until a negative number is entered. (The negative number is discarded.)

5.Calculate the (rounded integer) average of the non-negative numbers.

6.Display:

the number of non-negative numbers entered (Note: if no non-negative numbers were entered, display a special message and skip to iv.)

the sum of non-negative numbers entered

the average rounded to the nearest integer

a parting message (with the user's name)

Write a simple nasm program which displays the integers from 9 through 5 in the form 98765 using a counted loop.

Notes for the above

It is not necessary to store the Fibonacci numbers in an array. The terms may be displayed as they are generated.

The second-order Fibonacci sequence is defined as:

The first two terms are both 1.

All other terms are calculated as the sum of the two previous terms.

The reason for restricting n to [1 .. 46] is that the 47th Fibonacci number is too big for DWORD data type.

Find the assembly language instruction syntax in the textbook.

Extra credit:

Keep in mind, any of these are IN ADDITION to the completed problem definition listed above. No extra credit will be given if the basic version above does not work.

Modularize your program using procedures/functions

Create all of the above as a single program with a menu to select which problem (must use functions).

Display the numbers in aligned columns.

Do something incredible.

Explanation / Answer

#include<stdio.h>
#include<conio.h>
main()
{
int n,i,c,a=0,b=1;
printf("Enter Fibonacci series of nth term : ");
scanf("%d",&n);
printf("%d %d ",a,b);
for(i=0;i<=(n-3);i++)
{
c=a+b;
a=b;
b=c;
printf("%d ",c);
}
getch();
}

Fibonacci series each number is the sum of the two previous numbers.

#include < p18f452.h >

//these memory locations hold the Fibonacci series
unsigned char fib0; //lowest number
//(oldest when going up, newest when reversing down)
unsigned int fib1; //middle number
unsigned float fib2; //highest number
unsigned double fibtemp; //temporary location for newest number

main ()
{
counter 3; //have preloaded the first three numbers, so start at 3
fib0 0;
fib1 1;
fib2 1;
loop: do
{
float test0;
fibtemp fib1 + fib2;
counter counter + 1;
//now shuffle numbers held, discarding the oldest
fib0 fib1; //first move middle number, to overwrite oldest
fib1 fib2;
fib2 fibtemp;
}
while (counter<12):
//when reversing down, we will subtract fib0 from fib1 to form new fib0
do
{
fibtemp fib1 - fib0; //latest number now placed in fibtemp
counter counter - 1;
//now shuffle numbers held, discarding the oldest
fib2 fib1; //first move middle number, to overwrite oldest
fib1 fib0;
fib0 = fibtemp;
}
while (fib0>0);
go to loop
return 10;
}