Tuesday, 15 November 2016

Program to find average of three no using function

#include<conio.h>
#include<iostream.h>
int avg(int a,int b,int c);
void main()
{
clrscr();
int w,x,y,z;
cout<<"Enter three nos. ";
cin>>w>>x>>y;
z=avg(w,x,y);
cout<<"Average = "<<z;
getch();
}
int avg(int a,int b,int c)
{
int z;
z=(a+b+c)/3;
return(z);
}

Program to find area of triangle using function

#include<conio.h>
#include<iostream.h>
float areaoftriangle(float b,float h);
void main()
{
clrscr();
float x,y,z;
cout<<"Enter base of the Triangle ";
cin>>x;
cout<<"Enter height of the Triangle ";
cin>>y;
z=areaoftriangle(x,y);
cout<<"Area of the Triangle = "<<z;
getch();
}
float areaoftriangle(float b,float h)
{
float ar;
ar=0.5*b*h;
return(ar);
}

Friday, 4 November 2016

Program to find area of triangle using functions

#include<conio.h>
#include<iostream.h>
float areaoftriangle(float b,float h);
void main()
{
clrscr();
float x,y,z;
cout<<"Enter base of the Triangle ";
cin>>x;
cout<<"Enter height of the Triangle ";
cin>>y;
z=areaoftriangle(x,y);
cout<<"Area of the Triangle = "<<z;
getch();
}
float areaoftriangle(float b,float h)
{
float ar;
ar=0.5*b*h;
return(ar);
}

Wap to find sum of digits in a given range

#include<iostream.h>
#include<conio.h>
float sum_of_digits(float a,float b);
void main()
{
clrscr();
int w,x,y;
cout<<"Enter the range below "<<"\n";
cout<<"From (included) ";
cin>>w;
cout<<"To (included) ";
cin>>x;
y=sum_of_digits(w,x);
cout<<"Sum of digits from "<<w<<" to "<<x<<" is "<<y;
getch();
}
 float sum_of_digits(float a,float b)
 {
  int sum=0;
  for (int i=a;i<=b;i++)
     { sum=sum+i;
     }
  return(sum);
  }

Wap to calculate average of three number

#include<conio.h>
#include<iostream.h>
int avg(int a,int b,int c);
void main()
{
clrscr();
int w,x,y,z;
cout<<"Enter three nos. ";
cin>>w>>x>>y;
z=avg(w,x,y);
cout<<"Average = "<<z;
getch();
}
int avg(int a,int b,int c)
{
int z;
z=(a+b+c)/3;
return(z);
}