Home / Programs / Reverse a Number using Command Line Argument
🚀 Programming Example

Reverse a Number using Command Line Argument

👁 3,217 Views
💻 Practical Program
📘 Step Learning
Write a C program which will reverse all the digits of a Number using Command Line Arguments to reverse the digits of a number

💻 Program Code

#include<stdio.h>
#include<stdlib.h>

int main(int argc, char *argv[])
{
    if(argc==1)
    {
        printf("No Arguments");
        return 0;
    }
    else
    {
        int n,reverseNumber,temp,rem;
        n=atoi(argv[1]);
        temp=n;
        reverseNumber=0;

    while(temp)
    {
        rem=temp%10;
        reverseNumber=reverseNumber*10+rem;
        temp=temp/10;
    }
    
    printf("%d",reverseNumber);
    return 0;
}
}
                        

🖥 Program Output

123

321
                            

📘 Explanation

no
📚 Learning Subject

Master Programming Through Practical Examples

Improve your coding logic, problem-solving skills and programming confidence by practicing real-world examples with explanations.

🎯 How to learn from this example

First understand the algorithm carefully. Then study the program line-by-line and compare it with the output. Finally, review the explanation section to strengthen your logic and programming understanding.

🔥 Practice suggestion

Rewrite the program without looking at the code. Modify values, conditions or logic and run it again. This helps improve confidence and strengthens coding skills much faster.