0% found this document useful (0 votes)
335 views8 pages

Project CSC 430 Fakulti Kejuruteraan Mekanikal Uitm Shah Alam

This document describes a C++ program to reverse the digits of a positive integer number. The program takes a number as input, uses a do-while loop to extract the units digit at each iteration by using the modulo and division operators, and displays the number in reverse order as output. The objective is to display the entered number with its digits in reverse order. The flowchart shows the logic of using a do-while loop to repeatedly extract digits and build the reversed number.

Uploaded by

piju91
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
335 views8 pages

Project CSC 430 Fakulti Kejuruteraan Mekanikal Uitm Shah Alam

This document describes a C++ program to reverse the digits of a positive integer number. The program takes a number as input, uses a do-while loop to extract the units digit at each iteration by using the modulo and division operators, and displays the number in reverse order as output. The objective is to display the entered number with its digits in reverse order. The flowchart shows the logic of using a do-while loop to repeatedly extract digits and build the reversed number.

Uploaded by

piju91
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

PROJECT CSC 430

FAKULTI KEJURUTERAAN MEKANIKAL UiTM SHAH ALAM

Lecturer’s name : Puan Norzehan Sakamat


CONTENT

Members’ Information................................................................................. 3

Problem........................................................................................................ 4

Objective...................................................................................................... 4

Flowchart...................................................................................................... 5

Code Program............................................................................................... 6

Program Screen............................................................................................ 7

Reference..................................................................................................... 8

2
MEMBERS’ INFORMATION

Name ID No. IC No. Contact No.

Afizu Bin Aznan 2010869844 910216-06-6029 60139075635

Mohamad Zakuan Bin M. Jafri 2010822042 911015-05-5299 60136435742

Ahmad Musthofa Bin Jais 2010825538 910806-10-5569 60127775336

3
PROBLEM

Write a program to reverse the digits of a positive integer number. For example, if the 1708
is entered, the number displayed should be 8071. (Hint: use a do statement and
continuously strip off and display the unit digit of the number. If the variable num initially
contains the number entered, the unit digit is obtained as (num % 10). After a unit digit is
displayed, dividing the number by 10 sets up the number for the next iteration. Thus, (1708
% 10) is 8 and (1708 / 10) is 170. The do statement should continue as long as the remaining
number is not zero.)

OBJECTIVE

Display the entered number in reverse order.

4
FLOWCHART

Start

reverse = 0

Enter number

If no > 0
No

Yes

digit = no % 10
reverse = reverse * 10 + digit
no = no / 10

no != 0
Yes

No

Display reverse number

End

5
CODE PROGRAM

#include<iostream>

using namespace std;

int main()

int reverse=0,no,digit;

cout<<"Enter no = ";

cin>>no;

if(no>0)

do

digit=no%10;

reverse=reverse*10+digit;

no=no/10;

while(no!=0);

cout<<"Reverse no = "<<reverse<<endl;

system("pause");

6
PROGRAM SCREEN

SAMPLE INPUT

SAMPLE OUTPUT

7
REFERENCE

 C++ Programming Lab Manual (Noor Latiffah Adam,2011)


 Problem Solving with C++ (2011)

THANK YOU PUAN NORZEHAN SAKAMAT

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy