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

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...