Lab Exercise: Declaring a Structure Variable and Recursive Function in C, Assignments of Programming Languages

Two exercises from a c programming lab. The first exercise involves declaring a structure variable named 'rectangle' with two member variables 'length' and 'breadth' of type float. The document instructs creating two variables of this structure in the main function, taking user input for both variables, and defining a function 'addrectangle' to add the lengths and breadths of the two rectangles. The second exercise involves calculating the sum of natural numbers using recursion. The user is prompted to enter a number, and the function adds all numbers from 1 to the user-input number.

Typology: Assignments

2019/2020

Uploaded on 12/14/2020

razaroghani
razaroghani 🇵🇰

4.5

(4)

151 documents

1 / 2

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
pf2

Partial preview of the text

Download Lab Exercise: Declaring a Structure Variable and Recursive Function in C and more Assignments Programming Languages in PDF only on Docsity!

Lab

Page. 1

9.1 Declare a structure variable rectangle. Define its two-member variable length and breadth of type float. Create two variables of this structure in main () function. Take date form user for both these variable. Define a function addrectangle (). Pass these two structure variable to this function and add the length and breadth of both rectangles. Display the resultant rectangle sides.

Lab

Page. 2

9.2 Calculate the sum of natural number using recursion. [Hint: if user enter 5, the function will add all the number from 1 to 5 i.e.; 5+4+3+2+1=15]