Thursday, October 24, 2013

FOLLOWING SERIES

/*WAP TO ADD 1st SEVEN TERMS OF THE FOLLOWING SERIES: (1/1!)+(2/2!)+.......+(7/7!) [using FOR loop]*/


#include<stdio.h>
#include<conio.h>
 void main()
 {
int i,j;
float fact;
float sum=0;

clrscr();
printf("\nGiven series -->\n\t\t");
printf("1/1! + 2/2! + 3/3! + 4/4! + 5/5 + 6/6! + 7/7!");
for(i=1;i<=7;i++)
{
fact=1;
for(j=1;j<=i;j++)
{
fact=fact*j;
}
sum=sum+i/fact;
}
printf("\n\n\nSum of the 1st seven terms of the given series= %f",sum);
getch();
 }

ARMSTRONG NO

/* WAP TO PRINT AND COUNT ARMSTRONG NO.S FROM 1 TO 1000.



#include<stdio.h>
#include<conio.h>
 void main()
 {
int num;
int n;
int d,sum;
int count=0;

clrscr();

printf("\nArmstrong no.s from 1 to 1000 -->\n\n\t\t");
num=1;
while(num<1000)
{
n=num;
sum=0;
while(n>0)
{
d=n%10;
sum+=d*d*d;
n=n/10;
}
if(num==sum)
{
printf("%d\t",num);
count++;
}
num++;
}
printf("\n\nTotal no. of Armstrong no.s from 1 to 1000 = %d",count);
getch();
 }