Tuesday, 31 October 2017

Write a program which reads a set of integers into an integer array and then prints "YES"if all of them are same otherwise print "NO".

#include<stdio.h>
int main()
{
int a[10],M=0,i,n;
printf("enter a value for n\n");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("enter number");
  scanf("%d",&a[i]);  
    }
     for(i=1;i<n;i++)
      {
      if(a[0]==a[i])
      {
   
          M++;  
 }
      }
      i = i-1;
      if(i==M)
  printf("YES\n");
  else 
  printf("No\n");   
     return 0;
}

Tuesday, 16 September 2014

write a c+program to find the sum of odd numbers and even numbers from 1 to N.

#include<iostream>
using namespace std;
int main()
{   int n;
    int sum=0,sum1=0;
cout<<"enter the number of element"<<endl;
cin>>n;
for(int i=0;i<=n;i++)
{
if(i%2==0)
{

sum=sum+i;

}


}
cout<<"sum of even number is = "<<sum<<endl;
for(int i=0;i<=n;i++)
{
if(i%2!=0)
{

sum1=sum1+i;

}


}
cout<<"sum of odd number is = "<<sum1;
}

write a c++ program to find the GCD and LCM of two integers output the resuls along with the given integers.use Euclid's distance.

#include<iostream>
using namespace std;
int main()
{   int num1,num2;
    int m1,m2,r;
cout<<"enter two numbers"<<endl;
cin>>num1>>num2;
if(num1>num2)
{
  m1=num1;
  m2=num2;
}
else
{ m1=num2;
 m2=num1;

}
while(r!=0)
{
r=m1%m2;
m1=m2;
m2=r;
}
cout<<"result of gcd of two number is "<<m1<<endl;
int lcm= (num1*num2)/m1;
cout<<"result of lcm of two number is "<<lcm;
}

write a c++ program to simulate a simple calculator to perform addition,substraction,multiplication and devision only on integer.

#include<iostream>
using namespace std;
int main()
{
char ch;
int a,b,result;
cout<<"enter two value "<<endl;
cin>>a>>b;
cout<<"enter the operator";
cin>>ch;

switch(ch)
{

      case '+':
              result=a+b;
              cout<<result;
              break;
      case '-':
            result=a-b;
            cout<<result;
            break;
      case '*':
              result=a*b;
            cout<<result;
            break;
      case '/':
            result=a/b;
            cout<<result;
            break;
      default:
        cout<<"enter correct operator";
        break;
}
}

Friday, 25 July 2014

program to generate the first 20 terms of the facobian series by using recursion .

#include<iostream>
using namespace std;
int facob(int );
int main()
{
int i;
for(i=1;i<=20;i++)
cout<<facob(i)<<" ";
}

int facob(int i)
{
if(i==1)
return(0);
else if(i==2)
return(1);
else
return(facob(i-2)+facob(i-1));
}

program to display the multiplication table of a number.it uses recursion.

#include<iostream>
#include<iomanip>
#include<iostream>
using namespace std;
int product(int k, int i);

int main()
{
int i, k;
cout<<"enter any integer number ";
cin>>k;
for(i=1;i<=10;i++)
cout<<setw(4)<<k<<"*"<<setw(3)<<i<<"="<<setw(4)<<product(k,i)<<endl;
}

//function to evaluate the factorial
int product(int k,int i)
{
if(i==1)
 return(k);
else
 return(product(k,i-1)+k);
}

write a program to read an integer number and evaluate its factorial by recursion.

#include<iostream>
using namespace std;
float factorial(int);

int main()
{
int k;
cout<<"enter the number ";
cin>>k;
cout<<"factorial of"<<k<<"is"<<factorial(k);
}

//function to evaluate the factorial
float factorial(int n)
{
if(n==0)
 return(1);
else
 return(n*factorial(n-1));
}

Write a program which reads a set of integers into an integer array and then prints "YES"if all of them are same otherwise print "NO".

#include<stdio.h> int main() { int a[10],M=0,i,n; printf("enter a value for n\n"); scanf("%d",&n); fo...