What is the output of the below program and how it is?

void main()
{
static int var=5;
printf("%d",var--);
if(var)
main();
}

Answer Posted / gaurang

Programming Techniques Assignments

1) Write down an algorithm to get the weight (in kilograms)
and height (in meters) of a person. Then calculate and
print the Body Mass Index (BMI) according to the formula:
BMI = weight / (height*height)
The BMI should be printed with 3 decimal places. You
should choose an appropriate data types and names for your
variables.

2) Write down an algorithm to read in a temperature in
Celsius and convert it to Fahrenheit. The relationship
between Celsius and Fahrenheit is
C = (F-32)*5/9.

3) Write down an algorithm that reads in a positive integer
x and tests if it is a prime number.
Note: (1) A number is prime if it is only divisible by 1
and itself.
(2) The integer 1 is defined as non-prime.

4) Write down an algorithm to find out smallest and largest
amongst 3 elements.

5) Modify the above algorithm so that it will work with N
elements where N is accepted from the user.

6) Write down an algorithm to read in an integer between 0
and 99 and output the value in English. For example, if
the input is 28, it should output “twenty-eight”.

7) Write down an algorithm to find out roots of a quadratic
equation. Please note that roots can be imaginary.

8) Write down an algorithm that reads in the number of
seconds and converts it to hours, minutes and seconds. A
sample output of your program is as follows. Don’t bother
with the singular or plural forms of the nouns.






Hint: Use the / and % operators.


9) Write down an algorithm that reads in a mark of a
student (which is an integer between 0 and 100) and prints
the corresponding grades (A-F). The mark-to-grade
conversion table is as follows:

Grade A B C D F
Range &#8805;80 65-79 50-64 40-49 <40

1. Modify the program to allow user-specified grade
boundaries. You may need to define more variables.
2. Modify the program so that it checks if the input
is between 0 and 100. If not, it should ask the user to
input again until the input is in the correct range. Use
while statements.
3. Modify the program so that it repeats the above
computation on 50 students. Use while statements.

10) Write down an algorithm which will perform following
functionality
1) Read an integer array
2) Display above array
3) Find out sum of all elements of an array
4) Find out mean of an array
5) Find out standard deviation of an array
6) Find out probability of occurrence of every element
in an array
7) Draw histogram

11) Write down an algorithm to
1) Read and display Float array
2) Reverse an array
3) Check whether array is a palindrome
4) Sort an array
5) Search an element in an array
6) Find out how many times a given element is
appearing in an array


12) Write a nalgorithm to perform following operations on
an array :-
a) Insert element at nth position in an array. Please
note it should insert and not overwrite.
b) Delete an element at a given position
c) Display an array. Take care of proper validations.


13) A “password” file contains username and password. Write
an algorithm to accept the username and password and
crosscheck it with the password file and display
appropriate message.

14) Write down an algorithm to simulate a stack.
It should allow following operations on stack :-
a) Pushing an element onto stack
b) Popping an element on stack
c) Display TOS
d) Check whether stack is full or empty. Let the stack
be a stack of Characters.

15) Write down an algorithm to simulate a Queue. It should
allow following operations on Queue.
a) Adding an element into queue at the end
b) Deleting an element on queue from front
c) Display Contents of queue 4) Check whether queue is
full or empty. Let the Queue be a Queue of Employee where
Employee is user defined data type.

16) Write down an algorithm to read a set of sentence from
user till user enters a sentence QUIT.
Find out following statistical data such as number of
characters, words and sentences.

17) In above algorithm only perform following modification.
Reverse ordering of sentences as well as reverse ordering
of character within a sentence.

18) Write an algorithm to perform an encryption as well as
decryption of a file. Use any algorithm to perform above
said activity. Simplest possible algorithm is to read every
character, add 128 to it and stores it while performing an
encryption and do reverse step while performing a
decryption.

19) Write down an algorithm to:-
a) Display contents of a file
b) Copy a file to another file
c) Compare two files

20) Write down an algorithm to merge two sorted STRING
arrays to create third sorted STRING array.

21) Write down an algorithm to accept string consisting of
anything between ‘o’ to ‘9’ and convert it into
corresponding integer. Don’t assume any inbuilt function.

22) Write an algorithm to perform any five operations on
string such as :-
a) String Length
b) Changing case
c) Reversing a string
d) Checking for palindrome etc.


23) A file contains AAAAABBCCCDD. Write an algorithm to
read such file and find out run length of every character
in above file. For example, in above case A is appearing 5
times, B 2 times and so on. So the output should look like
as follows:
A5B2C3D2
Also write down another program which will read above
output and come out with original data such as
AAAAABBCCCDD. By the way this is very preliminary algorithm
used in compression and is known as RunLength Coding.

24) Task
You are to write an algorithm for a telephone company
(Company A) to generate the phone bills for its customers.
The input to the program is a sequence of call records, one
for each customer. Each call record consists of a customer
ID, followed by the start and end time of each call made by
that customer during the last month. The program should
calculate the charge on each call and then sum up the total
for each customer.
To attract more customers, the company has promised to
offer the cheapest rate compared with 2 other rival
companies, B and C. That is, for each call, it will
calculate the charges for all 3 companies and take the
cheapest one. The rates for the 3 companies are shown in
the following table:

Company A $0.80/min
Company B $1.00/min during 9:00 – 21:00 $0.60/min
during 21:00 – 9:00
Company C $0.90/min for the first hour $0.70/min
for the rest

Your program should
1. Input the number of customers (at most 99999).
2. For each customer, input his/her call record
consisting of:
a. The customer ID (an integer between 10000 and
99999).
b. For each call made by the customer, the start time
and end time of the call. (We assume that no calls have
duration more than 23 hrs 59 mins.)
c. After the last call, there is a special time value
(-1:-1) to signify the end of the list of calls.
3. For each customer, output his/her billing
information consisting of:
a. The customer ID.
b. For each call, the start time, duration (in
minutes) and the charge (in dollars).
c. The total duration (in minutes) and total charge
(in dollars) for that customer. (We assume that the total
duration is at most 99999.)
4. There should be one blank line after the billing
information of each customer.

* You cannot use array and self-defined function for this
assignment.
Output Format
1. Time: Each time value is represented in the format
hh:mm where hh is an integer between 0 and 23, and mm is an
integer between 0 and 59.
2. Call Duration: It should be printed in a field of
width 7, right-justified.
3. Money: Each monetary value should be printed with
a ‘$’ sign followed by a decimal value in fixed-point
notation with 2 decimal places. The decimal value should
occupy a field of width 7, right-justified.



Sample Input/Output
Observe carefully the special cases as well as the
spacing/format of the input/output.

Is This Answer Correct ?    12 Yes 8 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is maximum size of array in c?

580


What is #define used for in c?

609


Explain that why C is procedural?

652


You are to write your own versions of strcpy() and strlen (). Call them mystrcpy() and mystrlen(). Write them first as code within main(), not as functions, then, convert them to functions. You will pass two arrays to the function in the case of mystrcpy(), the source and target array.

1774


How can you restore a redirected standard stream?

606






What is character set?

681


Explain pointer. What are function pointers in C?

622


FORMATTED INPUT/OUTPUT functions are a) scanf() and printf() b) gets() and puts() c) getchar() and putchar() d) all the above

615


what is the difference between 123 and 0123 in c?

716


What Is The Difference Between Null And Void Pointer?

636


What does sizeof int return?

588


int i=3; this declaration tells the C compiler to a) reserve space in memory to hold the integer value b) associate the name i with this memory location c) store the value 3 at this location d) all the above

740


Why doesnt that code work?

597


what do the 'c' and 'v' in argc and argv stand for?

640


What are the types of variables in c?

578