All 18 Mechanical Engineering Optional questions from 1995 to 2007 on topics that are no longer in the syllabus – computer programming (FORTRAN and C), computer basics, lubrication and journal bearings, and a control-systems problem – solved step by step, latest first.
Try them yourself first: the same questions, without solutions, are on our Other Questions Outside the Present Syllabus topic-wise PYQs page. These topics are not in the present syllabus – the last question on them was set in 2007 – so expect few or no new questions on them. We solve them for students who practise from old papers, and because lubrication and journal bearings overlap with Machine Design.
How we check these solutions
These are our own solutions, prepared with AI help. UPSC does not publish official answers. Every solution is checked a second way before it goes up, and says how:
- ✓ Checked by computer the numbers were worked out again independently in code (Python with NumPy/SymPy) and matched.
- ✓ Program compiled and tested every program was compiled (gcc for C, gfortran for FORTRAN) and run on test data, and its output was matched against an independent calculation.
- ✓ Derivation checked step by step for derivations and “show that” questions, every step was checked against the governing laws.
- ✓ Answer checked step by step for descriptive questions, every point was checked against the standard theory.
Spotted a mistake or a neater method? Tell us in the comments below or through Report an error.
Jump to a question (year · question number):
2007 · 5d 2006 · 8c 2005 · 8c 2004 · 8b 2002 · 5d 2001 · 5c 2001 · 5d 2000 · 3b 2000 · 5d 1999 · 1c 1998 · 1a 1998 · 1d 1997 · 5b 1996 · 1d 1996 · 7c 1995 · 4a 1995 · 5c 1995 · 8a
(i) With a neat sketch briefly explain organization of digital computer. (ii) Write down the general structure of a logical IF statement in modern FORTRAN language. (iii) Differentiate between a function sub programme and sub-routine.
Solution
(i) Organisation of a digital computer
A digital computer has five functional units. They follow the stored-program (von Neumann) design: the program and its data both sit in the same memory.
- Input unit (keyboard, mouse, scanner, disk). It converts data and instructions into binary form and passes them to memory.
- Memory unit.
- Primary memory (RAM, with ROM for start-up) holds the running program and its data. The CPU can reach it directly.
- Secondary memory (hard disk, CD, tape) stores large amounts of data permanently.
- Arithmetic and logic unit (ALU). It does the arithmetic (+, −, ×, ÷) and the comparisons and logical operations (AND, OR, NOT, greater/less). Intermediate results sit in registers such as the accumulator.
- Control unit (CU). It fetches each instruction from memory, decodes it and sends timing and control signals to every other unit. The fetch–decode–execute cycle repeats, step by step, for each instruction. The program counter holds the address of the next instruction.
- Output unit (monitor, printer, plotter). It turns the binary results back into a form people can read.
The ALU, the CU and the registers together form the central processing unit (CPU). The units are linked by three buses:
- the data bus carries the data;
- the address bus carries the memory address;
- the control bus carries the read/write and timing signals.
(ii) Logical IF statement in FORTRAN
The logical IF runs one statement only when a logical expression is true:
IF (logical expression) statementExample: IF (X .GT. XMAX) XMAX = X. The statement must be a single executable statement. It may not be a DO, another IF, or an END.
For more than one statement, modern FORTRAN (77 and later) uses the block IF:
IF (logical expression 1) THEN
block 1
ELSE IF (logical expression 2) THEN
block 2
ELSE
block 3
END IFThe relational operators are .LT. .LE. .EQ. .NE. .GT. .GE. (Fortran 90 also allows < <= == /= > >=). The logical operators are .AND. .OR. .NOT..
(iii) Function subprogram and subroutine
| Function subprogram | Subroutine | |
|---|---|---|
| Heading | REAL FUNCTION AREA(R) |
SUBROUTINE STATS(X, N, AV, SD) |
| Result | Returns one value, through its own name | Returns any number of values (or none), through its arguments |
| How it is used | Called by using its name inside an expression: A = 2.0*AREA(R) |
Called by a separate CALL statement: CALL STATS(X, N, AV, SD) |
| Name | Has a type (REAL, INTEGER …), and is assigned a value inside the body | Has no type and carries no value |
| Arguments | Usually one or more; a function with none is still called with brackets, F() |
May have none: CALL INIT |
| Typical use | A formula: area, factorial, friction law | A task: sorting, input/output, solving a system |
Both end with RETURN and END, are compiled separately, and get their data through dummy arguments (or COMMON).
✓ Answer checked step by step We checked the computer-organisation points and the FORTRAN 77 rules for the logical IF, functions and subroutines against the language standard.
Write a “C” program to calculate the factorial of a positive integer quantity by incorporating user defined function for calculating factorial in main program.
Solution
The factorial is , with . A user-defined function factorial() works out the product in a loop. main() reads , calls the function and prints the result.
#include <stdio.h>
/* user-defined function: returns n! for n >= 0 */
unsigned long long factorial(int n)
{
unsigned long long f = 1;
int i;
for (i = 2; i <= n; i++)
f = f * i;
return f;
}
int main(void)
{
int n;
printf("Enter a positive integer: ");
if (scanf("%d", &n) != 1 || n < 0) {
printf("Please enter a whole number 0 or more.\n");
return 1;
}
if (n > 20) { /* 21! does not fit in 64 bits */
printf("n must be 20 or less for this program.\n");
return 1;
}
printf("%d! = %llu\n", n, factorial(n));
return 0;
}How it works.
factorial()receivesnby value. It starts withf = 1and multiplies by 2, 3, …, n. For n = 0 or 1 the loop does not run, so it correctly returns 1.- The result type is
unsigned long long(64 bits). Factorials grow very fast: 20! ≈ 2.4 × 10¹⁸ is the largest that fits, so the program rejects n > 20. - A recursive version of the function also works:
return (n <= 1) ? 1 : n * factorial(n - 1);. The loop is preferred because it uses no stack.
Sample run: input 5 → 5! = 120.
✓ Program compiled and tested We compiled the program with gcc and ran it for n = 0, 5 and 20 (0! = 1, 5! = 120, 20! = 2 432 902 008 176 640 000), and for the invalid inputs n = 21 and n = −3.
Write a flow chart to solve the quadratic equation . Write also the corresponding C program.
Solution
The roots of are
The sign of the discriminant decides the kind of roots. The case must be caught first, because the formula would then divide by zero.
Flow chart
C program
#include <stdio.h>
#include <math.h>
int main(void)
{
double a, b, c, d, x1, x2, re, im;
printf("Enter a, b, c: ");
scanf("%lf %lf %lf", &a, &b, &c);
if (a == 0.0) { /* not a quadratic */
if (b == 0.0)
printf("a = b = 0: no equation to solve.\n");
else
printf("Linear equation: x = %g\n", -c / b);
return 0;
}
d = b * b - 4.0 * a * c; /* discriminant */
if (d > 0.0) { /* real and distinct */
x1 = (-b + sqrt(d)) / (2.0 * a);
x2 = (-b - sqrt(d)) / (2.0 * a);
printf("Real, distinct roots: x1 = %g, x2 = %g\n", x1, x2);
} else if (d == 0.0) { /* real and equal */
x1 = -b / (2.0 * a);
printf("Real, equal roots: x1 = x2 = %g\n", x1);
} else { /* complex conjugate */
re = -b / (2.0 * a);
im = sqrt(-d) / (2.0 * a);
printf("Complex roots: x1 = %g + %gi, x2 = %g - %gi\n", re, im, re, im);
}
return 0;
}Sample runs
| Input a, b, c | Output |
|---|---|
| 1 −3 2 | Real, distinct roots: x1 = 2, x2 = 1 |
| 1 2 1 | Real, equal roots: x1 = x2 = −1 |
| 1 2 5 | Complex roots: x1 = −1 + 2i, x2 = −1 − 2i |
| 0 2 4 | Linear equation: x = −2 |
Notes:
- The program is linked with the maths library (
gcc quad.c -lm) forsqrt(). - Testing
d == 0.0exactly is fine for whole-number data. For measured data, a small tolerance such asfabs(d) < 1e-12is safer.
✓ Program compiled and tested We compiled the program with gcc and ran it on all four cases: x² − 3x + 2 (roots 2, 1), x² + 2x + 1 (−1, −1), x² + 2x + 5 (−1 ± 2i) and 2x + 4 = 0 with a = 0 (x = −2). The flow chart follows the same branches.
Write a flow chart for choosing the largest of three distinct numbers X, Y and Z.
Solution
Since the numbers are distinct, two comparisons are always enough. First compare X with Y. Then compare the larger of the two with Z.
Trace.
- X = 3, Y = 9, Z = 4: X > Y is No, so we test Y > Z; that is Yes, so the largest is Y = 9.
- X = 9, Y = 3, Z = 4: X > Y is Yes, so we test X > Z; that is Yes, so the largest is X = 9.
Every path passes through exactly two decision boxes.
The same logic in C:
#include <stdio.h>
int main(void)
{
double x, y, z, big;
printf("Enter X, Y, Z: ");
scanf("%lf %lf %lf", &x, &y, &z);
if (x > y) {
if (x > z) big = x; else big = z;
} else {
if (y > z) big = y; else big = z;
}
printf("Largest = %g\n", big);
return 0;
}✓ Program compiled and tested We traced the flow chart for all six orderings of three distinct numbers, and ran the matching C program (for example 3, 9, 4 → 9 and −1, −5, −2 → −1).
(i) Bevery Company, a weighing machine manufacturer essentially manufactures a mechanical weighing machine and another deluxe version which is a digital weighing machine. The company gives 7% commission on sales of the ordinary mechanical type and 8% commission on sales of the deluxe digital version. However, all such commissions are available, provided there is a base level sale of at least Rs. 10,000 of ordinary variety and Rs. 15,000 of deluxe variety. To motivate the sales engineers, for a sales exceeding Rs. 20,000 and Rs. 25,000 for the ordinary and deluxe variety respectively, there is a 1% increase in the commission levels for both varieties. Draw a flow chart to enable writing a computer programme for the above. (ii) Write a computer programme for the above situation.
Solution
Reading the scheme. We read the conditions variety by variety:
| Variety | Sales below the base level | Sales from the base level up to the upper level | Sales above the upper level |
|---|---|---|---|
| Ordinary (mechanical) | below Rs 10 000: no commission | Rs 10 000 – 20 000: 7 % | above Rs 20 000: 8 % |
| Deluxe (digital) | below Rs 15 000: no commission | Rs 15 000 – 25 000: 8 % | above Rs 25 000: 9 % |
The commission is paid on the whole sale of that variety, and the higher rate applies to the whole sale once it crosses the upper level.
The question can also be read jointly: no commission at all unless both base levels are met, and the extra 1 % only when both upper levels are crossed. For that reading, change the two tests in the flow chart to ORD ≥ 10000 AND DLX ≥ 15000 and ORD > 20000 AND DLX > 25000.
(i) Flow chart
(ii) Program (C)
The same rule applies to both varieties with different numbers, so it is written once, as a function, and called twice.
#include <stdio.h>
/* commission on one variety:
sales below the base level -> no commission
sales at or above base -> basic rate
sales above the upper level -> basic rate + 1 % */
double commission(double sales, double base, double upper, double rate)
{
if (sales < base)
return 0.0;
if (sales > upper)
rate = rate + 1.0;
return sales * rate / 100.0;
}
int main(void)
{
int n, k;
double ord, dlx, c_ord, c_dlx;
printf("Number of sales engineers: ");
scanf("%d", &n);
for (k = 1; k <= n; k++) {
printf("Engineer %d - sales of ordinary and deluxe (Rs): ", k);
scanf("%lf %lf", &ord, &dlx);
c_ord = commission(ord, 10000.0, 20000.0, 7.0);
c_dlx = commission(dlx, 15000.0, 25000.0, 8.0);
printf("Engineer %d: ordinary Rs %.2f, deluxe Rs %.2f, total Rs %.2f\n",
k, c_ord, c_dlx, c_ord + c_dlx);
}
return 0;
}Test run
| Ordinary sales (Rs) | Deluxe sales (Rs) | Commission on ordinary (Rs) | Commission on deluxe (Rs) | Total (Rs) |
|---|---|---|---|---|
| 8 000 | 30 000 | 0 | 2 700 | 2 700 |
| 10 000 | 15 000 | 700 | 1 200 | 1 900 |
| 20 000 | 25 000 | 1 400 | 2 000 | 3 400 |
| 20 001 | 25 001 | 1 600.08 | 2 250.09 | 3 850.17 |
| 40 000 | 12 000 | 3 200 | 0 | 3 200 |
✓ Program compiled and tested We compiled the program with gcc and checked five sales cases by hand: below the base level, exactly at the base levels, at the upper levels, just above them, and one variety only. For example, deluxe sales of Rs 30 000 earn 9 % = Rs 2 700, and ordinary sales of Rs 8 000 earn nothing.
(i) List the primary hardware components of a personal computer. (ii) List some of the options for each of the above components. (iii) What do you understand from the following terms? (a) RAM (b) ROM (c) 5 GB (d) 860 MHz (e) 57.6 KBPS.
Solution
(i) Primary hardware components of a PC
- Processor (CPU) on the motherboard, with the chipset, the expansion slots and the BIOS ROM.
- Main memory (RAM).
- Storage devices: hard disk, floppy disk, CD-ROM/CD-writer.
- Input devices: keyboard, mouse.
- Output devices: monitor (with its display adapter) and printer.
- Communication device: modem or network card.
- Cabinet with its power supply (SMPS), plus a UPS.
(ii) Options for each
| Component | Options around 2001 | Today |
|---|---|---|
| Processor | Intel Pentium III / Pentium 4, Celeron; AMD Athlon, Duron; 500 MHz – 1.5 GHz | multi-core Intel Core / AMD Ryzen, 3–5 GHz |
| RAM | 64–512 MB SDRAM (PC-100/133), RDRAM, DDR | 8–32 GB DDR4/DDR5 |
| Hard disk | 10–40 GB IDE (ATA) or SCSI | 0.5–2 TB SSD or HDD |
| Removable storage | 1.44 MB floppy, CD-ROM, CD-RW, Zip drive | USB flash drive, DVD |
| Monitor | 14–17 inch CRT, LCD | 22–27 inch LCD/LED |
| Printer | dot-matrix, inkjet, laser | inkjet, laser |
| Input | keyboard; ball or optical mouse; scanner; joystick | keyboard, optical mouse, touchpad, webcam |
| Communication | 33.6 / 56 kbps modem, 10/100 Mbps Ethernet card | broadband router, Wi-Fi, gigabit Ethernet |
(iii) Terms
(a) RAM (random access memory).
- It is the computer’s main working memory. The CPU can read and write any location directly, in the same time whatever the address.
- It is volatile: its contents are lost when the power goes off.
- It holds the operating system, the running programs and their data.
(b) ROM (read-only memory).
- It is non-volatile memory whose contents are written once, at manufacture (PROM, EPROM and EEPROM can be reprogrammed in special ways).
- Normally it can only be read.
- In a PC it holds the BIOS start-up program.
(c) 5 GB.
- Five gigabytes, a storage capacity (typically a hard disk). 1 GB = 2³⁰ bytes ≈ 1.07 × 10⁹ bytes; disk makers use 10⁹ bytes.
- So 5 GB ≈ 5 × 10⁹ bytes. One byte is 8 bits and stores one character.
(d) 860 MHz.
- The processor’s clock speed: 860 million clock cycles per second.
- One cycle lasts 1/(860 × 10⁶) s ≈ 1.16 ns.
- A higher clock means more instructions per second for the same design.
(e) 57.6 KBPS.
- A data-transfer rate of 57.6 kilobits per second, typical of a dial-up modem or a serial port.
- It is about 57 600 bits per second, or roughly 7 200 characters (bytes) per second.
- Note the capital B in “KBPS” here means bits, not bytes. The standard symbol is kbit/s.
✓ Answer checked step by step We checked the component list and the meaning of each term against standard computer-fundamentals texts. The options listed are typical of the 2001 PCs the question had in mind; modern equivalents are noted.
Write a FORTRAN programme to accept data of heights of up to 100 students of a college. The programme should be able to calculate the main variance, and standard deviation of heights and print (i) the number of students (ii) the serial number and heights of individual students (iii) the mean, variance and standard deviation of heights.
Solution
We take the “main variance” in the question to mean the mean and the variance. For heights :
The program stores up to 100 heights in an array. It makes two passes over the data: the first finds the mean, the second the sum of squared deviations about that mean. Working about the mean is more accurate than the one-pass formula .
C HEIGHTS OF UP TO 100 STUDENTS: MEAN, VARIANCE, STANDARD DEVIATION
PROGRAM HEIGHT
INTEGER N, I
REAL H(100), SUM, SUMSQ, AMEAN, VAR, SD
WRITE (*,*) 'NUMBER OF STUDENTS (1 TO 100)?'
READ (*,*) N
IF (N .LT. 1 .OR. N .GT. 100) THEN
WRITE (*,*) 'N MUST BE BETWEEN 1 AND 100'
STOP
END IF
WRITE (*,*) 'ENTER THE HEIGHTS (CM)'
READ (*,*) (H(I), I = 1, N)
C FIRST PASS: MEAN
SUM = 0.0
DO 10 I = 1, N
SUM = SUM + H(I)
10 CONTINUE
AMEAN = SUM / N
C SECOND PASS: VARIANCE ABOUT THE MEAN
SUMSQ = 0.0
DO 20 I = 1, N
SUMSQ = SUMSQ + (H(I) - AMEAN)**2
20 CONTINUE
VAR = SUMSQ / N
SD = SQRT(VAR)
C OUTPUT
WRITE (*,100) N
WRITE (*,110)
DO 30 I = 1, N
WRITE (*,120) I, H(I)
30 CONTINUE
WRITE (*,130) AMEAN, VAR, SD
100 FORMAT (/' NUMBER OF STUDENTS = ', I4)
110 FORMAT (/' SERIAL NO. HEIGHT (CM)')
120 FORMAT (I8, F15.2)
130 FORMAT (/' MEAN = ', F8.2, ' VARIANCE = ', F9.3,
& ' STANDARD DEVIATION = ', F8.3)
STOP
ENDSample output (6 students):
NUMBER OF STUDENTS = 6
SERIAL NO. HEIGHT (CM)
1 160.00
2 172.00
3 165.00
4 158.00
5 181.00
6 170.00
MEAN = 167.67 VARIANCE = 60.222 STANDARD DEVIATION = 7.760Notes:
- If the sample (rather than the population) variance is wanted, divide by
N-1instead ofN(here: 72.27 cm², σ = 8.50 cm). - The check on N keeps the program from writing past the end of the 100-element array.
✓ Program compiled and tested We compiled the program with gfortran and ran it on six heights (160, 172, 165, 158, 181, 170 cm). It gave mean 167.67 cm, variance 60.222 cm² and standard deviation 7.760 cm, the same values Python’s statistics module gives.
A 150 mm diameter shaft supporting a load of 10 kN has a speed of 1500 rpm. The shaft runs in a bearing whose length is 1.5 times the shaft diameter. If the diametral clearance of the bearing is 0.15 mm and the absolute viscosity of the oil at the operating temperature is 11 centipoises find the power wasted in friction.
Solution
Data
- Diameter mm, so radius mm.
- Length mm.
- Load kN; speed rpm.
- Diametral clearance mm, so radial clearance mm.
- Viscosity cP Pa·s (1 cP = 10⁻³ Pa·s).
With no eccentricity given, we use Petroff’s equation: the journal is taken as concentric, and the oil film as a thin layer sheared at a uniform rate.
Surface speed
Shear stress in the film (velocity varies linearly across the gap ):
Friction force and torque
Power wasted in friction
Cross-check with Petroff’s equation.
- Bearing pressure: kPa.
- Speed: rev/s.
So N, as before.
The Sommerfeld number is . This is high: the bearing runs lightly loaded and nearly concentric, so Petroff’s assumption holds well. A Raimondi–Boyd chart would raise the loss by only a few per cent.
✓ Checked by computer We recalculated the result in Python by two routes: the shear stress on the bearing area, and Petroff’s equation written with the Sommerfeld number. Both give f = 0.01832 and a friction loss of 2158 W.
A ball at the end of a very long pendulum can be assumed to move linearly between two metallic plates at a fixed distance apart. The inner distance between the plates is slightly more than the diameter of the pendulum bob which is spherical leaving clearance on the left or on the right. If the plates move in simple harmonic motion, the amplitude being very small, the bob may touch the left or the right side plate or it may not touch any, at any instant. If the bob touches the left plate, equation A is governed while if it touches the right plate, equation B is governed. If there is no contact by the bob on any of the plates, then equation C is governed. Write a flow chart in FORTRAN for the motion of the bob.
Solution
Setting up. Let the plates oscillate together: the centre of the gap is at . Let be the bob’s position and the clearance on each side, so the gap is . The relative position decides which equation applies:
| Condition | Contact | Equation |
|---|---|---|
| and the plate is closing on the bob () | left plate | A |
| and the plate is closing on the bob () | right plate | B |
| otherwise | no contact | C |
A plate can only push. Once it starts to move away faster than the bob, contact ends and C takes over again.
The question does not print equations A, B and C, so we use the simplest physical model. A very long pendulum has a tiny restoring force and a massive plate:
- A: the bob moves with the left plate: , .
- B: the bob moves with the right plate: , .
- C: free pendulum motion, , stepped forward by .
If the examiner’s own A, B and C are different, only the three subroutines change; the flow chart and the main program stay the same.
Flow chart
FORTRAN program
C BOB OF A VERY LONG PENDULUM BETWEEN TWO PLATES IN SHM
C XP = AMP*SIN(W*T) : CENTRE OF THE GAP (PLATES MOVE TOGETHER)
C R = X - XP : BOB POSITION RELATIVE TO THE GAP CENTRE
C R <= -D AND V <= VP : BOB TOUCHES LEFT PLATE -> EQUATION A
C R >= +D AND V >= VP : BOB TOUCHES RIGHT PLATE -> EQUATION B
C (THE PLATE CAN ONLY PUSH: CONTACT LASTS WHILE IT CLOSES ON THE BOB)
C OTHERWISE NO CONTACT -> EQUATION C
PROGRAM BOB
REAL X, V, T, DT, TEND, AMP, W, D, GL, XP, VP, R
INTEGER ISTATE, NPRINT, K, NA, NB, NC
WRITE (*,*) 'AMPLITUDE, OMEGA, CLEARANCE D, G/L ?'
READ (*,*) AMP, W, D, GL
WRITE (*,*) 'TIME STEP, END TIME, PRINT EVERY N STEPS ?'
READ (*,*) DT, TEND, NPRINT
C START AT REST AT THE CENTRE OF THE GAP
X = 0.0
V = 0.0
T = 0.0
K = 0
NA = 0
NB = 0
NC = 0
WRITE (*,100)
10 IF (T .GT. TEND) GO TO 90
XP = AMP*SIN(W*T)
VP = AMP*W*COS(W*T)
R = X - XP
C DECIDE WHICH EQUATION GOVERNS THIS STEP
IF (R .LE. -D .AND. V .LE. VP) THEN
CALL EQA(X, V, XP, VP, D)
ISTATE = 1
NA = NA + 1
ELSE IF (R .GE. D .AND. V .GE. VP) THEN
CALL EQB(X, V, XP, VP, D)
ISTATE = 2
NB = NB + 1
ELSE
CALL EQC(X, V, GL, DT)
ISTATE = 3
NC = NC + 1
END IF
IF (MOD(K, NPRINT) .EQ. 0) WRITE (*,110) T, XP, X, X-XP, ISTATE
T = T + DT
K = K + 1
GO TO 10
90 WRITE (*,120) NA, NB, NC
100 FORMAT (/' T XP X X-XP EQN')
110 FORMAT (F7.3, 3F11.5, I4)
120 FORMAT (/' STEPS ON EQUATION A, B, C: ', 3I8)
STOP
END
C
C EQUATION A: BOB PRESSED ON THE LEFT PLATE, MOVES WITH IT
SUBROUTINE EQA(X, V, XP, VP, D)
REAL X, V, XP, VP, D
X = XP - D
V = VP
RETURN
END
C
C EQUATION B: BOB PRESSED ON THE RIGHT PLATE, MOVES WITH IT
SUBROUTINE EQB(X, V, XP, VP, D)
REAL X, V, XP, VP, D
X = XP + D
V = VP
RETURN
END
C
C EQUATION C: FREE PENDULUM, X'' = -(G/L)*X (ONE EULER-CROMER STEP)
SUBROUTINE EQC(X, V, GL, DT)
REAL X, V, GL, DT
V = V - GL*X*DT
X = X + V*DT
RETURN
ENDOutput (part, printed every 0.125 s; EQN 1, 2, 3 = A, B, C):
T XP X X-XP EQN
0.000 0.00000 0.00000 0.00000 3
0.125 0.00707 0.00572 -0.00135 3
0.250 0.01000 0.01200 0.00200 2
0.375 0.00707 0.00907 0.00200 2
0.500 0.00000 0.00200 0.00200 2
0.625 -0.00707 -0.00585 0.00122 3
0.750 -0.01000 -0.01200 -0.00200 1
0.875 -0.00707 -0.00907 -0.00200 1What the run shows.
- The plates start moving right, and the bob, left behind, is struck by the left plate.
- It is thrown ahead and flies freely (C) across the gap.
- It meets the right plate as the plate swings back, and is carried by it (B).
- The cycle then repeats on the left side (A).
Over 3 s the bob spends about half the time in contact, split equally between the two plates.
✓ Program compiled and tested The equations A, B and C are not printed in the question, so we stated a contact model for them. We then compiled the FORTRAN program with gfortran and ran it (amplitude 10 mm, ω = 2π rad/s, clearance 2 mm, g/L = 0.098 s⁻²). The same algorithm written independently in Python gave the same states at every printed time step.
Draw the flow chart and write a computer programme in Fortran for computing standard deviation of a given set of 100 numbers , where where x is an individual number of a group is the arithmetic mean of the group of numbers and N is the size of the group of numbers.
Solution
The formula in the question is the population standard deviation:
It needs two passes over the data. The first pass finds ; the second adds up the squared deviations.
Flow chart
FORTRAN program
C STANDARD DEVIATION OF 100 NUMBERS
PROGRAM STDEV
INTEGER N, I
PARAMETER (N = 100)
REAL X(N), SUM, XBAR, S2, SIGMA
READ (*,*) (X(I), I = 1, N)
SUM = 0.0
DO 10 I = 1, N
SUM = SUM + X(I)
10 CONTINUE
XBAR = SUM / N
S2 = 0.0
DO 20 I = 1, N
S2 = S2 + (X(I) - XBAR)**2
20 CONTINUE
SIGMA = SQRT(S2 / N)
WRITE (*,100) N, XBAR, SIGMA
100 FORMAT (' N = ', I4, ' MEAN = ', F10.4, ' SIGMA = ', F10.4)
STOP
ENDNotes:
PARAMETER (N = 100)fixes the array size and the loop limits in one place. To handle any N up to 100, read N first, as in the student-heights program on this page.- The 100 numbers can be typed in free format, separated by spaces or line breaks, or read from a file by redirection:
./stdev < data.txt.
✓ Program compiled and tested We compiled the program with gfortran and ran it on 100 test numbers. It gave mean 23.5145 and σ = 14.3004, matching Python’s statistics.pstdev.
Explain the mechanism of hydrodynamic and boundary lubrications. State with justification the important properties of lubricant in each case.
Solution
Hydrodynamic (thick-film) lubrication
- Mechanism. The moving surface drags viscous oil into a converging (wedge-shaped) gap. Squeezing the oil into the narrowing gap builds up a pressure.
- In a journal bearing the shaft runs slightly off-centre, which makes the wedge itself. The film pressure supports the load, so the surfaces are fully separated by a film thicker than their roughness (h ≈ 5–50 µm).
- Friction comes only from shearing the oil, so it is very low (f ≈ 0.001–0.005), and there is almost no wear.
- It needs enough speed, viscosity and a not-too-high load, that is, a large .
Boundary (thin-film) lubrication
- Mechanism. At low speed, high load, at starting and stopping, or with too little oil, the film becomes thinner than the surface roughness. The asperities (high points) then touch.
- The load is carried by the asperities, coated with adsorbed or chemically reacted layers only a few molecules thick (polar fatty acids, or sulphides, chlorides and phosphates formed by additives).
- These layers shear easily and keep the metal from welding together. Friction is higher (f ≈ 0.05–0.15) and some wear occurs.
- Between the two regimes lies mixed lubrication.
Important properties of the lubricant
| Regime | Property | Why it matters |
|---|---|---|
| Hydrodynamic | Viscosity (the single most important) | Sets the load capacity and the film thickness. Too low: the film breaks. Too high: large friction loss and heating. |
| Hydrodynamic | High viscosity index | Viscosity should change little with temperature, because the film heats up in running. |
| Hydrodynamic | Oxidation and thermal stability | The oil circulates hot for long periods, and must not form sludge or acid. |
| Hydrodynamic | Low pour point; resistance to foaming and emulsifying | It must flow at start-up and keep a continuous film. |
| Hydrodynamic | Good thermal conductivity and specific heat | The oil also carries the friction heat away. |
| Boundary | Oiliness (lubricity) | Polar molecules (fatty acids, esters) must cling to the metal and form a strong adsorbed layer. |
| Boundary | Extreme-pressure (EP) and anti-wear additives (S, Cl, P compounds, ZDDP) | They react with the hot asperities to form low-shear-strength films that prevent seizure. |
| Boundary | High film strength and flash point | Local flash temperatures at the asperity contacts are high. |
| Boundary | Chemical stability; non-corrosive | The additives must protect the surfaces, not attack them. |
In short: in hydrodynamic lubrication the oil’s bulk property, viscosity, carries the load. In boundary lubrication the surface chemistry of the oil (oiliness and EP additives) prevents metal-to-metal contact.
✓ Answer checked step by step We checked the mechanisms and the lubricant properties against standard machine-design and tribology texts (the Stribeck curve and the film-thickness regimes).
Write an interactive file-oriented C programme that will maintain the list of names, addresses and telephone numbers in alphabetical order (by last name). Consider the information associated with each name to be a separate record and represent each record as a structure.
Solution
Each entry is one structure. The program keeps an array of these structures in alphabetical order of last name at all times:
- a new record is inserted in its place, by shifting the later records down one position;
- a deleted record’s gap is closed up.
The array is read from a binary file at start-up and written back after every change, so the list survives between runs. A menu makes the program interactive.
#include <stdio.h>
#include <string.h>
#include <strings.h>
#define MAX 500
#define FNAME "phonebook.dat"
struct record { /* one entry = one structure */
char last[30];
char first[30];
char address[80];
char phone[20];
};
struct record book[MAX];
int count = 0;
void getline_s(const char *prompt, char *s, int size)
{
printf("%s", prompt);
if (fgets(s, size, stdin) == NULL) s[0] = '\0';
s[strcspn(s, "\n")] = '\0'; /* drop the newline */
}
int compare(const struct record *a, const struct record *b)
{ /* by last name, then first name, ignoring case */
int c = strcasecmp(a->last, b->last);
return c != 0 ? c : strcasecmp(a->first, b->first);
}
void load(void) /* read the file into memory */
{
FILE *fp = fopen(FNAME, "rb");
if (fp == NULL) return; /* first run: no file yet */
count = fread(book, sizeof(struct record), MAX, fp);
fclose(fp);
}
void save(void) /* write memory back to the file */
{
FILE *fp = fopen(FNAME, "wb");
if (fp == NULL) { printf("Cannot write %s\n", FNAME); return; }
fwrite(book, sizeof(struct record), count, fp);
fclose(fp);
}
void add(void) /* insert in alphabetical position */
{
struct record r;
int i;
if (count == MAX) { printf("List is full.\n"); return; }
getline_s("Last name : ", r.last, sizeof r.last);
getline_s("First name: ", r.first, sizeof r.first);
getline_s("Address : ", r.address, sizeof r.address);
getline_s("Telephone : ", r.phone, sizeof r.phone);
i = count - 1;
while (i >= 0 && compare(&book[i], &r) > 0) {
book[i + 1] = book[i]; /* shift larger names down */
i--;
}
book[i + 1] = r;
count++;
save();
printf("Added.\n");
}
int find(const char *last)
{
int i;
for (i = 0; i < count; i++)
if (strcasecmp(book[i].last, last) == 0) return i;
return -1;
}
void show(int i)
{
printf("%-15s %-12s %-30s %s\n", book[i].last, book[i].first,
book[i].address, book[i].phone);
}
void search(void)
{
char key[30]; int i, found = 0;
getline_s("Last name to find: ", key, sizeof key);
for (i = 0; i < count; i++)
if (strcasecmp(book[i].last, key) == 0) { show(i); found = 1; }
if (!found) printf("Not found.\n");
}
void delete_rec(void)
{
char key[30]; int i;
getline_s("Last name to delete: ", key, sizeof key);
i = find(key);
if (i < 0) { printf("Not found.\n"); return; }
for (; i < count - 1; i++) book[i] = book[i + 1]; /* close the gap */
count--;
save();
printf("Deleted.\n");
}
void list(void)
{
int i;
printf("%d record(s)\n", count);
for (i = 0; i < count; i++) show(i);
}
int main(void)
{
char ch[8];
load();
for (;;) {
printf("\n1 Add 2 Delete 3 Search 4 List 5 Quit\n");
getline_s("Choice: ", ch, sizeof ch);
switch (ch[0]) {
case '1': add(); break;
case '2': delete_rec(); break;
case '3': search(); break;
case '4': list(); break;
case '5': save(); return 0;
default : printf("Choose 1 to 5.\n");
}
}
}Sample session (second run, the file already holds Agarwal, Kumar and Sharma; we add Bose, delete Kumar and list):
1 Add 2 Delete 3 Search 4 List 5 Quit
Choice: 4
3 record(s)
Agarwal Meena 4 Park St, Kolkata 033-2221111
Bose Tara 9 Lake Rd, Chennai 044-2445566
Sharma Ravi 12 MG Road, Pune 020-2551234Design points:
- Structure:
struct recordgroups the four fields of one person, so a whole record is copied, compared or written with one statement. - File-oriented:
fread/fwritemove the whole array of structures to and fromphonebook.datin binary form. If the file does not exist on the first run, the program starts with an empty list. - Alphabetical order:
compare()usesstrcasecmp, so “kumar” sorts with “Kumar”. Equal last names are ordered by first name. Keeping the list sorted on insertion means it never needs a separate sort. fgetsreads whole lines, so addresses may contain spaces.
✓ Program compiled and tested We compiled the program with gcc and ran it in two sessions. In the first we added three people out of alphabetical order (including a lower-case name) and the list came out sorted. In the second, the file was reloaded, a new name was inserted in its place, one record was deleted, a search was made and the list was correct.
Write a FORTRAN programme for the amount payable (A) after n years on a principle amount (P) at a rate of interest (i%) compounded annually. The formula for calculating the amount is given below:
Solution
The program reads P, i and n, evaluates the formula with the exponentiation operator **, and also prints the balance at the end of each year.
C AMOUNT AFTER N YEARS, INTEREST COMPOUNDED ANNUALLY
PROGRAM COMPND
INTEGER N, K
REAL P, RATE, A
WRITE (*,*) 'PRINCIPAL P, RATE I (PER CENT), YEARS N ?'
READ (*,*) P, RATE, N
A = P * (1.0 + RATE/100.0)**N
WRITE (*,100) P, RATE, N, A
C YEAR-BY-YEAR TABLE (SAME RESULT BY REPEATED MULTIPLICATION)
A = P
DO 10 K = 1, N
A = A * (1.0 + RATE/100.0)
WRITE (*,110) K, A
10 CONTINUE
100 FORMAT (' P = ', F12.2, ' I = ', F6.2, ' % N = ', I3,
& /' AMOUNT PAYABLE A = ', F14.2)
110 FORMAT (' END OF YEAR ', I3, F14.2)
STOP
ENDSample output (P = 10 000, i = 8, n = 5):
P = 10000.00 I = 8.00 % N = 5
AMOUNT PAYABLE A = 14693.28
END OF YEAR 1 10800.00
END OF YEAR 2 11664.00
END OF YEAR 3 12597.12
END OF YEAR 4 13604.89
END OF YEAR 5 14693.28N is declared INTEGER, so (1.0 + RATE/100.0)**N is worked out by repeated multiplication, which is exact and fast. With a real exponent, FORTRAN would use logarithms instead.
✓ Program compiled and tested We compiled the program with gfortran and ran it for P = Rs 10 000, i = 8 % and n = 5 years. It gave A = Rs 14 693.28, the same as 10 000 × 1.08⁵ = 14 693.28 worked out in Python, and the year-by-year table ends at the same figure.
What is the classical Reynold’s Equation for one dimensional fluid flow based on Hydrodynamic lubrication theory? What are the assumptions made in arriving at this equation? Explain the significance of Sommerfeld Number, Temperature Rise and Minimum Film Thickness for assessing a bearing performance.
Solution
Reynolds equation (one-dimensional flow)
Take the oil film between a surface moving at speed in the -direction and a fixed surface, with film thickness . The flow is taken as unchanged across the width (an infinitely long bearing).
Force balance on an element. The pressure gradient balances the viscous shear:
Velocity profile. Integrate twice with at and at . The profile is a linear shear part plus a pressure-driven parabola:
Flow per unit width.
Continuity. is the same at every section, so . This gives the Reynolds equation:
The wedge term on the right shows why a converging film () is needed to build up pressure.
For a 2-D film the equation becomes
Assumptions
- The lubricant is Newtonian, and the flow is laminar.
- Inertia and body forces (gravity) are negligible compared with the viscous and pressure forces.
- The film is very thin compared with the other dimensions, so the pressure is constant across it (). The curvature of the film is neglected.
- The viscosity is constant through the film (isothermal), and the fluid is incompressible.
- There is no slip at the surfaces.
- Only matters: the velocity gradients along the film are negligible.
- For the 1-D form, there is no side leakage (an infinitely wide bearing).
Significance of the performance parameters
- Sommerfeld number
where is in rev/s and .
It is the dimensionless bearing characteristic number: it groups everything the designer can choose.
For a given , the Raimondi–Boyd charts give, in terms of alone: the eccentricity ratio, the minimum film thickness, the coefficient of friction , the oil flow and the temperature rise.
A large means light load or high speed: a thick film and higher friction.
A small means heavy load: a thin film, near the boundary regime.
Two bearings with the same and behave alike.
Temperature rise
- The friction power heats the oil: , where is the oil flow.
- Viscosity falls steeply with temperature, so the design must be iterated. Assume an average film temperature, find μ, work out ΔT, and repeat until they agree.
- Too large a rise thins the oil, reduces the load capacity and speeds up oxidation. In practice the oil outlet temperature is kept below about 80–90 °C.
Minimum film thickness
- This is the critical safety criterion. It must exceed the combined surface roughness of the shaft and the bearing, with a margin for misalignment, deflection and dirt particles; a typical design value is – mm.
- If is too small, the bearing goes into mixed or boundary lubrication and wears or seizes. Designers often choose to lie between the minimum-friction and maximum-load lines of the Raimondi–Boyd chart.
✓ Derivation checked step by step We checked the derivation of the Reynolds equation step by step from the force balance on a fluid element and continuity, together with the meaning of the performance parameters, against standard lubrication texts.
There are ‘NSTUD’ students in a class whose roll numbers are given in an array ‘NROLL’ and the marks obtained in the final examination are given in array ‘TOTAL’. Write a program, in FORTRAN, to read roll numbers and corresponding marks of all the students and arrange them in order of merit. Assume the value of ‘NSTUD’ as 40.
Solution
The program reads the 40 roll numbers into NROLL and the marks into TOTAL. It then sorts the marks in descending order, moving each roll number together with its marks, and prints the merit list.
An insertion sort is used. Each new student is slid up past all students with lower marks. Students with equal marks keep their input order, because the sort is stable.
C ARRANGE NSTUD STUDENTS IN ORDER OF MERIT (HIGHEST TOTAL FIRST)
PROGRAM MERIT
INTEGER NSTUD
PARAMETER (NSTUD = 40)
INTEGER NROLL(NSTUD), I, J, KR, IRANK
REAL TOTAL(NSTUD), T
WRITE (*,*) 'ENTER ROLL NUMBER AND TOTAL FOR EACH STUDENT'
DO 10 I = 1, NSTUD
READ (*,*) NROLL(I), TOTAL(I)
10 CONTINUE
C INSERTION SORT, DESCENDING ON TOTAL. ROLL NUMBERS MOVE WITH
C THEIR MARKS. EQUAL TOTALS KEEP THEIR INPUT ORDER.
DO 30 I = 2, NSTUD
T = TOTAL(I)
KR = NROLL(I)
J = I - 1
20 IF (J .GE. 1) THEN
IF (TOTAL(J) .LT. T) THEN
TOTAL(J+1) = TOTAL(J)
NROLL(J+1) = NROLL(J)
J = J - 1
GO TO 20
END IF
END IF
TOTAL(J+1) = T
NROLL(J+1) = KR
30 CONTINUE
C PRINT THE MERIT LIST. EQUAL TOTALS SHARE A RANK.
WRITE (*,100)
IRANK = 1
DO 40 I = 1, NSTUD
IF (I .GT. 1) THEN
IF (TOTAL(I) .LT. TOTAL(I-1)) IRANK = I
END IF
WRITE (*,110) IRANK, NROLL(I), TOTAL(I)
40 CONTINUE
100 FORMAT (/' RANK ROLL NO. TOTAL')
110 FORMAT (I6, I10, F10.1)
STOP
ENDSample output (first lines; three students tied on 450):
RANK ROLL NO. TOTAL
1 1008 450.0
1 1023 450.0
1 1026 450.0
4 1006 440.0
4 1011 440.0
4 1039 440.0
7 1002 430.0Notes:
- The key point is to swap (or move)
NROLLandTOTALtogether; sorting only the marks would lose track of who scored them. - A bubble sort with the same paired exchange is equally acceptable for 40 students.
- For a large class a faster sort such as heapsort would be used.
✓ Program compiled and tested We compiled the program with gfortran and ran it on 40 test students with several tied totals. The 40 totals came out in non-increasing order, each roll number stayed with its own marks, and tied students shared a rank (1, 1, 1, 4, 4, 4, 7 …). The order matched a Python sort of the same data.
A tank having liquid capacitance is supplying liquid through a pipe of resistance to another tank of liquid capacitance which delivers this liquid through another pipe of resistance . The steady-state outflow rates of tank 1 and that of tank 2 are and and heads are and respectively. The flow balance equation for tank 1 is Similarly for tank 2 is where ; and Δ’s show small variations of quantities. Draw the overall feedback block diagram of the system and obtain the transfer function.
[Figure: Two open tanks side by side, “Tank 1” (capacitance ) on the left and “Tank 2” (capacitance ) on the right, both containing liquid. Inflow Q enters Tank 1 from the top through a valve. A pipe at the bottom of Tank 1 carries flow (labelled below the pipe) to Tank 2; a pipe at the bottom of Tank 2 discharges to the right (arrow; its label is not legible in the copy)]
Solution
Equations in the Laplace domain (small changes, zero initial values; write for the transforms of the Δ quantities):
Each equation is one block:
- each tank is an integrator acting on the difference between its inflow and outflow;
- each pipe is a gain acting on the head difference across it.
Block diagram
- Inner loop of tank 2. From : the block gives , then gives , which is fed back negatively. Reduced:
Interaction loop. is fed back to the head difference , so tank 2 “pushes back” on tank 1. This is why the two tanks do not simply act as two first-order lags in series.
Outer loop of tank 1. passes through to give .
Transfer function. From the second equation, . From the last two, , so
Substitute into the first equation, :
In terms of the head in tank 2:
Mason’s formula check.
- Forward path: .
- Loops: , , . and do not touch.
- So . Multiplying through by gives the same denominator.
Interpretation.
- The system is second order and overdamped: both poles are real and negative, so the response is non-oscillatory.
- The cross term is the interaction (loading) effect. If the tanks did not interact (tank 1 discharging freely into tank 2), the result would be , with no term.
- The steady-state gain is 1: in steady flow, all that enters leaves.
✓ Derivation checked step by step We checked the transfer function in SymPy by solving the four Laplace-domain equations, and checked it again by Mason’s gain formula on the block diagram (three loops, two of them non-touching). All three results agree.
Write complete program in C-language to obtain the output: Civil Services Examination.
Solution
#include <stdio.h>
int main(void)
{
printf("Civil Services Examination\n");
return 0;
}Output
Civil Services ExaminationHow it works:
#include <stdio.h>brings in the declaration ofprintf.- Execution starts at
main(). printfsends the string to the standard output, and\nends the line.return 0tells the operating system the program ended normally.
✓ Program compiled and tested We compiled the program with gcc and ran it; it printed the required line.
The frictional force f(x) acting on a body is expressed by the following: This function is required to be used in the following equation: Write a FORTRAN programme for the stated problem.
Solution
Reading the problem.
- The friction function has a dead band: for and for .
- It is called with the argument , so
- Because , only the two printed branches are ever needed. The program treats as the second branch, which also covers the unprinted case .
The natural FORTRAN tool for is a function subprogram. It is called with any argument, here F(V**2).
The main program reads m, a and t, and a range of speeds. It prints a table of , and , so the switch of the friction law at () can be seen.
C G = M*V*T - F(V**2) + A*T WITH THE PIECEWISE FRICTION FUNCTION F
PROGRAM FRICT
REAL M, A, T, V, V1, V2, DV, G, F
INTEGER K, NSTEP
WRITE (*,*) 'M, A, T ?'
READ (*,*) M, A, T
WRITE (*,*) 'FIRST V, LAST V, STEP DV ?'
READ (*,*) V1, V2, DV
NSTEP = NINT((V2 - V1)/DV)
WRITE (*,100)
DO 10 K = 0, NSTEP
V = V1 + K*DV
G = M*V*T - F(V**2) + A*T
WRITE (*,110) V, F(V**2), G
10 CONTINUE
100 FORMAT (/' V F(V**2) G')
110 FORMAT (F8.3, 2F12.4)
STOP
END
C
C FRICTION FUNCTION: ZERO INSIDE THE DEAD BAND |X| <= 0.5
REAL FUNCTION F(X)
REAL X
IF (ABS(X) .LE. 0.5) THEN
F = 0.0
ELSE
F = 2.0*X**2
END IF
RETURN
ENDSample output (m = 2, a = 1.5, t = 3):
V F(V**2) G
0.000 0.0000 4.5000
0.200 0.0000 5.7000
0.400 0.0000 6.9000
0.600 0.0000 8.1000
0.800 0.8192 8.4808
1.000 2.0000 8.5000
1.200 4.1472 7.5528Up to the friction term is zero and grows linearly with . Beyond it, friction grows as and soon outweighs the term.
✓ Program compiled and tested We compiled the program with gfortran and ran it for m = 2, a = 1.5, t = 3 and v from 0 to 1.2. A separate Python evaluation of the same formula gave the same g at every step (for example v = 0.8: f = 0.8192, g = 8.4808).
More on Other Questions Outside the Present Syllabus
- All Mechanical Engineering PYQ solutions, topic by topic
- Other Questions Outside the Present Syllabus topic-wise PYQs (questions only, for practice)
- Mechanical Engineering PYQ analysis: which units carry the marks year by year
- Year-wise question papers
- Mechanical Engineering booklist
Questions: UPSC Civil Services (Main) Examination, Mechanical Engineering Paper I, 1995–2007. Solutions: Optional Province. Found an error? Tell us.

