[go: up one dir, main page]

0% found this document useful (0 votes)
4 views3 pages

Pankaj 23

The document outlines an assignment to create a program that reverses a given integer. It includes an algorithm, flowchart, and C programming code to achieve this task. The program prompts the user for a number, processes it to reverse the digits, and then outputs the reversed number.

Uploaded by

kanishkbabugarh
Copyright
© © All Rights Reserved
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)
4 views3 pages

Pankaj 23

The document outlines an assignment to create a program that reverses a given integer. It includes an algorithm, flowchart, and C programming code to achieve this task. The program prompts the user for a number, processes it to reverse the digits, and then outputs the reversed number.

Uploaded by

kanishkbabugarh
Copyright
© © All Rights Reserved
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/ 3

ASSIGMENT:23

QUESTION:
Write a program to find the reverse of a number.

ALGORITHM:
Step 1: Start
Step 2: Input: Get the integer num from the user (the number whose reverse is to be found).
Step 3: Initialize: Set the variable reversed to 0 (this will store the reversed number).
Step 4: Calculate & Initialize:
remainder = num % 10.
reversed = reversed * 10 + remainder.
num = num / 10.
Step 5: Output: Print the reversed number reversed.
Step 6: Stop

CREATED BY PANKAJ
FLOWCHART:
Start

Declare variable: num,sum=0,remainder

Print: “Enter a number:”

Input: num

False
while(num!=0)

TRUE
Calculate and initialize
remainder = number % 10; // Get the last digit
reverse = reverse * 10 + remainder; // Add the digit to reverse
number = number / 10; // Remove the last digit

Print"Reversed number: %d\n", reverse

Stop

PROGRAM:
CREATED BY PANKAJ
#include<stdio.h>
int main() {
int number, reverse = 0, remainder;

// Take input from the user


printf("Enter a number: ");
scanf("%d", &number);

// Reverse the number


while (number != 0) {
remainder = number % 10; // Get the last digit
reverse = reverse * 10 + remainder; // Add the digit to reverse
number = number / 10; // Remove the last digit
}

// Output the reversed number


printf("Reversed number: %d\n", reverse);

return 0;
}
INPUT/OUTPUT:
Enter a number: 567875
Reversed number: 578765

...Program finished with exit code 0


Press ENTER to exit console.

CREATED BY PANKAJ

You might also like