Thursday 21 February 2013

Swapping without third variable

| |
0 comments

#include<iostream>
using namespace std;
int main()
{
int a,b;

cout<<"Enter the two numbers ";
cin>>a>>b;
a=a+b;
b=a-b;
a=a-b;
cout<<"Now a="<<a<<endl<<"Now b="<<b;
system ("pause");
return 0;
}
 
Read More

Compute the sum of Cos(X) Series

| |
0 comments

#include<iostream.h>
#include<conio.h>
#include<math.h>
int main()
{ float x,t,sum;
int i,n=20;
cout<<"Input X : \n";
cin>>x;
x=x*3.1412/180;
t=t+1;
sum=1;
for(i=1;i<=n;++i)
{ t=t*pow((double)(-1),(double)(2*i-1))*x*x/(2*i*(2*i-1));
sum +=t;
}
cout<<"cos(X) ="<<sum<<"\n";
system ("pause");
return 0;
}
 
Read More

WAP to print Pascals Triangle

| |
0 comments

#include<iostream>
#include<math.h>
using namespace std;

int main()
{
    int i,j,k,l,n,m;
    cout<<"Enter the number of rows :""\n";
    cin>>n;
   
    for(i=0;i<n;i++)
    {
                    cout<<"\n";
                    for(k=(n-i);k>0;k--)
                    { cout<<" ";}
                    if(i==0)
                    {
                            cout<<"*";
                            continue;}
                    if(i==(n-1))
                    {
                            for(j=0;j<((2*n)-1);j++)
                            { cout<<"*";}
                           
                    break;
                    }
                    cout<<"*";
                   
                    for(l=fabs(2*i-1);l>0;l--)
                    {
                                              cout<<" ";
                                              }
                    cout<<"*";
                    }
                   
                    cout<<"\n";
    system ("pause");
    return 0;
}
                   
 
Read More
Related Posts Plugin for WordPress, Blogger...
Powered by Blogger.