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

Explain what is the concatenation operator?

617


Subtract Two Number Without Using Subtraction Operator

348


How do you redirect a standard stream?

618


What is NULL pointer?

671


Explain what is the difference between functions abs() and fabs()?

611






What are keywords c?

594


What is structure in c language?

610


swap 2 numbers without using third variable?

656


Some coders debug their programs by placing comment symbols on some codes instead of deleting it. How does this aid in debugging?

649


Linked list is a Linear or non linear explain if linear how it working as a non linear data structures

1756


In this assignment you are asked to write a multithreaded program to find the duplicates in an array of 10 million integers. The integers are between -5000,000 to 5000,000 and are generated randomly. Use 10 threads, each thread works on 1000,000 integers. Compare the time needed to accomplish the task with single thread of execution program. Do not include the time to fill the array with integers in the execution time.

2673


Explain how do you print only part of a string?

642


What is the difference between functions abs() and fabs()?

641


In cryptography, you could often break the algorithm if you know what was the original (plain) text that was encoded into the current ciphertext. This is called the plain text attack. In this simple problem, we illustrate the plain text attack on a simple substitution cipher encryption, where you know each letter has been substituted with a different letter from the alphabet but you don’t know what that letter is. You are given the cipherText as the input string to the function getwordSets(). You know that a plain text "AMMUNITION" occurs somewhere in this cipher text. Now, you have to find out which sets of characters corresponds to the encrypted form of the "AMMUNITION". You can assume that the encryption follows simple substitution only. [Hint: You could use the pattern in the "AMMUNITION" like MM occurring twice together to identify this]

1952


What is a null pointer in c?

587