Code 1:

1.

**Warp to check a number is Armstrong**
2.

**C program to check whether a number is Armstrong or not**
3.

**Simple c program for Armstrong number**
4.

**Armstrong number in c with output**
#include<stdio.h>

int main(){

int num,r,sum=0,temp;

printf("Enter a
number: ");

scanf("%d",&num);

temp=num;

while(num!=0){

r=num%10;

num=num/10;

sum=sum+(r*r*r);

}

if(sum==temp)

printf("%d is an
Armstrong number",temp);

else

printf("%d is
not an Armstrong number",temp);

return 0;

}

Sample output:

Enter a number: 153

153 is an Armstrong number

**The time complexity of a program that determines Armstrong number is**: O (Number of digits)

Code 2:

1.

**Write a c program for Armstrong number**
2.

**C program for Armstrong number generation**
3.

**How to find Armstrong number in c**
4.

**Code for Armstrong number in c**
#include<stdio.h>

int main(){

int num,r,sum,temp;

int min,max;

printf("Enter
the minimum range: ");

scanf("%d",&min);

printf("Enter
the maximum range: ");

scanf("%d",&max);

printf("Armstrong
numbers in given range are: ");

for(num=min;num<=max;num++){

temp=num;

sum
= 0;

while(temp!=0){

r=temp%10;

temp=temp/10;

sum=sum+(r*r*r);

}

if(sum==num)

printf("%d
",num);

}

return 0;

}

Sample output:

Enter the minimum range: 1

Enter the maximum range: 200

Armstrong numbers in given range
are: 1 153

Code 3:

1.

**Armstrong number in c using for loop**
#include<stdio.h>

int main(){

int num,r,sum=0,temp;

printf("Enter a
number: ");

scanf("%d",&num);

for(temp=num;num!=0;num=num/10){

r=num%10;

sum=sum+(r*r*r);

}

if(sum==temp)

printf("%d is an
Armstrong number",temp);

else

printf("%d is
not an Armstrong number",temp);

return 0;

}

Sample output:

Enter a number: 370

370 is an Armstrong number

Logic of Armstrong number in c

Code 4:

1.

**C program to print Armstrong numbers from 1 to 500**
2.

**C program for finding Armstrong numbers**
#include<stdio.h>

int main(){

int num,r,sum,temp;

for(num=1;num<=500;num++){

temp=num;

sum
= 0;

while(temp!=0){

r=temp%10;

temp=temp/10;

sum=sum+(r*r*r);

}

if(sum==num)

printf("%d
",num);

}

return 0;

}

Output:

1 153 370 371 407

**Definition of Armstrong number or what is an Armstrong number:**

**Definition according to c programming point of view:**

##
Those numbers which sum of the cube of its digits is equal to that number
are known as Armstrong numbers. For example 153 since 1^3 + 5^3 + 3^3 = 1+ 125
+ 9 =153

##
Other Armstrong
numbers: 370,371,407 etc.

##
In general definition:

##
Those numbers which sum of its digits to power of number of its digits is
equal to that number are known as Armstrong numbers.

##
Example 1: 153

##
Total digits in 153
is 3

##
And 1^3 + 5^3 + 3^3 =
1 + 125 + 27 = 153

Example 2: 1634

Total digits in 1634 is 4

And 1^4 + 6^4 + 3^4 +4^4 = 1 + 1296 + 81 + 64 =1634

Examples of Armstrong numbers: 1, 2, 3, 4, 5, 6, 7, 8, 9, 153, 370, 371, 407, 1634,
8208, 9474, 54748, 92727, 93084, 548834, 1741725

18. Write a c program which passes structure to function.

this will get you only 3 digit armstrong nos..

ReplyDeleteyahh!! 1-9 all r armstrong but it won't show it

Deletelets work out this with example

ReplyDeletetake num = 153

while 153!=0 satisfies

r = 153%10 = 3

num = 153/10 = 15

sum=0+(3*3*3) = 27

now num = 15

15!=0

r=15%10=5

num=15/10=1

sum = 27+(5*5*5)=152

now num=1

1!=0

r=1%10=1

num=1/10=0

sum = 152+1=153

so now the condition sum==temp or num satisfies

nice explanation yaar...thanx alot

Deletethanks

DeleteI have written this code for any no. of digits. It works. I have used above code. Need Help. Help me reduce no of lines as well as no of variables. you can reply on arpann72@gmail.com

ReplyDelete#include

void main()

{

int num,exp=1,rem,sum=0;

int i,temp,temp2,count=0,j;

scanf("%d",&num);

temp=num;

while(num/exp>0)

{

count=count+1;

exp*=10;

}

j=count;

while(j)

{

temp2=1;

rem=num%10;

num=num/10;

for(i=0;i<count;i++)

{

temp2*=rem;

}

sum+=temp2;

exp*=10;

j--;

}

if(sum==temp)

printf("\nThe number %d is an armstrong number",temp);

else

printf("\nThe number %d is not an armstrong number",temp);

}

Armstrong checking for any no

ReplyDelete#include

int main(){

int num,r,s,sum=0,temp,c=0;

printf("\nEnter a number:-");

scanf("%d",&num);

temp=num;

while(num!=0){

r=num%10;

num=num/10;

c++;

}

printf("\nno of digits:\n%d",c);

num=temp;

printf("\nno after assignment :\n%d",num);

while(num!=0){

s=num%10;

num=num/10;

sum=sum+power(s,c);

}

printf("\nsum is\n%d",sum);

if(sum==temp)

printf("\nThe number %d is an armstrong number",temp);

else

printf("\nThe number %d is not an armstrong number",temp);

getch();

return 0;

}

int power(int a,int b){

int i=1,mul=1;

while(i<=b){

mul*=a;

i++;

}

return mul;

}

/*the below program holds good for any no. of digits*/

ReplyDelete#include

#include

int main()

{

int m,t,i=1,s=0,n,r,j=1;

printf("enter the no: ");

scanf("%d", &n);

m=t=n;

while(j!=0)

{

r=n%10;

if(n<10)

{

break;

}

n=n/10;

j++;

}

printf("no of digits=%d\n",j);

while(i<=j)

{

r=m%10;

m=m/10;

s=s+pow(r,j);

i++;

}

printf("sum=%d\n",s);

if(s==t)

{

printf("valid");

}

else

{

printf("invalid");

}

getch();

return 0;

}

in the above program directives are stdio.h and math.h

ReplyDeletehow it works for 407......

ReplyDelete4*4*4=64

Delete7*7*7=343

343+64=407

merging 2 1-d arrays into 3rd array

ReplyDeletehow to find armstrong numbers between 1 and 1000 using only while?

ReplyDeleteThis comment has been removed by the author.

Deleteint i=1,temp,s;

Deletewhile(i<=1000)

{

temp=i;

s=0

i++;

while(temp!=0)

{

r=temp%10;

temp=temp/10;

s=s+temp;

}

if(s==i)

printf("%d",i);

}

return 0;

}

is it for amstrong numbers??? or for perfect numbers...??

Deleteethilum bedam njana

ReplyDeleteGuys can u help me out knowing why "temp" is used in this program???

ReplyDeletebecause by using temp or any another variable we can get the single value.

Deletefor example:

153

step 1 step 2 step 3

153%10=3 15%10=5 1%10=1

153/10=15 15/10=1 1/10=0

0+(3*3*3)=27 27+(5*5*5)=152 152+(1*1*1)=153

you can visit www.codecast.org for more codes,can register and upload there

ReplyDeleteThere is a rail road to different towns from one town. It is considered that the rail road is a one way because of budgetary issues. If there is city A and it has cities B and C cities connected by rail roads, it is not mandatory that A has direct rail road to both B and C. The route to C from A can be A to B and then B to C. The above scenario is depicted as a graph. The nodes are the towns and edges are the distances between them. The input given will be a graph and also the route to towns. The output must be the total rail road distance between the towns and if no route exists, it must say 'No Route exists'.

ReplyDeletePLEASE SEND ME A C PROGRAMME FOR THIS QUESTION. PLEASE ITS URGENT.

There is a mistake in the explanation of the Armstrong section: its 3^3=27 not 9 (the first part of the explanation)

ReplyDeleteA correction on this part. Its seems that if the Armstrong num. is anything other than three, then this wont work (except for 1). I think the number of r's has to be adjusted to how many digits the natural number inputted has. the way to do this is to create a loop to see how many times is the number entered divisible by 10 at the beginning of the program, and then multiply by that many r's everytime. Please notify me if I am wrong. Thanks

ReplyDeletegood , but small mist.

ReplyDeletego to Definition. 1^3 + 5^3 + 3^3 = 1+ 125 + 27 =153

thats it.

i have searched in net that there are only 4 three digited amstrong nos

ReplyDelete153,370,371,407

but if 153 is amstrong then 351 and 531 are also amstrong numbers

if u find answer for this plz mail@mani sai

@mani4sai@gmail.com

how can 531 be an amstrong no,

ReplyDelete3^3+5^3+1^3=27+125+1=153 not 351 so 351 cant be an amstrong no.An amstrong no is sum of cubes of the number is the no itself.

same goes with 531.

above all code implemented by admin is wrong

ReplyDelete#include

ReplyDelete#include

int main(void)

{

int sum,term,policytype;

float bonus;

printf("enter the sum \n");

scanf("%d",&sum);

printf("enter 1 for Endownment \n 2 for Money Bank \n 3 for Term Assurance \n");

scanf("%d",&policytype);

switch(policytype)

{

case 1: printf("enter the term: \n");

scanf("%d",&term);

if(term>=25)

{

bonus=((float)sum/1000)*60;

printf("the bonus rate per thousand is %f \n",bonus);

}

else if((term>=20)&&(term<25))

{

bonus=((float)sum/1000)*55;

printf("the bonus rate per thousand is %f \n",bonus);

}

else if((term>=10)&&(term<20))

{

bonus=((float)sum/1000)*50;

printf("the bonus rate per thousand is %f \n",bonus);

}

else if(term<10)

{

bonus=((float)sum/1000)*45;

printf("the bonus rate per thousand is %f \n",bonus);

}

break;

case 2:printf("enter the term: \n");

scanf("%d",&term);

if(term>=25)

{

bonus=((float)sum/1000)*55;

printf("the bonus rate per thousand is %f \n",bonus);

}

else if((term>=20)&&(term<25))

{

bonus=((float)sum/1000)*50;

printf("the bonus rate per thousand is %f \n",bonus);

}

else if((term>=10)&&(term<20))

{

bonus=((float)sum/1000)*45;

printf("the bonus rate per thousand is %f \n",bonus);

}

break;

case 3:printf("the bonus is not applicable for this policy type \n");

break;

default: printf("please enter valid policy type \n");

break;

}

getch();

return 0;

}

/* */

ReplyDelete#include //directive for input output

#include //directive for displaying output

#include

int compound_interest(float p,float t, float r,float n);

void main()

{

float comp_intrest,principal_amt,rate,time,number_interest;

float result;

printf("enter the amount, time, rate and number\n");

scanf("%f%f%f%f",&principal_amt,&time,&rate,&number_interest);

result = compound_interest(principal_amt,time,rate,number_interest);

printf("the compound intreset is %f\n",result);

getch();

}

int compound_interest(float p,float t, float r,float n)

{

float amount, ci,temp=1,nt;

int i;

nt=n*t;

for(i=0;i<nt;i++)

{

temp=temp*(1+r/n);

}

amount=p*temp;

ci=amount-p;

return ci;

}

nice explnation

ReplyDelete