You are on page 1of 2

Computer Engineering Department

TED University

CMPE 252 – C Programming, Spring 2022


Lab 01
An Armstrong number of three digits is an integer such that the sum of the cubes of its digits is equal to
the number itself. For example, 371 is an Armstrong number since 3^3 + 7^3 + 1^3 = 371. In this lab, you
are asked to complete armstrong_task1.c, armstrong_task2.c and armstrong_task3.c program files
which has been already given in Moodle. In this program, you are asked to enter a number, then the
program checks whether the given input is armstrong number or not.

In this experiment you are going to implement series functions to calculate armstrong numbers with
different scenarios.

In the given program there are four functions, namely, main, armstrong_number, armstrong_in_range,
and armstrong_recursive. main function is already provided, and it is supposed to remain as it is (you
should not change it). You are required to implement armstrong_number, armstrong_in_range and
armstrong_recursive functions.

Task 1: Complete armstrong_task1.c by implementing armstrong_number function.


int armstrong_number (int arm) ;

A number to be checked whether it is armstrong number or not. It is given as an input and the function
returns 1 if it is armstrong and 0 if not.

Consider the below example run:

Enter a three-digit integer: 371


371 is an Armstrong number.

Enter a three-digit integer: 101


101 is not an Armstrong number.

Task 2: Complete armstrong _task2.c by implementing armstrong_in_range function.


void armstrong_in_range (int a, int b) ;

A range to be checked is entered as an input to calculate all armstrong numbers in the given range. The
function prints all the armstrong numbers in the given range.
Computer Engineering Department

TED University

Consider the below example run:

Enter a three-digit integer to start: 100


Enter a three-digit integer to end: 999
The Armstrong numbers in range 100 and 999: 153 370 371 407

Enter a three-digit integer to start: 400


Enter a three-digit integer to end: 500
The Armstrong numbers in range 400 and 500: 407

The ranges are calculated and printed through the called function.

Task 3: Complete armstrong _task3.c by implementing armstrong_recursive function.


int armstrong_recursive (int arm) ;

It performs same operation as in Task 1, however in a recursive manner. A number to be checked whether
it is armstrong or not is given as an input and the function returns the summation of the digits. If the
returned value is equal to the given input value then it is an armstrong number.

The implementations without recursion will not be graded for this part.

Consider the below example run:

Enter a three-digit integer: 153


153 is an Armstrong number.

Enter a three-digit integer: 234


234 is not an Armstrong number.

You might also like