Command Line program to find Armstrong number using Command line arguments
Armstrong Number Command Line Programming
#include<stdio.h>
#include<stdlib.h>
int main(int argc,char *argv[])
{
int Given_number= atoi(argv[1]);
int num;
for(num=1; num<=Given_number; num++)
{
int a=num;
int s=0;
int r=0;
while(a>0)
{
s=a%10;
r=r+(s*s*s);
a=a/10;
}
if(r==num)
printf(” %d isarmstrong no \n”, num);
}
}
[/code]
Code – 2
[code language=”cpp”]
#include<stdio.h>
void main(int argc, char * argv[])
{
int num,num1,arms=0,rem;
if ( argc != 2 )
{
printf(“Enter the number:\n”);
scanf(“%d”,&num);
}
else
{
num = atoi(argv[1]);
}
num1=num;
while(num>0)
{
rem=num%10;
arms=arms+rem*rem*rem;
num=num/10;
}
if(num1==arms)
{
printf(” \n%d is an Armstrong number”,num1);
}
else
{
printf(“\n%d is NOT an Armstrong number”,num1);
}
}
[/code]
One Subscription, For Everything
The new cool way of learning and upskilling -
One Subscription access everything
Get Access to PrepInsta Prime
from FAANG/IITs/TOP MNC's
PrepInstaPrime
Get over 200+ course One Subscription
Courses like AI/ML, Cloud Computing, Ethical Hacking, C, C++, Java, Python, DSA (All Languages), Competitive Coding (All Languages), TCS, Infosys, Wipro, Amazon, DBMS, SQL and others.
Login/Signup to comment