Followers

Friday, January 6, 2012

REVERSING A STRING-USING ANOTHER STRING


#include<iostream.h>
#include<conio.h>
#include<string.h>
#include<stdio.h>

void main()
{
  char strng[25], rev[25];
  int len;
  cout<<"enter a string : ";
  gets(strng);
  len=strlen(strng);
  for(int i=0 ; i<len ; i++)
  {
    rev[i]=strng[len-1-i];
  }
  cout<<"\n\n reverse :\n";
  puts(rev);

  getch();
}
.................................................................
OUTPUT :(click to enlarge the image)

SUM OF A RANGE

#include<iostream.h>
#include<conio.h>

void main()
{
 int n, m, a=0, b=0;
 cout<<"Enter the starting number :";
 cin>>n;
 cout<<"Enter the last number :";
 cin>>m;
 a=n;
 int i=0;
 do
 {
  a=n+i;
  b=b+a;
  i++;
 }while(i<=m-n);
 cout<<"Sum of the range ="<<b;
 getch();
}
.................................................................
OUTPUT: (click to enlarge the image)

Thursday, January 5, 2012

CASE CONVERSION IN A STRING - USING LOGIC

#include<iostream.h>
#include<conio.h>
#include<string.h>

char strng[50];
int len, n;

void cmpltcnvrsion(char strng[50])
{
  for(int i=0 ; i<len ; i++)
  {
    if((97<=int(strng[i]))&&(int(strng[i])<=122))
      cout<<char(int(strng[i])-32);

    else if((65<=int(strng[i]))&&(int(strng[i])<=90))
      cout<<char(int(strng[i])+32);

    else
      cout<<strng[i];
  }
}

void capital(char strng[50])
{
  for(int i=0 ; i<len ; i++)
  {
    if((97<=int(strng[i]))&&(int(strng[i])<=122))
      cout<<char(int(strng[i])-32);
    else
      cout<<strng[i];
  }
}

void small(char strng[50])
{
  for(int i=0 ; i<len ; i++)
  {
    if((65<=int(strng[i]))&&(int(strng[i])<=90))
      cout<<char(int(strng[i])+32);

    else
      cout<<strng[i];
  }

}

void main()
{
  clrscr();
  cout<<"Enter a string :\n";
  cin.getline(strng,50);
  len=strlen(strng);
  cout<<"\n\nChoose the type of conversion : \n 1>Complete conversion \n 2>ALL CAPITAL \n 3>all small \nEnter your choice : ";
  cin>>n;
  switch(n)
  {
    case 1  : cmpltcnvrsion(strng);
    break;
    case 2  : capital(strng);
    break;
    case 3  : small(strng);
    break;
  }
  getch();
}
.................................................................
OUTPUT: (click to enlarge the image)