Fahrenheit To Celsius
Celsius=(Fahrenheit-32.0)/1.8
C=(F-32)/1.8
(5/9)*(F-32)
Celsius To Fahrenheit
C*(9/5)+32
Area of Triangle= ½ lb => 0.5*l*b
Area of Circle = 3.14*r*r
Area of Rectangle = l*b
Area of Square = a*a
Circumference of rectangle = 2*(l*b)
Circumference of Circle = 2*3.14*r
Circumference of Triangle = l+b+sqrt(l*l+b*b)
Thursday, August 27, 2009
E=1+1/1!+1/2!+1/3!+.. .. .. .. .
main()
{
float e=1;
int n=5,i;
int fact(int);
for(i=1;i<=n;i++)
e=e+1/fact(i);
printf("%f",e)
}
int fact(int n)
{
int i,f=1;
for(i=1;i<=n;i++)
f=f*i;
return(f);
}
e^x =1+x/1! + x(square)/2!+ x(cube)/3! +.. .. .. .. ..
main()
{
float e=0;
int n=5,i,x=2;
int fact(int);
for(i=1;i<=n;i++)
e=e+Math.Pow(x,i)/fact(i);//or use Math in #include
printf("%f",e)
}
int fact(int n)
{
int i,f=1;
for(i=1;i<=n;i++)
f=f*i;
return(f);
}
{
float e=0;
int n=5,i,x=2;
int fact(int);
for(i=1;i<=n;i++)
e=e+Math.Pow(x,i)/fact(i);//or use Math in #include
printf("%f",e)
}
int fact(int n)
{
int i,f=1;
for(i=1;i<=n;i++)
f=f*i;
return(f);
}
Pascal Triangle
Void main()
{
int n = 5,i,j;
for (i=1;i<=n;i++)
{
printf("\n*\n");
for (j = 1; j <= i * 2; j++)
printf("*");
(or)
/*
for (j = 1; j <= i; j++)
printf("**");
*/
}
}
Output
*
**
*
****
*
*******
Find Number of Occurance Characters
#include
#include
#include
void main()
{
int i=0,len=0,temp=0,count=0,temp1=0;
char a[25],ch,s,con='\0';
clrscr();
printf("\n\t Enter the name: ");
scanf("%s",a);
len=strlen(a);
printf("\n\t The length of the given name is: %d\n",len);
do
{
count=0;
printf("\n\t Enter the character to find : ");
s=getchar();
for(i=0;i {
if(s==a[i])
count++;
}
printf("\n\t Occurance is : %d",count);
getch();
printf("\n\t Do you want to find the occurance of characters (Y/y) : ");
con=getchar();
getch();
}while(con=='y'con=='Y');
}
/*
(OR)
printf("\n\t Enter the name: ");
ch=getchar();
a[len]=ch;
while(ch!='\n')
{
len++;
ch=getchar();
printf("\n%c",ch);
a[len]=ch;
}
printf("\n\t The length of the given name is: %d\n",len);
temp1=temp=len;
while(temp!=-1)
{
printf("%c",a[temp]);
temp--;
}
do
{
count=0;
printf("\n\t Enter the character to find : ");
s=getchar();
while(temp1!=0)
{
printf("%c",a[temp1]);
if(s==a[temp1-1])
{
count++;
temp1--;
}
else
temp1--;
}
printf("\n\t Occurance is : %d",count);
getch();
printf("\n\t Do you want to find the occurance of characters (Y/y) : ");
con=getchar();
getch();
}while(con=='y'con=='Y');
*/
Output
Enter the name: haiiii
The length of the given name is: 6
Enter the character to find :i
Occurance is : 4
Do you want to find the occurance of characters (Y/y) :n
#include
#include
void main()
{
int i=0,len=0,temp=0,count=0,temp1=0;
char a[25],ch,s,con='\0';
clrscr();
printf("\n\t Enter the name: ");
scanf("%s",a);
len=strlen(a);
printf("\n\t The length of the given name is: %d\n",len);
do
{
count=0;
printf("\n\t Enter the character to find : ");
s=getchar();
for(i=0;i
if(s==a[i])
count++;
}
printf("\n\t Occurance is : %d",count);
getch();
printf("\n\t Do you want to find the occurance of characters (Y/y) : ");
con=getchar();
getch();
}while(con=='y'con=='Y');
}
(OR)
printf("\n\t Enter the name: ");
ch=getchar();
a[len]=ch;
while(ch!='\n')
{
len++;
ch=getchar();
printf("\n%c",ch);
a[len]=ch;
}
printf("\n\t The length of the given name is: %d\n",len);
temp1=temp=len;
while(temp!=-1)
{
printf("%c",a[temp]);
temp--;
}
do
{
count=0;
printf("\n\t Enter the character to find : ");
s=getchar();
while(temp1!=0)
{
printf("%c",a[temp1]);
if(s==a[temp1-1])
{
count++;
temp1--;
}
else
temp1--;
}
printf("\n\t Occurance is : %d",count);
getch();
printf("\n\t Do you want to find the occurance of characters (Y/y) : ");
con=getchar();
getch();
}while(con=='y'con=='Y');
*/
Output
Enter the name: haiiii
The length of the given name is: 6
Enter the character to find :i
Occurance is : 4
Do you want to find the occurance of characters (Y/y) :n
Swapping of Two Number
#include
#include
void main()
{
int a=10,b=20,t;
clrscr();
printf("\nGiven Value A = %d and B = %d",a,b);
a=a+b;
b=a-b;
a=a-b;
printf("\nSwap Value Without Using Temporary Variable A = %d and B = %d",a,b);
t=a;
a=b;
b=t;
printf("\nSwap Value Using Temporary Variable A = %d and B = %d",a,b);
getch();
}
Output
Given Value A = 10 and B = 20
Swap Value Without Using Temporary Variable A = 20 and B = 10
Swap Value Using Temporary Variable A = 10 and B = 20
#include
void main()
{
int a=10,b=20,t;
clrscr();
printf("\nGiven Value A = %d and B = %d",a,b);
a=a+b;
b=a-b;
a=a-b;
printf("\nSwap Value Without Using Temporary Variable A = %d and B = %d",a,b);
t=a;
a=b;
b=t;
printf("\nSwap Value Using Temporary Variable A = %d and B = %d",a,b);
getch();
}
Output
Given Value A = 10 and B = 20
Swap Value Without Using Temporary Variable A = 20 and B = 10
Swap Value Using Temporary Variable A = 10 and B = 20
Sum of Series (/* (1/(2!))+(2/(3!))(3/(4!))(4/(5!))+....+(n/(n+1!)))
/* (1/(2!))+(2/(3!))(3/(4!))(4/(5!))+....+(n/(n+1!))*/
#include
#include
#include
void main()
{
int i,n;
float sum=0;
int factorial(int);/*Prototype*/
clrscr();
printf("Enter Value 'n' to Find Series(1/(2!))+(2/(3!))+(3/(4!))+...+(n/(n+1!)) : ");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
sum=sum+(i/factorial(i+1));
}
printf("\n\tSum is : %.2f",sum);
getch();
}
int factorial(int n)
{
int i,fact=1;
for(i=1;i<=n;i++)
fact=fact*i;
return(fact);
}
Output
Enter Value 'n' to Find Series(1/(2!))+(2/(3!))+(3/(4!))+...+(n/(n+1!)) : 3
Sum is :
#include
#include
#include
void main()
{
int i,n;
float sum=0;
int factorial(int);/*Prototype*/
clrscr();
printf("Enter Value 'n' to Find Series(1/(2!))+(2/(3!))+(3/(4!))+...+(n/(n+1!)) : ");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
sum=sum+(i/factorial(i+1));
}
printf("\n\tSum is : %.2f",sum);
getch();
}
int factorial(int n)
{
int i,fact=1;
for(i=1;i<=n;i++)
fact=fact*i;
return(fact);
}
Output
Enter Value 'n' to Find Series(1/(2!))+(2/(3!))+(3/(4!))+...+(n/(n+1!)) : 3
Sum is :
Subscribe to:
Posts (Atom)