Write a program to print out all armstrong numbers between 1 and 500

ilsamaryum 7,519 views 2 slides Nov 20, 2015
Slide 1
Slide 1 of 2
Slide 1
1
Slide 2
2

About This Presentation

Armstrong numbers


Slide Content

Write a program to print out all Armstrong numbers between 1 and 500. If sum of cubes of each digit of the
number is equal to the number itself, then the number is called an Armstrong number. For example, 153 = ( 1
* 1 * 1 ) + ( 5 * 5 * 5 ) + ( 3 * 3 * 3 )
#include <stdio.h>
#include <conio.h>
void main()
{
int i=1,a,b,c;
printf("ARMSTRONG NUMBERS BETWEEN 1 to 500 ARE \n");
while (i<=500)
{
a=i% 10; /*Extract Last Digit */
b=i% 100;
b=(b-a)/10; /*Extract First Digit */
c=i/100;/*Extract first Digit*/
if ((a*a*a)+(b*b*b)+(c*c*c)==i)
printf("% d\n",i);
i++;
}
getch();
}

Write a program to calculate overtime pay of 10 employees. Overtime is paid at the rate of Rs. 12.00 per hour
for every hour worked above 40 hours. Assume that employees do not work for fractional part of an hour.

Using for loop
#include<stdio.h>
#include<conio.h>
main()
{
int overtime, pay;
for(int a=1; a<=10; a++)
{
printf(“Please enter Overtime of % d ”,a );
scanf(“% d”, &overtime);
pay= 12*overtime;
printf(“His overtime pay is % d ”,pay);
}
getch();
}

Write a program to find the factorial value of any number entered through the keyboard.

#include<conio.h>
#include<stdio.h>
void main(void)
{
int a, num, fact=1;
printf(“Please type a number”);
scanf(“% d”, &num);

for(a=1; a<=num; a++)
{
fact=fact*a;
}
printf(“Factorial is % d”, fact);

getch();
}

Two numbers are entered through the keyboard. Write a program to find the value of one number raised to
the power of another.
#include <stdio.h>
#include <conio.h>
void main(void)
{
int num,power,ans wer=1;
printf(“Enter number and its power”);
scanf(" % d% d",&num, &power);
for(int i=1;i<=power;i++)
answer=answer*num;
printf("result is.. % d",answer);
getch();
}

Write a program to print all the ASCII values and their equivalent characters using a while loop. The ASCII
values vary from 0 to 255.
#include <stdio.h>
#include <conio.h>
void main(void)
{
Tags