Posts

Showing posts from March, 2014

Warshall Transitive Clousre

Image
#include<iostream> #include<conio.h> using namespace std; int main() { int a[4][4],i,j,k,r[4][4]; cout<<"Enter element of A matrix: \n"; for(i=0;i<4;i++) { for(j=0;j<4;j++) cin>>a[i][j]; cout<<endl; } cout<<"Matrix You enterd : \n"; for(i=0;i<4;i++) { for(j=0;j<4;j++) cout<<"\t"<<a[i][j]; cout<<endl; } cout<<"\nTransitive clousre :\n"; cout<<"R(0): \n"; for(i=0;i<4;i++) { for(j=0;j<4;j++) cout<<"\t"<<a[i][j]; cout<<endl; } for(i=0;i<4;i++) for(j=0;j<4;j++) r[i][j]=a[i][j]; for(k=0;k<4;k++) { for(i=0;i<4;i++) { for(j=0;j<4;j++) { r[i][j]=r[i][j]||(r[i][k]&&r[k][j]); } } cout<<"R("<<k+1<<")\n"; for(i=0;i<4;i++) { for(j=0;j<4;j++) cout<<"\t"

About

Image
Amit Duhan 3nd year CSE Lovely Professional University INDIA Licence  SmartProgrammerOn by Amit Duhan is licensed under a Creative Commons Attribution 4.0 International License . Based on a work at www.smartprogrammeron.blogspot.in .

Create a Harmless Funny Virus with Notepad-Continuously eject CD/DVD drives

Image
This VBS trick will create a code which will continuously eject all your connected Optical drives. If you put them back in, it will pop them out again.  Step:1 Press windows + R. Step:2 Type notepad and hit enter. Step:3 Write this code.                                        Set oWMP = CreateObject("WMPlayer.OCX.7")                                       Set colCDROMs = oWMP.cdromCollection                                       do                                            if colCDROMs.Count >= 1 then                                              For i = 0 to colCDROMs.Count - 1                                                 colCDROMs.Item(i).Eject                                              Next                                               For i = 0 to colCDROMs.Count - 1                                                  colCDROMs.Item(i).Eject                                              Next                                                   End If              

Comparison Counting Sort

Image
#include<conio.h> #include<iostream> #define max 50 using namespace std; int main() { int a[6],count[max],s[6]; cout<<"Enter 5 oderable values: \n"; for(int i=0;i<6;i++) cin>>a[i]; for(int i=0;i<6;i++) count[i]=0; for(int i=0;i<5;i++) for(int j=i+1;j<6;j++) { if(a[i]<a[j]) count[j]=count[j]+1; else count[i]=count[i]+1; } for(int i=0;i<6;i++) s[count[i]]=a[i]; cout<<"Shorted array is : "; for(int i=0;i<6;i++) cout<<"\t"<<s[i]; getch(); return 0; } Output How it works:-

Create, Select and Insert into table

Image
To create a table : create table table_name(col_name_1 data_type,........col_name_n data_type); For example:- Create a table  Bank with cols Account Number, Account Holder Name and Balance in account.                             create table bank(account_number int,account_holder_name varchar(20),balance int); output:- Table Created. To insert data into table : insert into table_name values(value_1,value_2,.......value_n); For example:- Insert data into Bank table. insert into bank values(101,'A',3000); insert into bank values(102,'B',4000); insert into bank values(103,'C',5000); insert into bank values(104,'D',6000); insert into bank values(105,'E',7000); insert into bank values(106,'F',8000); output:- 1 Row Created 1 Row Created 1 Row Created 1 Row Created 1 Row Created 1 Row Created To Select data from table : select *from table_name; For example:- Select all data from Bank table select *from bank; output:- 6 rows selecte

SQL (Structure Query Language)

DDL : Data Definition Language                                                    ( i )    Create Table                                                    ( ii )   Alter Table                                                    ( iii )   Drop the table DML : Data Manipulation Language                                                    ( i )    Insert                                                    ( ii )   Update                                                    ( iii )  Delete                                                    ( iv )  Select DCL : Data Control Language                                                    ( i )    Grant                                                    ( ii )   Revoke

The C keywords

Image
The C keywords are reserved by the compiler. All the C keywords have been assigned fixed meaning and they cannot be used as variable names. However, few C compilers allow constructing variable names, which exactly coincide with the keywords. It is suggested that the keyword should not be mixed up with variable names. For utilizing the keywords in a program, no header file is required tto be included. The descriptions of the keyword are explained in the different programs, Th 32 C keywords provided in ANSI C are listed below:-

Type Of Tokens

 A compiler designer prescribes rules for making a program using statements. The Smallest unit in a program/statement is called a token . The compiler identifies them as tokens. Tokens are classified in the following types:- Keyword : Key words are reserved by the compiler. There are 32 keywords(ANSI Standard). Variables : These are user defined. Any number of variables can be defined.' Constants : Constants are assigned to variables. Operators : Operators are of different types and are used in expression. Special Characters : These characters are used in different declarations in C. Strings : A sequence of characters.

The Character set

Image
  The C character set                                                       A character is a part of a word, sentence or paragraph. By using different character, words, expressions and statements can be created on the basis of the requirement. This creation depends upon the computer on which a program run.                                                                   A character is represented by any alphabets in lowercase or uppercase, digits or special characters. Figure presents valid categories of C character set, which are follow: (i) letters, (ii) digits, (iii) white space and (iv) special characters.                                The character list in the given table are represented in the computer by numeric values. Each character is assigned a unique numeric value. The value put together are called character code. which are used in the computer system. The widely used computer codes are ASCII and EBCDIC.         ASCII Code : ASCII stands for American

Header Files

Image
stdio.h : Standard input and output files. All formatted and un-formatted functions include file operation functions defined in this file. The most useful formatted printf() and scanf() are defined in this file. This file must be included at the top of the program. Most useful functions from this header file are printf(), scanf(), getchar(), gets(), putc(), and putchar().               conio.h : Console inout and output. This file contains input and output functions along with a few graphic-supporting functions. This getch(), geche() , and clrscr() functions are defined in this file.         math.h : This file contains all mathematical and other useful functions. The commonly useful functions this file are floor(), abs(), ceil(), pow(), sin(), cos() and tan() . The list of commonly used header files are given table:-

Advantage of C

It contains a powerful data definition. The data type supported are characters, alpha-numeric integers, long integer, floats and double. It also supports string manipulation in the form of character array. C supports a powerful set of operation. It also supports powerful graphic programming and directly operates with hardware. Execution of program is faster. An assembly code is also inserted into C programs. C programs are highly portable on any type of OS platforms. System programs such as compilers, operating system can be developed in C. For example the popular operating system UNIX is developed in C. The C language has 32 keywords and about 145 library function and near about 30 header files. C works closely with machines and matches assembly language in many ways.

Programming Rules

A programmer while writing a program should follow following rules. Every program should have main() function. C statements should be terminated by a semi-colon (;). At some place, a comma operator is permitted. If only a semi-colon is placed it is treated as a statement. For example:-                          while(condition)                          ; The above statement generates infinite loop. Without semi-colon the loop will not execute. An unessential semicolon if placed by the programmer is treated as an empty statement. All statements should be written in lowercase letters. Generally, uppercase letter are used only for symbolic constants. Blank space my be inserted between the words. This leads to improvement in the read-ability of the statements. However this is not applicable while declaring a variable, keyword, constant and function. It is not necessary to fin the position of statement in the program; i.e. a programmer can write the statement anywhere between the two

Insertion Sort

Image
#include<iostream> #include<conio.h> #define max 50 using namespace std; int main() { int a[max]; cout<<"How many elements you want to enter: "; int num,v,j; cin>>num; cout<<"Enter Elements one by one: \n"; for(int i=0;i<num;i++) cin>>a[i]; for(int i=0;i<num;i++) { v=a[i]; j=i-1; while (j>=0 && a[j]>v) { a[j+1]=a[j]; j=j-1; } a[j+1]=v; } cout<<"List after Sorting: "; for(int i=0;i<num;i++) cout<<"  "<<a[i]; getch(); return 0; } Output: How it work:- 89 | 45 68  90  29  34  17 45  89 | 68  90  29  34  17 45  68  89 | 90  29  34  17 45  68  89  90 | 29  34  17 29  45  68  89  90 | 34  17 29  34  45  68  89  90 | 17 17  29  34  45  68  89  90

Shutdown Pc

Image
#include<iostream> #include<stdlib.h> #include<conio.h> using namespace std; int main() {    int ch;   while(1)   {   cout<<"1. Shutdown\n2. Open TaskManager\n3. Open My Documents.\n4. Exit\nChoice : ";   cin>>ch;     switch (ch)   {   case 1:       system("C:\\WINDOWS\\System32\\shutdown /s");       break; case 2: system("C:\\WINDOWS\\System32\\taskmgr /s"); break; case 3: system("C:\\WINDOWS\\explorer /s"); break; case 4: return 0; } }   getch();     return 0; } Output:

Burte Force String Match

Image
#include<iostream> #include<conio.h> #include<string.h> using namespace std; int main() { char text[]={"SmartProgrammerOn"},strn[11]; int t,s; cout<<"Given Data is : \t"<<text; cout<<"\nWhat you want search(max size 10): "; cin>>strn; t=strlen(text); s=strlen(strn); int i,j=0; for(i=0;i<t;i++) { j=0; while (j<s&&strn[j]==text[i+j]) { j=j+1; if (j==s) { cout<<"String Match at location "<<i+1; return 0; } } } cout<<"No result found."; getch(); } OutPut:

Sequential Search

Image
#include<iostream> #include<conio.h> using namespace std; int main() { int a[10]={67,50,34,68,34,78,5,78,56,12},item,i; cout<<"Given Data is : "; for(i=0;i<10;i++) cout<<"  "<<a[i]; cout<<"\nEnter item you want to search : "; cin>>item; i=0; while (a[i]!=item) i++; if (i<10) cout<<"Item found at location "<<i+1; else cout<<"Item not found."; getch(); return 0; } Output:

Bubble Sort

Image
#include<iostream> #include<conio.h> using namespace std; int main() { int a[10]; cout<<"Enter 10 Oderable intergers: \n"; for(int i=0;i<=9;i++) cin>>a[i]; cout<<"List after sorted: "; for(int i=0;i<=9;i++) for(int j=0;j<=9;j++) if(a[j]>a[j+1]) { int temp=a[j]; a[j]=a[j+1]; a[j+1]=temp; } for(int i=0;i<=9;i++) cout<<"  "<<a[i]; getch(); return 0; } Output:

Selection Sort

Image
#include<iostream> #include<conio.h> using namespace std; int main() { int a[10],min; cout<<"\t\t\tSelection Sort"; cout<<"\nEnter 10 Oderable integers: \n"; for(int i=0;i<10;i++) cin>>a[i]; for(int i=0;i<10-1;i++) { min=i; for(int j=i+1;j<10;j++) { if(a[j]<a[min]) { min=j; } } if(min!=i) { int temp=a[i]; a[i]=a[min]; a[min]=temp; } } cout<<"Shorted List is: "; for(int i=0;i<10;i++) cout<<"  "<<a[i]; getch(); return 0; } Output:

Fibonacci Series (Non-Recursive Method)

Image
#include<iostream> #include<conio.h> using namespace std; int main() { int a; int f1=0,f2=1,f; cout<<"Enter no.: "; cin>>a; cout<<"Fibonacci Series : "; for(int i=0;i<a;i++) { if(i<=1) f=i; else { f=f1+f2; f1=f2; f2=f; } cout<<"  "<<f; } getch(); } Click here for Recursive Method

Fibonacci Series (Recursive Method)

Image
#include<iostream> #include<conio.h> using namespace std; int fibonacci(int x) { if(x==0) return 0; else if(x==1) return 1; else return (fibonacci(x-1)+fibonacci(x-2)); } int main() { int a,i=0; cout<<"Enter no.: "; cin>>a; cout<<"Fibonacci Series: "; for(int c=1;c<=a;c++) { cout<<" "<<fibonacci(i); i++; } getch(); return 0; } Output: Click Here For Non-Recursive Method

Fundamental Data Structures

Image
Since the vast majority of algorithms of interest operate on data, particular ways of organizing data play a critical role in the design and analysis of algorithms. A data structure can be defined as a particular scheme of organizing related data item. The nature of the data items is dictated by a problem at hand; they can range from elementary data types (e.g., integers or characters) to data structure. There are a few data structure that have proved to be particular important for computer algorithms. Since you are undoubtedly familiar with most if not all of them, just a quick review is provided here: Linear Data Structures The two most important elementary data structures are the array and the linked list. A (one-dimensional) array is a sequence of n items of the same data type that are stored contiguously in computer memory and made accessible by specifying value of the array’s index. In the majority of cases, the index is an integer either between 0 and n-1 or bet

Linear Search

Image
#include<iostream> #include<conio.h> using namespace std; int main() { int a[10],n; cout<<"Enter elements \n"; for(int i=0;i<10;i++) { cout<<"\t\t"; cin>>a[i]; } cout<<"Enter element you to search: "; cin>>n; for(int i=0;i<10;i++) if(a[i]==n) { cout<<"Element found"; return 0; } cout<<"\t\t\t\tNot found"; getch(); return 0; }

To find prime factor of a number

Image
#include<iostream> #include<conio.h> #include<math.h> #define MAX 50 using namespace std; int main() { int p,a[MAX],n,l[MAX],j,i; cout<<"Enter no. (number must be greater than 2) : "; cin>>n; for(p=2;p<=n;p++) a[p]=p; for(p=2;p<=(sqrt(n));p++) { if (a[p]!=0) { j=p*p; while (j<=n) { a[j]=0; j=j+p; } } } i=0; for(p=2;p<=n;p++) { if (a[p]!=0) { l[i]=a[p]; i=i+1; } } cout<<"Prime factor of "<<n<<" is: \n"; for(p=0;p<i;p++) cout<<" | "<<l[p]; cout<<" |"; getch(); return 0; } Console Screen Output: -

Wharshall's Path

Image
#include<iostream> #include<conio.h> #define INFINITY ((1 << (8*sizeof (int) - 6)) - 4) using namespace std; int main() { int a[4][4],b[4][4]; int i,j,k; cout<<"Enter value of Adjacent Matrix (row wise) :\n"; for(i=0;i<4;i++) for(j=0;j<4;j++) {cout<<"\t"; cin>>a[i][j]; } for(i=0;i<4;i++) for(j=0;j<4;j++) {if(a[i][j]==0) b[i][j]=INFINITY; else b[i][j]=a[i][j]; } for(k=0;k<4;k++) { for(i=0;i<4;i++) { for(j=0;j<4;j++) { if(b[i][j]>(b[i][k]+b[k][j])) b[i][j]=(b[i][k]+b[k][j]); } } } cout<<"\n\nWharshall's Path\n"; for(i=0;i<4;i++) { for(j=0;j<4;j++) cout<<b[i][j]<<"\t"; cout<<"\n"; } getch(); return 0; }

All Operation in One program

Image
#include<stdio.h> #include<conio.h> int main() { int a,b; printf("Enter A: "); scanf("%d",&a); printf("Enter B: "); scanf("%d",&b); printf("\nA + B = %d",a+b); printf("\nA - B = %d",a-b); printf("\nA * B = %d",a*b); printf("\nA / B = %d",a/b); printf("\nA % B = %d",a%b); getch(); } Output

Sum of two Integers

Image
#include<stdio.h> #include<conio.h> int main() { int a;                                                    //first number to be entered by user int b;                                                   //second number to be entered by user int sum;                                               //variable in which sum will stored printf("Enter Ist integer value :\t"); scanf("%d",&a);                                 //scanf is use to read a value "%d" is user for integer type printf("Enter IInd integer value :     +"); scanf("%d",&b); sum=a+b;                                                            // assign total to sum printf("\t\t\t\t--\nSum is\t\t\t        %d",sum);           // print sum getch(); } The name a, b and sum are the names of variables -- location in memory where values can be stored for use by a program. These definations specify that variables a , b and sum

Introduction of C programming language

Image
Programming Rules :- A programmer while writing a program should follow following rules. Every program should have main() function. C statements should be terminated by a semi-colon (;). At some place, a comma operator is permitted. If only a semi-colon is placed it is treated as a statement. For example:-                          while(condition)                          ; The above statement generates infinite loop. Without semi-colon the loop will not execute. An unessential semicolon if placed by the programmer is treated as an empty statement. All statements should be written in lowercase letters. Generally, uppercase letter are used only for symbolic constants. Blank space my be inserted between the words. This leads to improvement in the read-ability of the statements. However this is not applicable while declaring a variable, keyword, constant and function. It is not necessary to fin the position of statement in the program; i.e. a programmer can write the stateme