Showing posts with label Mathematical. Show all posts
Showing posts with label Mathematical. Show all posts

write a c program to swap three variable a,b&c using forth variable

/*write a c program to swap three variable a,b&c using forth variable*/

#include<stdio.h>
#include<conio.h>

void main()
{
int a,b,c,d;
clrscr();
printf("enter value of a:");
scanf("%d",&a);
printf("enter value of b:");
scanf("%d",&b);
printf("enter value of c:");
scanf("%d",&c);
printf("\n values of variables a,b&c before swapping:\n\t%d %d %d",a,b,c);
d=a;
a=b;
b=c;
c=d;
printf("\n values of variables a,b&c after swapping:\n\t%d %d %d",a,b,c);
getch();
}

Wap to swap two values without using third variable

/*Wap to swap two values without using third variable*/

#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c;
clrscr();
printf("Enter 2 value");
scanf("%d %d",&a,&b);
printf("before swapping\na=%d\nb=%d\n",a,b);
a=a+b;
b=a-b;
a=a-b;
printf("after swapping \na=%d,\nb=%d",a,b);
getch();
}

write a menu driven program to add,subtract,multiply,divide two int digits

/*write a menu driven program to add,subtract,multiply,divide two int digits*/

#include<stdio.h>
#include<conio.h>

void main()

{
int n1,n2,c,value;
clrscr();
printf("enter two int:\n");
scanf("%d %d",&n1,&n2);
printf("\n1.Adition\n2.Subsraction\n3.Multification\n4.Division\n");
printf("\nEntre Your Choice:");
scanf("%d",&c);
switch(c)
{
case 1:
value=n1+n2;
printf("\nValue:%d",value);
break;
case 2:
value=n1-n2;
printf("\nValue:%d",value);
break;
case 3:
value=n1*n2;
printf("\nValue:%d",value);
break;
case 4:
value=n1/n2;
printf("\nValue:%d",value);
break;
default:
printf("\nWrong Choice");
break;
}
getch();
}

write a c programme to calculate area of triangle

/*write a c programme to calculate area of triangle*/
#include<stdio.h>
#include<conio.h>
void main()
{
	float b,l,area;
	clrscr();
	printf("enter the value of b:");
	scanf("%f",&b);
	printf("enter the value of l:");
	scanf("%f",&l);
	area=0.5*b*l;
	printf("area of triangle: %.2f",area);
	getch();

}

write a c program to add first 10 successive integer

/*write a c program to add first 10 successive integer*/

#include<stdio.h>
#include<conio.h>

void main()

{
 int x,n,i,ans=1;
 clrscr();
 printf("enter value of x:");
 scanf("%d",&x);
 printf("enter value of n:");
 scanf("%d",&n);
 for(i=1;i<=n;i++)
 {
  ans=ans+x;
 }
 printf("ans:%d",ans);
 getch();
}

write C program for area of circle

/*C program for area of circle*/


#include <stdio.h>
#define PI 3.141
int main()
{
  float r, a;
  printf("Radius: ");
  scanf("%f", &r);
  a = PI * r * r;
  printf("%f\n", a);
  return 0;
}

WAP to find hexadecimal conversion of a given deimal number

/*WAP to find hexadecimal conversion
of a given deimal number*/

#include<stdio.h>
#include<conio.h>
#include<math.h>

void main()

{
 long int n,i=0,k,j,s[16];
 clrscr();

 printf("Enter any Decimal Number:");
 scanf("%ld",&n);
 printf("\nHexadecimal\n");
        printf("\n\n%x\n\n",n);
  while(n!=0)
  {
   s[i]=n%16;
   printf("%d:::",s[i]);
   n=n/16;
   printf("%d...",n);
   i++;
  }
  printf("\nHexadecimal Conversion:");

  for(j=i-1;j>=0;j--)
  {
  if(s[j]<=9)
  printf("%ld",s[j]);

   else if(s[j]==10)
   printf("A");

  else if(s[j]==11)
  printf("B");

   else if(s[j]==12)
   printf("C");

  else if(s[j]==13)
  printf("D");

   else if(s[j]==14)
   printf("E");

  else if(s[j]==15)
  printf("F");
  }

 getch();
}

Wap to find octal conversion of a given deimal number

/*WAP to find octal conversion
of a given deimal number*/

#include<stdio.h>
#include<conio.h>
#include<math.h>

void main()

{
 long int n,a,b=0,i=0,k,j,s[16];
 clrscr();

 printf("Enter any Decimal Number:");
 scanf("%ld",&n);
 printf("Octal\n");
  while(n!=0)
  {
   a=n%8;
   n=n/8;
   b=b+a*pow(10,i);
   i++;
  }
  printf("\nOctal Conversion:%ld",b);
 
 getch();
}

Wap to find BINNARY number of any Decimal Number

#include<conio.h>
#include<stdio.h>
void main()
{

int num,r;
clrscr();

printf("\nEnter the number");
scanf("%d",&num);

 r=num%2;
 num=num/2;
 if(num==0)
 {
  printf("\nThe binary euivalent is %d",r);

 }
 else
 {
 binary(num);
 printf("%d",r);
 getch();
}

Wap to find Binnary Number of any Decimal Number using functions

#include<conio.h>
#include<stdio.h>
int binary(int);
void main()
{

int num;
clrscr();

printf("\nEnter the number");
scanf("%d",&num);

binary(num);

getch();

}

int binary(int num)
{
 int r;
 r=num%2;
 num=num/2;
 if(num==0)
 {
  printf("\nThe binary euivalent is %d",r);

 }
 else
 {
 binary(num);
 printf("%d",r);
 return(r);
}
}