Friday, 18 November 2016

Another method to print prime nos. in a given range

#include<conio.h>
#include<iostream.h>

void check_prime (int x,int y);
void main()
{ clrscr();
  int x,y,z;
  cout<<"Enter the range below" ;
  cout<<"From ";
  cin>>x;
  cout<<"To ";
  cin>>y;
  check_prime(x,y);
  getch();
}

void check_prime(int x,int y)
{ int a,b,c,d;
  for(int i=x;i<=y;i++)
     { int ret=0;
       for (int j=1;j<=i;j++)
  { c=i%j;
    if (c==0)
{ ret++;
}
  }
       if (ret==2)
 { cout<<i<<" is a prime no. \n";
 }
     }
getch();
}

Tuesday, 15 November 2016

Q1. 15/11/2016

#include<conio.h>
#include<iostream.h>

int check_prime(int x);
void main()

{ clrscr();
  int a,b,z;
  cout<<"Enter the range below \n";
  cout<<"From ";
  cin>>a;
  cout<<"To ";
  cin>>b;
  for (int i=a;i<=b;i++)
      { z=check_prime(i);
if (z==1)
  { cout<<i<<" is a prime no. \n ";
  }
      }
  getch();
}

int check_prime(int x)

{ int z,w=0,y=0;

  for (int i=1;i<=x;i++)
      { z=x%i;
if (z==0)
  {w++;
  }
      }
  if (w==2)
     { y=1;
     }
  return(y);
}

Q. WAP to print prime nos. in a given range

#include<conio.h>
#include<iostream.h>

void main()

{ clrscr();
  float a,b,z;
  cout<<"Enter the range below \n";
  cout<<"From ";
  cin>>a;
  cout<<"To ";
  cin>>b;

  for (int i=a;i<=b;i++)
      { int ret=0;
for (int k=1;k<=i;k++)
   { z=i%k;
     if (z==0)
{ ret++;
}
   }
if (ret==2)
  { cout<<i<<" is a prime no. \n";
  }
      }
  getch();
}

Q2. 11/11/2016

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

float sum_of_series(float x);
void main()

{ clrscr();
  float x,y;
  cout<<"Enter the no. of terms ";
  cin>>x;
  y=sum_of_series(x);
  cout<<"Sum of "<<x<<" terms of series = "<<y;
  getch();
}

float sum_of_series(float x)

{ float z=1,sum=0;

  for(int i=1;i<=x;i++)
     { z=pow(i,i);
       sum=sum+z;
     }
  return(sum);
}

Q1. 11/11/2016

#include<conio.h>
#include<iostream.h>

float sum_of_series(float x);
void main()

{ clrscr();
  float x,y;
  cout<<"Enter no. of terms ";
  cin>>x;
  y=sum_of_series(x);
  cout<<"Sum of "<<x<<" terms of Series = "<<y;
  getch();
}

float sum_of_series(float x)

{ float sum=0;
  for (int i=1;i<=x;i++)
      { sum=sum+i;
      }

  return(sum);
}

Friday, 4 November 2016

Q. WAF to print Factorial of any entered no.

#include<conio.h>
#include<iostream.h>
float factorial(float x);
void main()
{ clrscr();
  float x,z;
  cout<<"Enter a no. ";
  cin>>x;
  z=factorial(x);
  cout<<"Factorial of "<<x<<" is "<<z;
  getch();
}
float factorial(float x)
{ float z=1;
  for (int i=x;i>=1;i--)
    { z=z*i;
    }
  return (z);
}

Q. WAF to find sum of 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);
  }

Q. WAF to calculate cube of any no.

#include<conio.h>
#include<iostream.h>
float cube_of(float a);
void main()
{
clrscr();
int x,y;
cout<<"Enter a no. ";
cin>>x;
y=cube_of(x);
cout<<"Cube of "<<x<<" = "<<y;
getch();
}
float cube_of(float a)
{
int c;
c=a*a*a;
return(c);
}

Q. WAF to print greatest and smallest among 3 nos.

#include<conio.h>
#include<iostream.h>
int which_is_great(int a,int b,int c);
int which_is_small(int d,int e,int f);
void main()
{
clrscr();
int w,x,y,z,s;
cout<<"Enter 3 nos. ";
cin>>w>>x>>y;
z=which_is_great(w,x,y);
s=which_is_small(w,x,y);
cout<<"Greatest no. = "<<z<<"\n";
cout<<"Smallest no. = "<<s;
getch();
}
int which_is_great(int a,int b,int c)
{
int d;
d=a>b?(a>c?a:c):(b>c?b:c);
return (d);
}
int which_is_small(int d,int e,int f)
{
int a;
a=d<e?(d<f?d:f):(e<f?e:f);
return(a);
}

Q. WAF to calculate average of 3 nos.

#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);
}

Thursday, 3 November 2016

Program to Calculate area of a Triangle using Fuction

#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);
}

Basic Implementation of Array as a Pointer

#include<iostream.h> #include<conio.h> void main() { clrscr();   int arr[5];   cout<<"Enter 5 nos. ";   f...