Tuesday 19 February 2013

To display the roman numeral of given 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/

To count the number of occurences of characters in a sentence



#include<iostream>
#include<conio.h>
#include<cstring>
#include<string>
using namespace std;
int main()
{string a;
cout<<"enter some text :\n\n";
getline(cin,a);

int l=a.length(),c=1,j,k,i,m;    //c for counting the number of occourences which is stored in freq
int freq[l];
for(j=0;j<l;j++)
   {freq[j]=c;
      for( k=j+1;k<l;k++)
       {   if(a[j]==a[k])              //a[j]  is compared with all of the remaining of characters, if
            {freq[j]=++c;              //it is equal to any of the character , count of freq[j]
            for( m=k;m<l-1;m++)   //corresponding to a[j] is increased.a[k] equal to a[j] is            
            a[m]=a[m+1];               // replaced by a[k+1].similarly a[k+1] by a[k+2].... so on
            k--;l--;
            }
        }c=1;
   }

 cout<<"character\tFrequency\n";
 for(i=0;i<l;i++)
 cout<<a[i]<<"\t\t"<<freq[i]<<endl;


 getch();
 return 0;
}

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 to hexadecimal number(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;
}

convert decimal number to hexadecimal number(Basic method)

#include<iostream>
#include<math.h>
using namespace std;
int main()
{ int dec,i,maxi,rem,q,s;
cout<<"decimal number please.....\n";
cin>>dec;rem=dec;
for(i=1;dec>pow(16,i);i++);
--i;                        //q=quotient represents the hexdecimal equivalent
for(;i>=0;i--)
{ s=pow(16,i);
q=rem/s;
if(q>=10)
    { ;cout<<(char)(q+55);}   //55 added  to give equivalent ASCII value
else
    cout<<q;
   rem=rem % s;
}
return 0;
}

Friday 1 February 2013

Finy any day of any century Devcalendar

#include<iostream>
#include<conio.h>
using namespace std;
int main()
{
    long  int y,i,count=0,m,d,j;
      cout<<"Enter day-month-year.\n";
      cin>>d;cout<<"/";cin>>m;cout<<"/";cin>>y;
                  
       for (i=1;i<y;i++)
       {
            if ((i%400==0)||((i%4==0)&&(i%100!=0)))    //checking  leap year
            count= count+2;         
            else
            count=count+1;
       }
               
             for(j=1;j<m;j++)                 //checking  month
             {switch(j)
                     {case 1:case 3:case 5: case 7: case 8: case 10: case 12: count=count+31;break;  
                     case 2:if ((i%400==0)||((i%4==0)&&(i%100!=0))) count=count+29; else count=count+28;break;
                     default :count=count+30;
                     }
             }
                  count=count+d-1;
                  switch (count%7)
                  {
                  case 0:cout<<"Mon\n";break;
                  case 1:cout<<"Tues\n";break;
                  case 2:cout<<"Wed\n";break;
                  case 3:cout<<"Thu\n";break;
                  case 4:cout<<"Fri\n";break;
                  case 5:cout<<"Sat\n";break;
                  case 6:cout<<"Sun\n";break;
                 
                  }
                 
                  getch();
      }