Friday, 20 January 2012

Swapping without using 3rd(temp) variable.........


#include<iostream.h>
#include<conio.h>
void main()
{

int a,b;
clrscr();
cout<<"ENTER TWO NUMBERS\n";
cin>>a>>b;
cout<<"a="<<a<<"\n"<<"b="<<b<<endl;
a=a+b;
b=a-b;
a=a-b;
cout<<"AFTER SWAPPING\n";
cout<<"a="<<a<<"\n"<<"b="<<b;
getch();
}

In a sorted array,find element whose value is equal to its index for eg:a[2]=2,a[5]=5 etc.......


#include<stdio.h>
#include<conio.h>
void main()
{
int i,n,a[100];
printf("\nENTER THE SIZE OF THE ARRAY\n");
scanf("%d",&n);
printf("ENTER THE ELEMENTS IN THE ARRAY\n");
for(i=0;i<n;i++)
scanf("%d",&a[i]);
for(i=0;i<n;i++)
{
if(a[i]==i)
printf("\n%d\t",a[i]);
}
getch();
}

C program to check whether a matrix is symmetric(ENIGMA) or not.......


#include<iostream.h>
#include<conio.h>
#include<process.h>
void main()
{
int mat[100][100];
clrscr();
int m,n,i,j;
cout<<"ENTER THE ROW N COLUMN VALUE\n";
cin>>m>>n;
cout<<"ENTER THE ELEMENTS ONE BY ONE\n";
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
cin>>mat[i][j];

}
}
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
cout<<"\t"<<mat[i][j]<<"\t";
}
cout<<"\n";
}
for(i=0;i<=m-2;i++)
{
for(j=i+1;j<=n-1;j++)
{
if(mat[i][j]!=mat[j][i])
{
cout<<"NOT ENIGMA\n";
}

else
{
cout<<
"ITS ENIGMA";
}
}
}

getch();
}

This program can CALULATE RUNRATE,CALCULATE REQUIRED RUNRATE PER OVER TO WIN,isn`t it cool plz run and comment


#include<iostream.h>
#include<conio.h>
int n,r,ch;
int tar,n1,r1;
float rr,o,rrr;
float runrate()
{
cout<<"ENTER THE NUMBER OF BALLS:\n";
cin>>r;
cout<<"ENTER THE RUNS\n";
cin>>n;
o=r/6;
rr=n/o;
return rr;
}
void main()
{

clrscr();
cout<<"\nPRESS->1:TO CALULATE RUNRATE\n2->TO CALCULATE REQUIRED RUNRATE PER OVER TO WIN\n";
cin>>ch;
switch(ch)
{
case 1:runrate();
      cout<<"RUN RATE="<<rr<<"/over"<<"\n";
case 2:cout<<"ENTER THE TARGET TO WIN:\n";
cin>>tar;
cout<<"ENTER THE CURRENT STATUS OF MATCH->\nRUNS AND OVERS:\n";
cin>>n>>r;
n1=tar-n;
r1=300-180;
if(r1<0)
cout<<"MATCH IS OVER NO REQUIRED RATE RATE\n";
else
rrr=n1/(r1/6);
cout<<"REQUIRED RUNRATE IS:\n"<<rrr;
}
getch();
}

Do u have habit of bunking the classes more want to calculate and maintain ur attendence run this code it a simple code........plz do comment on this.......

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

void main()
{
float att,tot,count=0;
float per,MIN;
clrscr();
printf("ENTER THE TOTAL NUMBER OF CLASSES TAKEN:\n");
scanf("%f",&tot);
printf("ENTER THE NUMBER OF CLASSES ATTENDED:\n");
scanf("%f",&att);
per=(att/tot)*100;
printf("PERCENTAGE=%f\n",per);
printf("MIN PERCENTAGE TO BE MAITAINED\n");
scanf("%d",&MIN);

if(per>=MIN)
printf("THE MIN ATTENDENCE ALREADY MAINTAINED\n");
else
{
while(per<MIN)
{
tot=tot+1;
att=att+1;
per=(att/tot)*100;
count=count+1;
}
printf("THE TOTAL NUMBER OF CLASSES TO BE ATTENDED CONTINUESLY TO MAINTAIN MIN(75) ATTENDENCE IS %f",count);
}
getch();
}

u can see the text animation using see just run it any c compiler any enjoy.......


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

int color=15;
int speed=50;
char String[25];

char colors[]={"USE { R, G, g, B, b, Y, M, C, W } for color | USE 0-9 for speed"};
char *StringMenu[]={"  String Animation",
   "---------------------",
   "  1-> Left To Right",
   "  2-> Right To Left",
   "  3-> Top To Bottom",
   "  4-> Bottom To Top",
   "  5-> Exit ",
   "---------------------",
   " Enter the Choice : [ ]"};

void SetColorAndSpeed(char cs)
{
 switch(cs)
 {
  case 'R':case 'r': textcolor(RED);break;
  case 'B':          textcolor(BROWN);break;
  case 'b':          textcolor(BLUE);break;
  case 'G':          textcolor(DARKGRAY);break;
  case 'g':          textcolor(GREEN);break;
  case 'Y':case 'y': textcolor(YELLOW);break;
  case 'M':case 'm': textcolor(MAGENTA);break;
  case 'C':case 'c': textcolor(CYAN);break;
  case 'W':case 'w': textcolor(WHITE);break;
 }
 if(cs > 47 && cs < 58)
 speed = (58-cs)*25+1;
}

void ShowColorSpeed()
{
 int i;
 for(i=1;i<=80;i++)
 {
  gotoxy(i,24);
  printf("-");
 }
 gotoxy(10,25);
 printf("%s",colors);
}
void ShowMenu()
{
 int i;
 clrscr();
 for(i=0;i<9;i++)
 {
  gotoxy(30,7+i);
  printf("%s",StringMenu[i]);
 }
}
void DisplayMsg(int x,int y,char msg[])
{
 int i,prev;
   gotoxy(x,y);
   printf("%s",msg);
   getch();
   gotoxy(x,y);
   for(i=0;msg[i];i++)
   {
    cprintf(" ");
    delay(25);
   }
}
void GetString()
{
 clrscr();
 gotoxy(20,12);
 printf("Enter the String : ");
 gets(String);
}
char GetChoice()
{
 char ch;
 do
 {
   gotoxy(51,15);  ch=getche();  gotoxy(51,15);
  if(!(ch>='1' && ch <='5'))
   DisplayMsg(28,18,"Enter Correct Choice !");
  if(ch=='5')
   exit(0);
 }while(!(ch>='1' && ch <='5'));
 GetString();
 clrscr();
 textcolor(15);
 _setcursortype(0);
 DisplayMsg(26,12,"Press Any Key to Animate !");
 ShowColorSpeed();
 return ch;
}

void LeftToRight()
{
 int i,j;
 gotoxy(2,12);
 printf("%s",String);
 for(i=strlen(String)-1;i>=0;i--)
 {
  for(j=2;String[i]!=' ' && j<60;j++)
  {
   if(kbhit())
    SetColorAndSpeed(getch());
   gotoxy(i+j,12);
   cprintf(" ");
   gotoxy(i+j+1,12);
   cprintf("%c",String[i]);
   delay(speed);
  }
 }
 getch();
 _setcursortype(2);
 textcolor(7);
}
void RightToLeft()
{
 int i,j;
 gotoxy(60,12);
 printf("%s",String);
 for(i=0;String[i];i++)
 {
  for(j=60;String[i]!=' ' && j>=2;j--)
  {
   if(kbhit())
    SetColorAndSpeed(getch());
   gotoxy(i+j,12);
   cprintf(" ");
   gotoxy(i+j-1,12);
   cprintf("%c",String[i]);
   delay(speed);
  }
 }
 getch();
 _setcursortype(2);
 textcolor(7);
}
void TopToBottom()
{
 int i,j;
 gotoxy(30,22);
 printf("%s",String);
 for(i=0;i[String];i++)
 {
  for(j=21;String[i]!=' ' && j>=5;j--)
  {
   if(kbhit())
    SetColorAndSpeed(getch());
   gotoxy(30+i,j+1);
   cprintf(" ");
   gotoxy(30+i,j);
   cprintf("%c",String[i]);
   delay(speed);
  }
 }
 getch();
 _setcursortype(2);
 textcolor(7);
}
void BottomToTop()
{
 int i,j;
 gotoxy(30,5);
 printf("%s",String);
 for(i=strlen(String)-1;i>=0;i--)
 {
  for(j=5;String[i]!=' ' && j<23;j++)
  {
   if(kbhit())
    SetColorAndSpeed(getch());
   gotoxy(30+i,j-1);
   cprintf(" ");
   gotoxy(30+i,j);
   cprintf("%c",String[i]);
   delay(speed);
  }
 }
 getch();
 _setcursortype(2);
 textcolor(7);
}
void main()
{
  do
  {
   ShowMenu();
   switch(GetChoice())
   {
    case '1':
  LeftToRight();
  break;
    case '2':
  RightToLeft();
  break;
    case '3':
  TopToBottom();
  break;
    case '4':
  BottomToTop();
  break;
   }
  }while(1);
}


Now i blog with many matters related to programming and also some thrilling programs mainly based on c and c++ ,now this particular c prg is to convert numbers to words eg:23698 to twenty three thousand six hundred ninty eight