Tuesday, 20 November 2012

Matrix addition and multiplication program

Program:
#include<stdio.h>
 void main()
 {
 int ch,i,j,m,n,p,q,k,r1,c1,a[10][10],b[10][10],c[10][10];
 clrscr();
 printf("************************************");
 printf("\n\t\tMENU");
 printf("\n**********************************");
 printf("\n[1]ADDITION OF TWO MATRICES");
 printf("\n[2]MULTIPLICATION OF TWO MATRICES");
 printf("\n[0]EXIT");
 printf("\n**********************************");
 printf("\n\tEnter your choice:\n");
 scanf("%d",&ch);
 if(ch<=2 & ch>0)
 {
 printf("Valid Choice\n");
 }
 switch(ch)
 {
 case 1:
 printf("Input rows and columns of A & B Matrix:");
 scanf("%d%d",&r1,&c1);
 printf("Enter elements of matrix A:\n");
 for(i=0;i<r1;i++)
 {
 for(j=0;j<c1;j++)
 scanf("%d",&a[i][j]);
 }
 printf("Enter elements of matrix B:\n");
 for(i=0;i<r1;i++)
 {
 for(j=0;j<c1;j++)
 scanf("%d",&b[i][j]);
 }
 printf("\n =====Matrix Addition=====\n");
 for(i=0;i<r1;i++)
 {
 for(j=0;j<c1;j++)
 printf("%5d",a[i][j]+b[i][j]);
 printf("\n");
 }
 break;
 case 2:
 printf("Input rows and columns of A matrix:");
 scanf("%d%d",&m,&n);
 printf("Input rows and columns of B matrix:");
 scanf("%d%d",&p,&q);
 if(n==p)
 {
 printf("matrices can be multiplied\n");
 printf("resultant matrix is %d*%d\n",m,q);
 printf("Input A matrix\n");
 read_matrix(a,m,n);
 printf("Input B matrix\n");
 /*Function call to read the matrix*/
 read_matrix(b,p,q);
 /*Function for Multiplication of two matrices*/
 printf("\n =====Matrix Multiplication=====\n");
 for(i=0;i<m;++i)
 for(j=0;j<q;++j)
 {
 c[i][j]=0;
 for(k=0;k<n;++k)
 c[i][j]=c[i][j]+a[i][k]*b[k][j];
 }
 printf("Resultant of two matrices:\n");
 write_matrix(c,m,q);
 }
 /*end if*/
 else
 {
 printf("Matrices cannot be multiplied.");
 }
 /*end else*/
 break;
 case 0:
 printf("\n Choice Terminated");
 exit();
 break;
 default:
 printf("\n Invalid Choice");
 }
 getch();
 }
 /*Function read matrix*/
 int read_matrix(int a[10][10],int m,int n)
 {
 int i,j;
 for(i=0;i<m;i++)
 for(j=0;j<n;j++)
 scanf("%d",&a[i][j]);
 return 0;
 }
 /*Function to write the matrix*/
 int write_matrix(int a[10][10],int m,int n)
 {
 int i,j;
 for(i=0;i<m;i++)
 {
 for(j=0;j<n;j++)
 printf("%5d",a[i][j]);
 printf("\n");
 }
 return 0;
 }

Output:
 

 

Multiplication Table using C

Program:
#include<stdio.h>
#include<conio.h>
void main()
{
int n,p,i;
printf("\n enter the noof which u want to see the table");
scanf("%d",&n);
for(i=1;i<=10;i++)
{
p=n*i;
printf("\n%d *%d=%d",n,i,p);
}
getch();
}

Output:


 

How to swap two numbers without using third variable

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

void main()
{
int a,b;
clrscr();
printf("Enter the values of a and b");
scanf("%d%d",&a,&b);
a=b+a;
b=a-b;
a=a-b;
printf("After Swapping a=%d b=%d,a,b);
getch();
}

Output:
Enter the values of a and b
30 40
After Swapping a=40 b=30

Friday, 16 November 2012

How to calculate Tamilnadu Electronic Bill in C Program


Program:
#include<stdio.h>
#include<conio.h>
#include<math.h>

void main()
{
float r=0.0,a=1.1,b=1.8,c=3.5,d=5.75;
clrscr();
printf("Enter the readings\n");
scanf("%f",&r);
if(r<=100)
printf("Rupees=%f",r*a);
else if((r>100)&&(r<=200))
printf("Rupees=%f",r*b);
else if((r>200)&&(r<=500))
printf("Rupees=%f",r*c);
else if(r>500)
printf("Rupees=%f",r*d);
getch();
}


Tuesday, 23 October 2012

Abstract Class Vs Interface

FeatureInterfaceAbstract class
Multiple inheritanceclass may inherit several  interface .class may inherit only one  abstract class .
Default implementationAn interface cannot provide any code, just the signature.An abstract class  can provide complete, default code and/or just the details that have to be overridden.
Access ModfiersAn  interface  cannot have access modifiers for the subs, functions, properties etc everything is assumed as publicAn  abstract class  can contain access modifiers for the subs, functions, properties
Core VS Peripheralinterfaces are used to define the peripheral abilities of a class. In other words both Human and Vehicle can inherit from a IMovable interfaceAn  abstract class  defines the core identity of a class and there it is used for objects of the same type.
HomogeneityIf various implementations only share method signatures then it is better to use interfaceIf various implementations are of the same kind and use common behaviour or status then abstract class  is better to use.
SpeedRequires more time to find the actual method in the corresponding classes.Fast
Adding functionality (Versioning)If we add a new method to an  interface  then we have to track down all the implementations of the interface  and define implementation for the new method.If we add a new method to an abstract class then we have the option of providing default implementation and therefore all the existing code might work properly.
Fields and ConstantsNo fields can be defined in interfacesAn  abstract class can have fields and constrants defined.


Monday, 22 October 2012

Pascal Triangle in c


Program:
#include<stdio.h>
 
long factorial(int);
 
main()
{
   int i, n, c;
 
   printf("Enter the number of rows you wish to see in pascal triangle\n");
   scanf("%d",&n);
 
   for ( i = 0 ; i < n ; i++ )
   {
      for ( c = 0 ; c <= ( n - i - 2 ) ; c++ )
         printf(" ");
 
      for( c = 0 ; c <= i ; c++ )
         printf("%ld ",factorial(i)/(factorial(c)*factorial(i-c)));
 
      printf("\n");
   }
 
   return 0;
}
 
long factorial(int n)
{
   int c;
   long result = 1;
 
   for( c = 1 ; c <= n ; c++ )
         result = result*c;
 
   return ( result );
}

Output:

Monday, 15 October 2012

Program to find odd or even number using C

#include<stdio.h>
void main ()
{
int number;
clrscr ();
printf ("Enter the value of number: ");
scanf("%d",&number);
if (number%2==0)
{
printf ("\nNumber is Even");
}
else
{
printf("\nNumber is Odd");
}
getch ();
}

Output:








Tuesday, 9 October 2012

Difference between C++ and Java



C++ was mainly designed for systems programming and Java was created initially to support network computing.
But today java is provides support for all purpose internet,distributed system etc.

1.C++ supports pointers whereas Java does not pointers.
Although Java supports pointers in a way, that Object reference are used to pass between functions, but pointer arithematical is not possible.
2.At compilation time Java Source code converts into byte code.
The interpreter execute  this byte code at run time and gives output.
Java is interpreted for the most part and hence platform independent.
C++ run and compile using compiler which converts source code into machine level languages so       c++ is plate from dependents 
3.Java uses compiler and interpreter both and in c++ their is only compiler.
4.C++ supports operator overloading,multiple inheritance but java does not.Java supports method overloading.
5.C++ is more nearer to hardware then Java
6.Everything is an object in Java (Single root hierarchy as everything gets derived from java.lang.Object). 
7.Java is pure object oriented programming language, while C++ supports both procedural and object oriented approach.
8.Thread support is built-in Java but not in C++. 
9.Internet support is built-in Java but not in C++.
10.Java does not support header file, include library files just like C++ .Java use import to include  different Classes and methods.
11.Java does not support default arguments like C++.
12.There is no scope resolution operator " :: "in Java.
13.There is no "goto " statement in Java.
14.Java support call by value only.
15.Java does not support unsigned integer.
16. No preprocessor is required in Java, while C++ rely on preprocessor.
17.Java doesn’t support Templates, while C++ supports Templates for parameterized type.
18.In Java, there is bound checking on the arrays, while in C++ there is no bound checking.
19.Java doesn’t supports forward referencing, while C++ supports explicit forward referencing
20.Java supports interfaces which is missing in C++
21.Java also supports network protocols such as TCP/IP and HTTP,while C++ lacks those support.
22.Java supports distributed applications such as RMI and sockets, while C++ lacks this functionality.
23. In Java, array lengths in multidimensional can vary from one element to the next within one dimension, while in C++ multidimensional arrays lengths are of same sizes.
24.Java supports labels on break and continue statements, while in C++ there is no label functionality.
25.  In Java, Strings are objects, while in C++, Strings are null-terminated character arrays.

Sunday, 7 October 2012

Difference between C and C++


1.C is Procedure Oriented Programming Language (POP).
   C++ is Object Oriented Programming Language (OOP).

2.C is mostly used to develop system software.
   C++ is mostly used to modal real life problem to program and use to develop application programs.  

3.C program has extension .C
   C++ program has extension .cpp

4.C uses the top-down approach.
    while C++ uses the bottom-up approach.

5.C is function-driven.
   while C++ is object-driven.

6.C supports GTK tool.
   C++ supports Qt tools for GUI programming.

7.C does not have different visibility mode to store data. It stores data in a default mode irrespective      of the data type.
   C++ provides different data visibility modes : Public, Private, and Protected.

8. C language was developed in AT & T bell laboratories. 
    While C++ is the higher version of C with GUI features developed by B. Stroutstrup.

Friday, 5 October 2012

Conversion of decimal number to a binary number in C++

#include<iostream.h>

#include<math.h>
#include<conio.h>
#include<stdlib.h>

void main()
{
int dec_num;
int bin_digits;
int *bi;
int index,i;
int repeat;

clrscr();

do
{
cout<<"\n"<<"Enter the decimal number ";
cin>>dec_num;
bin_digits=(log10(dec_num)/log10(2))+1;

bi=new int[bin_digits];
index=0;

while(dec_num > 0)
{
bi[index]=dec_num % 2;
index++;
dec_num=dec_num / 2;
}

for(i=bin_digits-1;i>=0;i--)
cout<<bi[i];

delete[] bi;
cout<<"\n"<<"Repeat? Press 1 ";
cin>>repeat;
}while(repeat == 1);

exit(0);
}

OUTPUT:


Monday, 1 October 2012

Program to find Armstrong Number


#include <stdio.h>
 
main()
{
   int number, sum = 0, temp, remainder;
 
   printf("Enter a number\n");      
   scanf("%d",&number);
 
   temp = number;
 
   while( temp != 0 )
   {
      remainder = temp%10;
      sum = sum + remainder*remainder*remainder;
      temp = temp/10; 
   }
 
   if ( number == sum )
      printf("Entered number is an armstrong number.");
   else
      printf("Entered number is not an armstrong number.");         
 
   return 0;
}

output:

Program to generate and print Armstrong Numbers using C


#include<stdio.h>
#include<conio.h>
 
main()
{
   int r;
   long numb = 0, c, sum = 0, temp;
 
   printf("Enter the maximum range upto which you want to find armstrong numbers ");
   scanf("%ld",&numb);
 
   printf("Following armstrong numbers are found from 1 to %ld\n",numb);
 
   for( c = 1 ; c <= numb ; c++ )
   {
      temp = c;
      while( temp != 0 )
      {
         r = temp%10;
         sum = sum + r*r*r;
         temp = temp/10;
      }
      if ( c == sum )
         printf("%ld\n", c);
      sum = 0;
   }
 
   getch();
   return 0;
}

Output:
Enter the maximum range up to which you want to find armstrong    numbers 1000
Following armstrong numbers are found from 1 to 1000
1
153
370
371
407


Sunday, 30 September 2012

Program to delete a file using C


#include<stdio.h>
 
main()
{
   int status;
   char file_name[30];
 
   printf("Enter the name of file you want to delete\n");
   gets(file_name);
 
   status = remove(file_name);
 
   if( status == 0 )
      printf("%s file deleted successfully.\n", file_name);
   else
   {
      printf("Unable to delete the file\n");
      perror("Error");
   }
 
   return 0;
}

Output:
       Enter the name of file you want to delete multiply.c
       multiply.c file deleted successfully.

Thursday, 27 September 2012

How to make a Pyramid using C


#include<stdio.h>
 
main()
{
   int row, c, n, temp;
 
   printf("Enter the number of rows in pyramid of stars you wish to see ");
   scanf("%d",&n);
 
   temp = n;
 
   for ( row = 1 ; row <= n ; row++ )
   {
      for ( c = 1 ; c < temp ; c++ )
         printf(" ");
 
      temp--;
 
      for ( c = 1 ; c <= 2*row - 1 ; c++ )
         printf("*");
 
      printf("\n");
   }
 
   return 0;
}

Output:

Thursday, 20 September 2012

Fibonacci series program using c


#include<stdio.h>
 
main()
{
   int n, a = 0, b = 1, next, c;
 
   printf("Enter the number of terms\n");
   scanf("%d",&n);
 
   printf("First %d terms of Fibonacci series are :-\n",n);
 
   for ( c = 0 ; c < n ; c++ )
   {
      if ( c <= 1 )
         next = c;
      else
      {
         next = a + b;
         a = b;
         b = next;
      }
      printf("%d\n",next);
   }
 
   return 0;
}







Output:

Thursday, 13 September 2012

Best applications of C and C++ Language

The famous applications and software packages have been written in C or C++ programming languages due to the fact that most of the programs are partially or completely written in C or C++. Apart from applications there are some operating systems that are written in C++ programming language.

Ex:Windows 95, 98, 2000, XP, Apple OS X, Symbian OS and BeOS.

Adobe Systems:
All major applications of adobe systems are developed in C++ programming language. These applications include Photoshop & Image Ready, Illustrator and Adobe Premier.

Google:
Some of the Google applications are also written in C++, including Google file system and Google Chromium.

Mozilla:
Internet browser Firefox and email client Thunderbird are written in C++ programming language and they are also open source projects.

MySql:
MySQL is the world’s most popular open source database software, with over 100 million copies of its software downloaded or distributed throughout its history. Many of the world’s largest and fastest-growing organizations use MySQL to save time and money powering their high-volume Web sites, critical business systems, and packaged software — including industry leaders such as Yahoo!, Alcatel-Lucent, Google, Nokia, YouTube, Wikipedia, and Booking.com.


Alias System - Autodesk Maya:
Maya 3D software was originally developed by Alias System Corporation and was later carried over by Autodesk. Maya 3D software, now a days is widely used in computers, video games, television. It is a powerful, integrated 3D modelling, animation, visual effects, and rendering solution.

Winamp Media Player:
Winamp is the ultimate media player, allows you to manage audio and video files, rip and burn CDs, enjoy free music, access and share your music and videos remotely, and sync your music to your iPod , Creative, and Microsoft Plays for Sure devices . Winamp features album art support, streams audio and video content, and provides access to thousands of internet radio stations and podcasts.

12D solutions:
12D Solutions Pty Ltd is an Australian software developer specialising in civil engineering and surveying applications. Computer Aided Design system for surveying, civil engineering, and more. 12D Solutions clients include civil and water engineering consultants, environmental consultants, surveyors, local, state and national government departments and authorities, research institutes, construction companies and mining consultants.

Bloomberg:
Providing real-time financial information to investors.

callas software:
callas software develops pdf creation, optmisation, updation and pdf form creation tools and plugins.

Image systems:
These are the world leading motion analysys programs and film scanner systems.

Operating Systems developed in C++
Apple os x:
Few parts of apple OS X are written in C++ programming language. Also few application for iPod are written in C++.

Microsoft:
Literally most of the software are developed using various flavors of Visual C++ or simply C++. Most of the big applications like Windows 95, 98, Me, 200 and XP are also written in C++. Also Microsoft Office, Internet Explorer and Visual Studio are written in Visual C++.

Symbian os:
Symbian OS is also developed using C++. This is one of the most widespread OS’s for cellular phones.





Tuesday, 11 September 2012

Bubble sort program using c


#include <stdio.h>
 
int main()
{
  int array[100], n, c, d, swap;
 
  printf("Enter number of elements\n");
  scanf("%d", &n);
 
  printf("Enter %d integers\n", n);
 
  for (c = 0; c < n; c++)
    scanf("%d", &array[c]);
 
  for (c = 0 ; c < ( n - 1 ); c++)
  {
    for (d = 0 ; d < n - c - 1; d++)
    {
      if (array[d] > array[d+1]) /* For decreasing order use < */
      {
        swap       = array[d];
        array[d]   = array[d+1];
        array[d+1] = swap;
      }
    }
  }
 
  printf("Sorted list in ascending order:\n");
 
  for ( c = 0 ; c < n ; c++ )
     printf("%d\n", array[c]);
 
  return 0;
}

Related Posts Plugin for WordPress, Blogger...