Escolar Documentos
Profissional Documentos
Cultura Documentos
SQL Programs
1. Create a table of Students
2. Display those who have PCM
3. Display average marks of all students
4. Display info of those whose marks lie in 90 to
100
5. Display info of those who have Commerce
and have marks greater than 85
6. Display info of those who doesn’t have PCB
7. Display info of those whose name starts with
the letter K
8. Filter Names Having 6 letters
9. Add a Column of max marks having value 100
10. Sort the table according to marks
11. Find total number of students
12. Find total Number of streams
13. Find Maximum marks of all the streams
Armstrong Number
#include <iostream.h>
#include <conio.h>
#include <stdlib.h>
void main()
clrscr();
int i,l=0,num,s=0;
i=num;
while (i>0)
l = i%10;
s = s+ (l*l*l);
i = i/10;
if (s==num)
else
}
getch();
}
Remove Duplicates from array
#include <iostream.h>
#include <conio.h>
void main()
clrscr();
int a[50];
int n, i, j, count=0;
cout << "How Many Numbers Do You Want To Enter?(Max 50): ";
cin >> n;
cout << "Enter Number " << i+1 << ": ";
{
if (a[i] == a[j])
a[j] = 0;
j=0;
if (a[i] == 0)
count++;
if (a[i] != 0)
a[j] = a[i];
j++;
}
for (i= (n - count); i<n; i++)
a[i] = 0;
getch();
}
Convert Decimal TO Binary
#include <stdio.h>
#include<conio.h>
#include<iostream.h>
int main()
clrscr();
int n,p,c,k,count=0;
cin>>n;
p=n;
while(p)
p=p/10;
count++;
if (count=1)
count=2;
c=count*count*count;
k = n >> c;
if (k & 1)
cout<<"1";
else
cout<<"0";
}
cout<<"\n";
getch();
return 0;
}
Hangman Game
#include <conio.h>
#include <iostream.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
char secret_name[15];
char name_entered[15];
int chnc = 5;
void init_name()
secret_name[i] = '\0';
};
void disp_screen()
int i;
gotoxy(3,12);
};
void main()
clrscr();
int i, lvl, l, n;
char ch;
cout << "\n\nThere Are Three Levels To Choose From.\nThen There Comes A Series Of Asteriks and You Have To
Uncover Them By Guessuing The Word Letter By Letter.If You Guess The Correct Letter The Asterik Will Be
Uncovered.\nYou HAve 5 Chances To Do That!.\nAll The Best!";
switch (lvl)
case 1: randomize();
n = random(10000) % 3;
break;
case 2: randomize();
n = random(10000) % 3 + 3;
break;
case 3: randomize();
n = random(10000) % 3 + 6;
break;
}
strcpy(name_entered, countries[n]);
l = strlen(name_entered);
secret_name[i] = '*';
int count = 0;
clrscr();
disp_screen();
if (toupper(ch) == name_entered[i])
secret_name[i] = toupper(ch);
count++;
if (count == 0)
chnc--;
}
if (chnc == 0)
goto finish;
disp_screen();
gotoxy(3, 14);
finish: getch();
}
Chances: 5
HHHHHHHHUU
nter A Guess:
Chances: S
t1JZAMB IQUE
#include <conio.h>
#include <stdlib.h>
#include <ctype.h>
void main()
clrscr();
int ch;
char choice;
<< "\nThe Computer Generates A Number And You Have To Guess The Number 0 < n < 1000"
<< "\nThe Computer Will Then Tell You If Its Higher Or Lower Than The Actual Number"
ch = 2;
goto play;
exit(0);
case 2: clrscr();
count = 0;
randomize();
n = random(10000);
n = n % 1000;
while (guess != n)
if (guess > n)
count ++;
cout << "Congartulations! You Took " << count + 1 << " Number Of Guesses";
if (toupper(choice) == 'Y')
ch = 2;
goto play;
break;
getch();
}
LCM of 2 Numbers
#include <iostream.h>
#include <conio.h>
void main()
clrscr();
while (n % n1 != 0)
n = n2 * i;
i++;
getch();
}
Pattern
#include <iostream.h>
#include <conio.h>
void main()
clrscr();
int i, j;
getch();
}
Permutation And Combination
#include <iostream.h>
#include <conio.h>
#include <math.h>
float fact(int a)
int i;
float ans=1;
ans = ans * i;
return ans;
float ans;
return ans;
float ans;
ans = fact(n) / (fact(n-r) * fact(r));
return ans;
void main()
clrscr();
int ch, n, r;
switch (ch)
case 1: clrscr();
cin >> n;
cin >> r;
break;
case 2: clrscr();
cin >> r;
break;
getch();}
Get A Number Of Unique Random Numbers
#include <iostream.h>
#include <stdlib.h>
#include <conio.h>
void main()
clrscr();
a[i] = 0;
cin >> n;
again: randomize();
{
if (a[j] == rand_no)
goto again;
a[i] = rand_no;
getch();
}
To reverse An Array Of Numbers
#include <iostream.h>
#include <conio.h>
void main()
clrscr();
int a[50], n, i;
cin >> n;
cout << "Enter Number " << i+1 << ": ";
getch();
}
Enter Number Of Elements: 5
Enter Number 1: 1
Enter Number z: 3
Enter Number 3: 5
Enter Number 4: 7
Enter Number 5: 9
9
7
5
3
1
To Reverse An Array of Letters
#include <iostream.h>
#include <string.h>
#include <dos.h>
#include <conio.h>
void main()
clrscr();
char text[20];
int l;
int i;
l = strlen(text);
for (i = l; i >= 0 ; i -= 1)
getch();
}
•
1
Sorting An Array
#include <iostream.h>
#include <conio.h>
void main()
clrscr();
cin >> n;
cout << "Enter Number " << i+1 << ": ";
temp = num[i];
num[i] = num[j];
num[j] = temp;
}
cout << "\n\nThe Sorted Array Is: \n";
getch();
}
Starline Pattern
#include <iostream.h>
#include <conio.h>
int i;
cout << a;
};
void main()
clrscr();
int n;
char a;
cin >> a;
cin >> n;
starline (a,n);
getch();
nter Character: f
ow Many Times Do You Want It To Repeat?: 20
fffffffffffffffffff
Check For Palindrome
#include <iostream.h>
#include <conio.h>
#include <string.h>
#include <stdio.h>
void main()
clrscr();
cin >> a;
strcpy(a1,a);
strrev(a);
if (strcmpi(a, a1) == 0)
else
getch();
}
Sorting Of Structure
#include <iostream.h>
#include <conio.h>
#include <stdio.h>
#include <string.h>
#include <iomanip.h>
struct stud
int roll;
char name[20];
int marks;
};
void main()
clrscr();
stud s[10];
stud temp;//Temp Will Be Of Student Type as we have to sort whole student data.Not OF Int!
int i, n, j;
cin >> n;
cout << "\nEnter Roll No of Student " << i+1 << ": ";
gets(s[i].name);
cout << "Enter Marks of Student " << i+1 << ": ";
temp = s[i];
s[i] = s[j];
s[j] = temp;
clrscr();
cout << setw(7) << "Roll No" << setw(20) << "Name" << setw(7) << "Marks" << endl;
cout << setw(7) << s[i].roll << setw(20) << s[i].name << setw(7) << s[i].marks << endl;
Getch();
TI1e Sorted List Is
Roll No Name Marks
6 Ishita 90
10 Parth 90
13 Shashwat 90
11 Tl.tshar 90
15 Utkarsh 90
Tic Tac Toe Game
#include <iostream.h>
#include <conio.h>
#include <dos.h>
#include <ctype.h>
char board[9] = {'1', '2', '3', '4', '5', '6', '7', '8', '9'};
char p[2][20];
void init_board()
board[0] = '1';
board[1] = '2';
board[2] = '3';
board[3] = '4';
board[4] = '5';
board[5] = '6';
board[6] = '7';
board[7] = '8';
board[8] = '9';
};
void disp_board ()
int i;
<< p[0] << " <x> " << p[1] << " <o>" << "\n\n";
if (i%3 == 0)
};
int chk_win ()
int i;
if (board[i] == 'x')
return 1;
{
if (board[i] == board[i+3] && board[i+3] == board[i+6])
if (board[i] == 'x')
return 1;
if (board[0] == 'x')
return 1;
if (board[2] == 'x')
{
cout << p[0] << " WINS!!";
return 1;
return 0;
};
void main()
again: clrscr();
char a;
init_board();
delay (800);
clrscr();
disp_board();
c = i%2;
delay(600);
i--;
else
if (c == 0)
board[ch-1] = 'x';
else if (c == 1)
board[ch-1] = 'o';
clrscr();
disp_board();
if (chk_win() == 1)
break;
else
count ++;
if (count == 9)
cin >> a;
if (toupper(a) == 'Y')
goto again;
getch();
}
Linear Search
#include<iostream.h>
#include<conio.h>
void main()
clrscr();
int arr[15],i,num,pos=0;
for(i=0;i<10;i++)
cin>>arr[i];
cin>>num;
for(i=0;i<10;i++)
if(num==arr[i])
pos=i+1;
if(pos==0)
getch();
Binary Search
#include<iostream.h>
#include<conio.h>
void main()
clrscr();
mid=(beg+last)/2;
for(i=0;i<10;i++)
cin>>arr[i];
cin>>num;
while(beg<last)
if(arr[mid]==num)
pos=mid+1;
else if(arr[mid]<num)
beg=mid+1;
else if(arr[mid]>num) last=mid-
1;
mid=(beg+last)/2;
if(pos==0)
getch();
}
Insertion In a Sorted Array
#include<iostream.h>
#include<conio.h>
int arr[15];
int findpos(int x)
int pos;
for(int i=0;i<10;i++)
pos=++i;
return pos;
void main()
clrscr();
int i,num,location;
for(i=0;i<10;i++)
cin>>arr[i];
cin>>num;
location=findpos(num);
for(i=11;i>location;i--)
arr[i]=arr[i-1];
arr[location]=num;
for(i=0;i<11;i++)
cout<<arr[i]<<" ";
getch();
}
Deletion from An Array
#include<iostream.h>
#include<conio.h>
int arr[10];
int findpos(int x)
int pos=0;
for(int i=0;i<10;i++)
if(arr[i]==x)
pos=++i;
return pos;
void main()
clrscr();
int i,num,location;
for(i=0;i<10;i++)
cin>>arr[i];
cin>>num;
location=findpos(num);
if (location==0)
for(i=0;i<10;i++)
cout<<arr[i]<<" ";
else
for(i=location-1;i<9;i++)
arr[i]=arr[i+1];
for(i=0;i<9;i++)
cout<<arr[i]<<" ";
getch();
}
Traversal In An Array
#include<iostream.h>
#include<conio.h>
void main()
clrscr();
int a[10],i;
for(i=0;i<10;i++)
cin>>a[i];
for(i=0;i<10;i++)
cout<<a[i]<<" ";
getch();
}
Input And Display Members OF 2D array In
Matrix Form
#include<iostream.h>
#include<conio.h>
void main()
clrscr();
int a[3][3],i,j;
for(i=0;i<3;i++)
for(j=0;j<3;j++)
cin>>a[i][j];
for(i=0;i<3;i++)
for(j=0;j<3;j++)
cout<<a[i][j]<<" ";
if(j==2)
cout<<endl;
getch();
}
i
To Find Row Sum Of Matrix
#include<iostream.h>
#include<conio.h>
void main()
clrscr();
int a[3][3],i,j,r,sum=0;
for(i=0;i<3;i++)
for(j=0;j<3;j++)
cin>>a[i][j];
cin>>r;
for(i=0;i<3;i++)
for(j=0;j<3;j++)
if(i==r-1)
sum+=a[i][j];
getch();
}
sum
To Find Column Sum Of A Matrix
#include<iostream.h>
#include<conio.h>
void main()
clrscr();
int a[3][3],i,j,r,sum=0;
for(i=0;i<3;i++)
for(j=0;j<3;j++)
cin>>a[i][j];
cin>>r;
for(i=0;i<3;i++)
for(j=0;j<3;j++)
if(j==r-1)
sum+=a[i][j];
getch();
sum i
To Find Diagonal Sum Of A Matrix
#include<iostream.h>
#include<conio.h>
void main()
clrscr();
int a[3][3],i,j,r,sum1=0,sum2=0;
for(i=0;i<3;i++)
for(j=0;j<3;j++)
cin>>a[i][j];
for(i=0;i<3;i++)
for(j=0;j<3;j++)
if(i==j)
sum+=a[i][j];
getch();
Create A File
#include <fstream.h>
#include <conio.h>
#include <stdio.h>
#include <iomanip.h>
#include <string.h>
#include <process.h>
class student
public:
int roll;
char name[20];
int marks;
void input()
gets(name);
void display()
{
cout << setw (7) << roll << setw (10) << name << setw (8) << marks << endl;
};
void main()
clrscr();
int n2;
student s1;
fstream f;
switch (n2)
case 1: cout << "Enter Name Of File (Add '.txt' at end): ";
gets(fname);
gets (str);
f << str;
f.close();
getch();
break;
case 2: cout << "Enter Name Of File (Add '.dat' at end): ";
gets(fname);
do
s1.input();
f.close();
getch();
break;
}
Append a File
#include <fstream.h>
#include <conio.h>
#include <stdio.h>
#include <iomanip.h>
#include <string.h>
#include <dos.h>
#include <process.h>
class student
public:
int roll;
char name[20];
int marks;
void input()
gets(name);
void display()
{
cout << setw (7) << roll << setw (10) << name << setw (8) << marks << endl;
};
void main()
clrscr();
int n2;
student s1;
fstream forg;
switch (n2)
case 1: cout << "Enter Name Of File (Add '.txt' at end): ";
gets(fname);
getch();
break;
do
gets (str);
forg.close();
getch();
break;
case 2: cout << "Enter Name Of File (Add '.dat' at end): ";
gets(fname);
if (!forg)
{
cout << "File Doesnt Exist!!";
getch();
break;
do
s1.input();
forg.close();
getch();
break;
}
Read A File
#include <fstream.h>
#include <conio.h>
#include <stdio.h>
#include <iomanip.h>
#include <string.h>
#include <dos.h>
#include <process.h>
class student
public:
int roll;
char name[20];
int marks;
void input()
gets(name);
void display()
{
cout << setw (7) << roll << setw (10) << name << setw (8) << marks << endl;
};
void main()
clrscr();
int n2;
student s1;
fstream f;
cout << "Enter Name Of File You Want To Read From: ";
gets(fname);
cout << setw (7) << "Roll No" << setw (10) << "Name" << setw (8) << "Marks" << endl;
s1.display();
getch();
Copy A File
#include <fstream.h>
#include <conio.h>
#include <stdio.h>
#include <iomanip.h>
#include <string.h>
#include <dos.h>
#include <process.h>
class student
public:
int roll;
char name[20];
int marks;
void input()
gets(name);
void display()
{
cout << setw (7) << roll << setw (10) << name << setw (8) << marks << endl;
};
void main()
clrscr();
student s1;
fstream f, fnew;
cout << "Enter Name Of File You Want To Copy FROM: ";
gets(fname);
if(!f)
getch();
cout << "Enter Name Of File You Want To Copy TO: ";
gets(fname);
fnew.open (fname, ios::out | ios::binary | ios::noreplace);
if(!fnew)
getch();
f.close();
fnew.close();
getch();
}
Search In A File
#include <fstream.h>
#include <conio.h>
#include <stdio.h>
#include <iomanip.h>
#include <string.h>
#include <dos.h>
#include <process.h>
class student
public:
int roll;
char name[20];
int marks;
void input()
gets(name);
void display()
{
cout << setw (7) << roll << setw (10) << name << setw (8) << marks << endl;
};
void main()
clrscr();
long pos;
cout << "Enter The Name Of The File (Add '.dat'): ";
gets(fname);
if (!forg)
getch();
break;
}
cout << "Okay!";
delay (500);
clrscr();
switch (n2)
case 1: clrscr();
gets (str1);
cout << setw (7) << "Roll No" << setw (10) << "Name" << setw (8) << "Marks" << endl;
s1.display();
break;
break;
case 2: clrscr();
cin >> n;
cout << setw (7) << "Roll No" << setw (10) << "Name" << setw (8) << "Marks" << endl;
if (s1.roll == n)
s1.display();
break;
break;
forg.close();
getch();
}
Modification Of File
#include <fstream.h>
#include <conio.h>
#include <stdio.h>
#include <iomanip.h>
#include <string.h>
#include <dos.h>
#include <process.h>
class student
public:
int roll;
char name[20];
int marks;
void input()
gets(name);
void display()
{
cout << setw (7) << roll << setw (10) << name << setw (8) << marks << endl;
};
void main()
clrscr();
long pos;
cout << "Enter The Name Of The File (Add '.dat'): ";
gets(fname);
delay (500);
forg.close();
clrscr();
cout << "1. By Name"
do
switch (n2)
gets(str);
if (strcmpi(s1.name, str) == 0)
break;
break;
case 2: cout << "Enter Roll number You Want To Edit: ";
cin >> n;
while (forg.read ((char *) &s1, sizeof(s1)))
if (s1.roll == n)
break;
break;
case 3: cout << "Enter Record Number You Want To Modify With: ";
cin >> n;
break;
forg.seekg(pos);
s1.input();
clrscr();
cout << setw (7) << "Roll No" << setw (10) << "Name" << setw (8) << "Marks" << endl;
forg.close();
s1.display();
forg.close();
getch();
}
Delete A Record
#include <fstream.h>
#include <conio.h>
#include <stdio.h>
#include <iomanip.h>
#include <string.h>
#include <dos.h>
#include <process.h>
class student
public:
int roll;
char name[20];
int marks;
void input()
gets(name);
void display()
{
cout << setw (7) << roll << setw (10) << name << setw (8) << marks << endl;
};
void main()
clrscr();
long pos;
cout << "Enter The Name Of The File (Add '.dat'): ";
gets(fname);
delay (500);
clrscr();
switch (n2)
gets(str);
if (strcmpi(str, s1.name) != 0)
break;
case 2: cout << "Enter Roll Number Of Record You Want To Delete: ";
cin >> n;
if (s1.roll != n)
}
}
break;
case 3: cout << "Enter The Record Number You Want To Delete: ";
cin >> n;
i++;
if (i != n)
break;
forg.close();
fnew.close();
remove (fname);
cout << setw (7) << "Roll No" << setw (10) << "Name" << setw (8) << "Marks" << endl;
forg.open (fname, ios::in | ios::binary);
s1.display();
forg.close();
getch();
}
Insert A Record
#include <fstream.h>
#include <conio.h>
#include <stdio.h>
#include <iomanip.h>
#include <string.h>
#include <dos.h>
#include <process.h>
class student
public:
int roll;
char name[20];
int marks;
void input()
gets(name);
void display()
{
cout << setw (7) << roll << setw (10) << name << setw (8) << marks << endl;
};
void main()
clrscr();
long pos;
cout << "Enter The Name Of The File (Add '.dat'): ";
gets(fname);
cout << "Enter The Roll Number After Which You Want To Add: ";
cin >> n;
s2.input();
forg.close();
fnew.close();
remove (fname);
cout << setw (7) << "Roll No" << setw (10) << "Name" << setw (8) << "Marks" << endl;
s1.display();
forg.close();
getch();
}
Sorting A File
#include <fstream.h>
#include <conio.h>
#include <stdio.h>
#include <iomanip.h>
#include <string.h>
#include <dos.h>
#include <process.h>
class student
public:
int roll;
char name[20];
int marks;
void input()
gets(name);
void display()
{
cout << setw (7) << roll << setw (10) << name << setw (8) << marks << endl;
};
void main()
clrscr();
long pos;
cout << "Enter The Name Of The File (Add '.dat'): ";
gets(fname);
s3[i] = s1;
i++;
temp = s3[k];
s3[k] = s3[j];
s3[j] = temp;
cout << setw (7) << "Roll No" << setw (10) << "Name" << setw (8) << "Marks" << endl;
forg.close();
s3[j].display();
forg.close();
getch();
}
Rename A File
#include <fstream.h>
#include <conio.h>
#include <stdio.h>
void main()
clrscr();
gets(str);
gets(str1);
rename(str, str1);
getch();
}
Link List As A Stack
#include <iostream.h>
#include <conio.h>
struct node
int e;
node* link;
};
class stack
public:
stack()
top = NULL;
~stack()
while(ptr != NULL)
ptr = top;
top = top->link;
delete ptr;
}
void push();
void display();
void pop();
};
void stack::push()
>link = NULL;
if (top == NULL)
top = ptr;
else
ptr->link = top;
top = ptr;
void stack::display()
if (top == NULL)
else
{
ptr = top;
ptr = ptr->link;
void stack::pop()
ptr = top;
if (top == NULL)
else
top = top->link;
delete ptr;
void main()
stack s1;
int n;
do
clrscr();
cin >> n;
switch(n)
case 1: clrscr();
s1.push();
break;
case 2: clrscr();
s1.display();
getch();
break;
case 3: clrscr();
s1.pop();
getch();
break;
}while (n!=4);
getch();
}
Link List As A Queue
#include <iostream.h>
#include <conio.h>
struct node
int e;
node* link;
};
class queue
public:
queue()
rear = NULL;
front = NULL;
void queins();
void quedel();
void quedisp();
};
void queue::queins()
>link = NULL;
cout << "Enter Element: ";
if (rear == NULL)
else
rear->link = ptr;
rear = ptr;
void queue::quedisp()
if (front == NULL)
else
ptr = front;
while (ptr!=NULL)
ptr = ptr->link;
}
void queue::quedel()
ptr = front;
if (front == NULL)
else
front = front->link;
delete ptr;
if (front == NULL)
rear = NULL;
void main()
queue q1;
int n;
do
{
clrscr();
cin >> n;
switch(n)
case 1: clrscr();
q1.queins();
break;
case 2: clrscr();
q1.quedisp();
getch();
break;
case 3: clrscr();
q1.quedel();
getch();
break;
}while (n!=4);
miN MENU
1. Insert
2. Display Enter Element: Zl
3. Delete
14. Exit
our Choice: 1
miN MENU
1. Insert
- Display
- Delete
!4. Exit
fe 21 22
our Choice: 2_
miN MENU
1. Insert
- Display
- Delete
lerrent: 20
14 . Exit
1 e leted-
our Choice: 3
Table For SQL Programs
CREATE A TABLE OF STUDENTS
Display those Having PCM
Display Average Marks Of All Students
Display Info Of those whose marks lie in
90 to 100
Display info of those who have commerce
and have marks greater than 85
Display Info Of those who doesn’t have
PCB
Display Info Of those whose name Starts
with “K”
Filter Names Having 6 Letters
Add A column Of Max Marks having value
100
Sort Table By Marks
Find Total Number Of Students
Find Total Number Of Streams
Find Maximum Marks OF All The Streams