Showing posts with label Our Mini-Developments. Show all posts
Showing posts with label Our Mini-Developments. Show all posts

Wednesday, February 8, 2012

A Mini Number Guessing Game using C++ ...

#include<iostream.h>
#include<conio.h>
main()
{
clrscr();
cout<<"Please Think a  Number between 0 to 100 in your mind and press enter : ";
getch();
char ug;
int cg=50,high=100,low=0;
clrscr();
while(ug!='=')
{
cout<<"What about : "<<cg;
cin>>ug;
switch(ug)
{
case '<':
{
high=cg-1;
cg=(high+low)/2;
break;
}
case '>':
{
low=cg+1;
cg=(high+low)/2;
break;
}
case '=':
{
cout<<"Your Number is :"<<cg;
break;
}
default:
{
cout<<"Wrong Choice";
}
}
}
getch();
}

Sunday, January 29, 2012

C ++ Program to Reverse a String Word By Word . . .

Hi Buddies , this is a small program that helps to reverse a given string word by word .

Example , If u give input as "I am studying in USA" means it will return output as "I ma gniyduts ni ASU"




int main()
{
    int i,j=0,len,k=0,m=0;
   char text[30];
   clrscr();
   gets(text);
    char temp[30],temp2[5];
    len=strlen(text);
    text[len+1]=' ';
    for(i=0;i<len;i++)
    {
 if(text[i]==' ')
 {
     i++;
 }
 else
 {
     while(text[i]!=' ')
     {
      temp[j]=text[i];
      i++;
      k++;
      j++;
     }
     for(m=k-1;m>=0;m--)
     {
     printf("%c",temp[m]);
     }
     cout<<" ";
     j=0;
     k=0;
 }
    }
    getch();
}