Tuesday, 19 February 2013

To display the roman numeral of user entered number

#include<iostream>
using namespace std;
int main()
{
    int n;
    cout<<"Enter number to display equivalent roman numeral\n";
    cin>>n;
            for (;n>=1000;n-=1000)
                cout<<"M";
            for (;n>=900;n-=900)
                cout<<"CM";
            for (;n>=500;n-=500)
                cout<<"D";
            for (;n>=400;n-=400)
                cout<<"CD";
            for (;n>=100;n-=100)
                cout<<"C";
            for (;n>=90;n-=90)
                cout<<"XC";
            for (;n>=50;n-=50)
                 cout<<"L";
            for (;n>=40;n-=40)
                cout<<"XL";
            for (;n>=10;n-=10)
                cout<<"X";
            for (;n>=9;n-=9)
                cout<<"IX";
            for (;n>=5;n-=5)
                cout<<"V";
            for (;n>=4;n-=4)
                cout<<"IV";
            for (;n>=1;n-=1)
                cout<<"I";




    return 0;
}




Do visit
http://facebook.com/csedevgroup
http://devendradora.blogspot.in/
http://computersciencedora.blogspot.in/

ragged matrix

ragged matrix is that which has unequal number of elements in the each row

#include<iostream>
using namespace std;
#include<conio.h>
int main()
{int r,j,i,pos[]={2,1,3,5,7,4,6,9,10,8,11,13,12,15,14};
cout<<"enter how many rows u want to display of a ragged matrix";
cin>>r;int a[r][15];
cout<<"Enter the elements\n";
int s=1,n;
for(i=0;i<r;i++)
  { for(j=0;j<pos[i];j++)
      cin>>a[i][j];
  }
cout<<"\n\n\n\n";
for(i=0;i<r;i++)
  { for(j=0;j<pos[i];j++)
    cout<<a[i][j]<<"  ";
   cout<<endl;
  }
       getch();
}

convert decimal number to hexadecimal(using arrays)

#include<iostream>
#include<math.h>
using namespace std;
int main()
{ int dec,i=0,store[20];
cout<<"decimal number please.....\n";
cin>>dec;
while(dec!=0)
{  store[i]=dec%16;   //remainder represents hexadecimal equivalent
   dec=dec/16;
   i++;
}
for(;i>=0;i--)
{if(store[i]>=10)
    cout<<(char)(store[i]+55);   //55 added  to give equivalent ASCII value
     else
    cout<<store[i];
}
return 0;
}