You are on page 1of 2

INTRODUCTION TO PROGRAMMING

TE51 A
Question 1.
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 )
SOLUTION
**************************************
** ** ************************* ** ** ***
* Programming Assignment :2 *
* Introduction to Programming
* Programmer: CAPT ADEEL
* Due Date: WED 3 DEC 2014. *
***** ** ** ** ******* ** ** ** ** ** ******
#include <iostream.h>
#include <conio.h>
void main()
{
int number, sum = 0, temp, remainder;
cout<<"Enter an integer\n";
cin>> number;
temp = number;
while( temp != 0 )
{
remainder = temp%10;
sum = sum + remainder*remainder*remainder;
temp = temp/10;
}
if ( number == sum )
cout<<"Entered number is an armstrong number.\n";
else
cout<<"Entered number is not an armstrong number.\n";
getch();
}
Question 2.
Write a program to compute sinx for given x. The user should supply x and a
positive integer n. We compute the sine of x using the series and the computation
should use all terms in the series up throughthe term involving x n
sin x = x - x3/3! + x5/5! - x7/7! + x9/9! ........
SOLUTION

**************************************
** ** ************************* ** ** ***
* Programming Assignment :2 *
* Introduction to Programming
* Programmer: CAPT ADEEL
* Due Date: WED 3 DEC 2014. *
***** ** ** ** ******* ** ** ** ** ** ******
#include <iostream.h>
#include <conio.h>
void main()
{
int i,j,n,fact,sign=-1;
float x, p=1,sum=0;
cout<<"Enter the value of x : ";
cin>>x;
cout<<"Enter the value of n : ";
cin>>n;
while(i<=n)
{
fact=1;
while(j<=i)
{
p=p*x;
fact=fact*j;
j++;
}
sign=-1*sign;
sum+=sign*p/fact;
i+=2;
}
cout<<"sin "<<x<<"="<<sum;
getch();
}

You might also like