Tuesday 7 June 2016

Try this out to add two matrices

#include<stdio.h>
#include<conio.h>
void main()
{
    int a[3][3],b[3][3],i,j,k;
    clrscr();
    gotoxy(1,1);
    printf("Enter first matrix:");
    gotoxy(4,2);
    printf("%c     %c",218,191);
    gotoxy(4,3);
    printf("%c_ _ _%c",179,179);
    gotoxy(4,4);
    printf("%c_ _ _%c",179,179);
    gotoxy(4,5);
    printf("%c_ _ _%c",179,179);
    gotoxy(4,6);
    printf("%c     %c",192,217);

    gotoxy(25,1);
    printf("Enter second matrix:");
    gotoxy(29,2);
    printf("%c     %c",218,191);
    gotoxy(29,3);
    printf("%c_ _ _%c",179,179);
    gotoxy(29,4);
    printf("%c_ _ _%c",179,179);
    gotoxy(29,5);
    printf("%c_ _ _%c",179,179);
    gotoxy(29,6);
    printf("%c     %c",192,217);
    //input in first matrix
    for(i=0;i<3;i++)
    {
        for(j=0,k=0;j<3;j++,k+=2)
        {
            gotoxy(5+k,3+i);
            a[i][j]=getche();
            a[i][j]-=48;
        }
    }
    //input in second matrix
    for(i=0;i<3;i++)
    {
        for(j=0,k=0;j<3;j++,k+=2)
        {
            gotoxy(30+k,3+i);
            b[i][j]=getche();
            b[i][j]-=48;
        }
    }
    printf("\n\nSUM OF MATRICES IS:\n");
    for(i=0;i<3;i++)
    {
        for(j=0;j<3;j++)
        {
            printf("%d ",a[i][j]+b[i][j]);
        }
        printf("\n");
    }
    getch();
}

Sunday 13 January 2013

Calculator coded in C++


#include<iostream.h>
#include<conio.h>
#include<stdio.h>
void main()
{
 int a,b;
 char opr;
 textmode(C80);
 clrscr();
  textbackground(BLACK);
  textcolor(WHITE+BLINK);
  gotoxy(10,1);
  textbackground(BLACK);
  cprintf("CALCULATOR");
  textcolor(WHITE);
 label:
 gotoxy(9,3);
 cout<<"Enter number here ";
 putchar(25);
 gotoxy(27,4);
 cin>>a;
 gotoxy(27,5);
 cin>>b;
 gotoxy(15,10);
 cout<<"[+][-][*]    [CE]";
 gotoxy(15,11);
 cout<<"[\/][  = ]";
 gotoxy(15,13);
 cout<<"Select operator: ";
 opr=getch();
 gotoxy(25,5);
 putchar(opr);
 gotoxy(25,6);
 cout<<"----------";
 textbackground(BLACK);
 gotoxy(18,11);
 textbackground(GREEN);
 cprintf("[  = ]");
 textcolor(WHITE);
 switch(opr)
 {
  case '+':
  textbackground(BLACK);
  gotoxy(15,10);
  textbackground(YELLOW);
  cprintf("[+]");
  textcolor(WHITE);
  gotoxy(25,7);
  cout<<"="<<a+b;
  break;
  case '-':
  textbackground(BLACK);
  gotoxy(18,10);
  textbackground(YELLOW);
  cprintf("[-]");
  textcolor(WHITE);
  gotoxy(25,7);
  cout<<"="<<a-b;
  break;
  case '*':
  textbackground(BLACK);
  gotoxy(21,10);
  textbackground(YELLOW);
  cprintf("[*]");
  textcolor(WHITE);
  gotoxy(25,7);
  cout<<"="<<a*b;
  break;
  case '/':
  textbackground(BLACK);
  gotoxy(15,11);
  textbackground(YELLOW);
  cprintf("[\/]");
  textcolor(WHITE);
  gotoxy(25,7);
  cout<<"="<<a/b;
  break;
  case 'c':
  case 'C':
  textbackground(BLACK);
  gotoxy(28,10);
  textbackground(YELLOW);
  cprintf("[CE]");
  textcolor(WHITE);
  gotoxy(25,7)
  goto label;
  default:
  gotoxy(27,4);
  cout<<"    ";
  gotoxy(27,5);
  cout<<"    ";
  gotoxy(25,7);
  cout<<"         ";
  cout<<"Invalid operator.";
  break;
 }
 getch();
}