Select Clauses in SQL Part1

SQL> create table student_master(Name varchar(20),Reg_no number(5),dept varchar(20),year number(4));
Table created.
SQL> insert into student_master values('&name',&Reg_no,'&dept', &year);
Enter value for name: Navin
Enter value for reg_no: 001
Enter value for dept: BCA
Enter value for year: 1991
old   1: insert into student_master values('&name',&Reg_no,'&dept', &year)
new   1: insert into student_master values('Navin',001,'BCA', 1991)
1 row created.
SQL> /
Enter value for name: Neenu
Enter value for reg_no: 002
Enter value for dept: BCA
Enter value for year: 1989
old   1: insert into student_master values('&name',&Reg_no,'&dept', &year)
new   1: insert into student_master values('Neenu',002,'BCA', 1989)
1 row created.
SQL> /
Enter value for name: XXX
Enter value for reg_no: 003
Enter value for dept: BCA
Enter value for year: 1990
old   1: insert into student_master values('&name',&Reg_no,'&dept', &year)
new   1: insert into student_master values('XXX',003,'BCA', 1990)
1 row created.
SQL> SELECT * FROM STUDENT_MASTER;
NAME             REG_NO DEPT                  YEAR
---------------- ---------- ---------------- ----------
Navin            1 BCA                        1991
Neenu            2 BCA                        1989
XXX              3 BCA                        1990
SQL> SELECT NAME FROM STUDENT_MASTER;
NAME
--------------------
Navin
Neenu
XXX
SQL> SELECT DISTINCT (REG_NO),NAME,DEPT,YEAR FROM STUDENT_MASTER;
REG_NO NAME            DEPT              YEAR
----- ---------------- ----------------- ----------
    1 Navin            BCA               1991
    2 Neenu            BCA               1989
    3 XXX              BCA               1990
SQL> SELECT DISTINCT * FROM STUDENT_MASTER ORDER BY REG_NO DESC;
NAME           REG_NO     DEPT     YEAR
-------------- ---------- -------- ----------
XXX                     3 BCA      1990
Neenu                   2 BCA      1989
Navin                   1 BCA      1991
SQL> SELECT * FROM STUDENT_MASTER  WHERE DEPT = 'BCA';
NAME           REG_NO     DEPT     YEAR


-------------- ---------- -------- ----------
XXX                     3 BCA      1990
Neenu                   2 BCA      1989
Navin                   1 BCA      1991

To Search A Record Using Functions

SQL> create table phonebook(phone_no number(10),user_name varchar(20),address varechar(30));
Table created.

SQL> insert into phonebook values(&no,'&name','&add');
Enter value for no: 2249616
Enter value for name: xxx
Enter value for add: asdf
old   1: insert into phonebook values(&no,'&name','&add')
new   1: insert into phonebook values(001,'xxx','vellore')
1 row created.
SQL> /
Enter value for no: 234567
Enter value for name: yyy
Enter value for add: asdfg
old   1: insert into phonebook values(&no,'&name','&add')
new   1: insert into phonebook values(234567,'yyy','madurai')
1 row created.
SQL> /
Enter value for no: 34567
Enter value for name: zzzz
Enter value for add: asdfghjk
old   1: insert into phonebook values(&no,'&name','&add')
new   1: insert into phonebook values(34567,'zzzz','chennai')
1 row created.
SQL> set serveroutput on

// Function decleration
SQL> create or replace function search(no in number) return varchar is ad varchar(30);
  2   begin
  3   select address into ad from phonebook where phone_no=no;
  4   return ad;
  5   end;
  6  /
Function created.
//function call
SQL>  set serveroutput on
SQL>  declare addd varchar(20);
  2   begin
  3   select search(phone_no) into addd from phonebook where phone_no =2249616;
  4   dbms_output.put_line(addd);
  5   end;
  6   /
PL/SQL procedure successfully completed.
SQL> select * from phonebook;
  PHONE_NO USER_NAME            ADDRESS
---------- -------------------- ------------------------------
  2249616  xxx                  vellore
    

Deleting From Table

//MASTER TABLE
SQL> select * from student_register;
    REG_NO NAME             CLASS                REMARKS
---------- ---------------- -------------------- ----------
         1 xxx              BCA                  GOOD
         2 YYY              BBA                  DISOB
         3 ZZZ              BCA                  GOOD
         4 AAA              BSC                  BAD
         5 BBB              BCA                  BAD
SQL> delete from student_register where class = 'BSC';
1 row deleted.
//TABLE AFTER DELETION
SQL> select * from student_register;
REG_NO NAME              CLASS             REMARKS
----- ------------------ ----------------- -------------
    1 xxx                BCA               GOOD
    2 YYY                BBA               DISOB
    3 ZZZ                BCA               GOOD
    5 BBB                BCA               BAD
SQL> 

Inserting Into Table2

//use  & to display domain name
SQL> insert into student_register values(&Rgno,'&name','&Class','&remarks');
Enter value for rgno: 001
Enter value for name: xxx
Enter value for class: 3rd-A
Enter value for remarks: good
old   1: insert into student_register values(&Rgno,'&name','&Class','&remarks')
new   1: insert into student_register values(001,'xxx','3rd-A','good')
1 row created.
// use / to run the query again 
SQL> /
Enter value for rgno: 002
Enter value for name: yyy
Enter value for class: 2nd-B
Enter value for remarks: talkitive
old   1: insert into student_register values(&Rgno,'&name','&Class','&remarks')
new   1: insert into student_register values(002,'yyy','2nd-B','talkitive')
1 row created.
SQL>  select * from student_register;
    REG_NO NAME             CLASS                REMARKS
---------- ---------------- -------------------- ---------      
         1 xxx              3rd-A                good
         2 yyy              2nd-B                talkitive
SQL> 

Inserting Into Table1

SQL> insert into student_register values(001,'xxx','3rd-A','Good');
1 row created.
SQL> insert into student_register values(002,'yyy','2nd-B','Talkit');
1 row created.
SQL> select * from student_register;
    REG_NO NAME                 CLASS                REMARKS
---------- -------------------- -------------------- ----------
         1 xxx                  3rd-A                Good
         2 yyy                  2nd-B                Talkit

CREATING A TABLE

SQL> create table student_register(Reg_no number(10), Name varchar(20), class varchar(20), Remarks varchar(40));
Table created.
//To see table description
SQL> desc student_Register;
 Name                     Null?    Type
 ------------------------ -------- ---------
 REG_NO                            NUMBER(10)
 NAME                              VARCHAR2(20)
 CLASS                             VARCHAR2(20)
 REMARKS                           VARCHAR2(40)

NESTED IF IN COBOL

       IDENTIFICATION DIVISION.
       PROGRAM-ID. FIBONACCI.
       ENVIRONMENT DIVISION.
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       77 A PIC S99 VALUE -1.
       77 B PIC 99 VALUE 1.
       77 C PIC 99 VALUE 1.
       PROCEDURE DIVISION.
       PARA1.
           DISPLAY "ENTER THE VALUE OF A".
           ACCEPT A.
           DISPLAY "ENTER THE VALUE OF B".
           ACCEPT B.
           DISPLAY "ENTER THE VALUE OF C".
           ACCEPT C.
           IF A > B
               IF A > C
                   DISPLAY " A IS GREATER"
               ELSE
                   DISPLAY "C IS GREATER"
           ELSE IF B > C
               DISPLAY "B IS GREATER"
               ELSE DISPLAY "C IS GREATER".
           STOP RUN.
       

GREATER OF 2 NUMBERS

       IDENTIFICATION DIVISION.
       PROGRAM-ID. FIBONACCI.
       ENVIRONMENT DIVISION.
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       77 A PIC S99 VALUE -1.
       77 B PIC 99 VALUE 1.
       77 C PIC 99 VALUE 1.
       PROCEDURE DIVISION.
       PARA1.
           DISPLAY "ENTER THE VALUE OF A".
           ACCEPT A.
           DISPLAY "ENTER THE VALUE OF B".
           ACCEPT B.
           IF A > B
               DISPLAY " A IS GREATER"
           ELSE
               DISPLAY "B IS GREATER"
           STOP RUN.
       

FIBONACCI

       IDENTIFICATION DIVISION.
       PROGRAM-ID. FIBONACCI.
       ENVIRONMENT DIVISION.
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       77 A PIC S99 VALUE -1.
       77 B PIC 99 VALUE 1.
       77 C PIC 99.
       77 N PIC 99.
       77 N1 PIC 99 VALUE 0.
       PROCEDURE DIVISION.
       PARA1.
           DISPLAY "ENTER A NUMBER".
           ACCEPT N.
           PERFORM PARA2 UNTIL N1 = N.
           STOP RUN.
       PARA2.
           COMPUTE C = A + B;
           DISPLAY C.
           MOVE B TO A.
           MOVE C TO B.
           ADD 1 TO N1.

Reversing An Array

#include <stdio.h>
#define NMAX 10

void intSwap(int *x, int *y);
int getIntArray(int a[], int nmax, int sentinel);
void printIntArray(int a[], int n);
void reverseIntArray(int a[], int n);

int main(void) {
  int x[NMAX];
  int hmny;

  hmny = getIntArray(x, NMAX, 0);
  printf("The array was: \n");
  printIntArray(x,hmny);
  reverseIntArray(x,hmny);
  printf("after reverse it is:\n");
  printIntArray(x,hmny);
}

void intSwap(int *x, int *y)
{
  int temp = *x;
  *x = *y;
  *y = temp;
}

void printIntArray(int a[], int n)
{
  int i;

  for (i=0; i<n; ){
    printf("\t%d ", a[i++]);
    if (i%5==0)
      printf("\n");
  }
  printf("\n");
}

int getIntArray(int a[], int nmax, int sentinel)
{
  int n = 0;
  int temp;

  do {
    printf("Enter integer [%d to terminate] : ", sentinel);
    scanf("%d", &temp);
    if (temp==sentinel) break;
    if (n==nmax)
      printf("array is full\n");
    else 
      a[n++] = temp;
  }while (1);
  return n;
}

void reverseIntArray(int a[], int n)
{
  int i;

  for(i=0;i<n/2;i++){
    intSwap(&a[i],&a[n-i-1]);
  }
}

Using Function Scopes

#include <stdio.h>
#include <conio.h>
int x = 2;
int y = 3;
int z = 4;
void fun(int x, int *y)
{
  int z;
  x = x+3;
  *y = *y+3;
  z = z+3;  
  printf("fun:  x = %1d, *y = %1d, y = %1d, z = %1d\n", x,*y,y,z);
}
int main(void){
  moo(x, &y);
  printf("main: x = %1d1, y = %1d, z = %1d\n", x,y,z);
}

Simple Array

#include <stdio.h>

int main(void) 
{
  int a[2] = {1,2};  
  int b[2] = {2,3};
  int i;
  for(i=0;i<2;i++)
    a[i]=b[i];
  if(a==b)
    printf("They are equal\n");
  else
    printf("They are not equal\n");
  }

Effects of the scope

#include <stdio.h>

int a=0;    /* This is a global variable */

void fun(void);

int main(void) {
  int a=2;  /* This is a variable local to main */
  int b=3;  /* This is a variable local to main */

  printf("1. main_b = %d\n", b);
  printf("main_a = %d\n", a);
  foo();
  printf("2. main_b = %d\n", b);
}

void fun(void){
  int b=4;  /* This is a variable local to foo */

  printf("foo_a = %d\n", a);
  printf("foo_b = %d\n", b);
}

ADDING SEQUENCE OF +VE NUMBERS

#include <stdio.h>
#define N 0

int main(void) {
  int sum = 0; 
  int current; 

  do {
    printf("\n Enter an integer > ");
    scanf("%d", &current);
    if (current > N)
      sum = sum + current;
  } while (current > N);
  printf("\nThe sum is %d\n", sum);
}

VALUE OF TRUE AND FALSE IN C

#include <stdio.h>

 int main(void) {
    printf("The value of 1<2 is %d\n", (1<2));
    printf("The value of 2<1 is %d\n", (2<1));
 }

 /* output

 The value of 1<2 is 1
 The value of 2<1 is 0

*/

Ledger Report Validation.

       IDENTIFICATION DIVISION.
       PROGRAM-ID. LEDGER.
       ENVIRONMENT DIVISION.
       INPUT-OUTPUT SECTION.
       FILE-CONTROL.
           SELECT INFILE ASSIGN TO DISK
           ORGANIZATION IS LINE SEQUENTIAL.
           SELECT OUTFILE ASSIGN TO DISK
           ORGANIZATION IS LINE SEQUENTIAL.
       DATA DIVISION.
       FILE SECTION.
       FD INFILE
           LABEL RECORDS ARE STANDARD
           VALUE OF FILE-ID IS "LEDIN.TXT".
       01 ACC-REC.
           02 RC PIC X(2).
               88 VALID-RC  VALUE "LM".
           02 ACC-NO.
               03 FNO PIC X(5).
               03 LNO PIC X(3).
           02 ACC-DESC.
               03 FNAME PIC X.
               03 REST-NAME PIC X(19).
           02 ACC-TYPE PIC X.
               88 VALID-ACC-TYPE VALUES ARE
                   'X' '1' '2' '3' '4' '5' '6'.
           02 ACC-BALANCE PIC X(8).
       FD OUTFILE
           LABEL RECORDS ARE STANDARD
           VALUE OF FILE-ID IS "LEDOUT.TXT".
       01 OUTREC PIC X(80).
       WORKING-STORAGE SECTION.
       01 H1.
           05 F PIC X(28) VALUE SPACES.
           05 F PIC X(28) VALUE "LEDGER RECORDS VALIDATION".
       01 H11.
           05 F PIC X(28) VALUE SPACES.
           05 F PIC X(28) VALUE "AUDIT/ERROR LIST".
       01 H2.
           05 F PIC X(2) VALUE "RC".
           05 F PIC X(5) VALUE SPACES.
           05 F PIC X(6) VALUE "NUMBER".
           05 F PIC X(5) VALUE SPACES.
           05 F PIC X(11) VALUE "DESCRIPTION".
           05 F PIC X(5) VALUE SPACES.
           05 F PIC X(5) VALUE "TYPE".
           05 F PIC X(5) VALUE SPACES.
           05 F PIC X(10) VALUE "BALANCE".
           05 F PIC X(5) VALUE SPACES.
           05 F PIC X(15) VALUE "ERROR CODES".
       01 D-REC.
           02 RC PIC X(2).
           02 F PIC X(5) VALUE SPACES.
           02 ACC-NO-O.
               03 FNO-O PIC X(5).
               03 LNO-O PIC X(3).
           02 F PIC X(5) VALUE SPACES.
           02 ACC-DESC-O.
               03 FNAME PIC X.
               03 REST-NAME PIC X(19).
           02 F PIC X(5) VALUE SPACES.
           02 ACC-TYPE PIC X.
           02 F PIC X(5) VALUE SPACES.
           02 ACC-BALANCE-O PIC X(8) VALUE SPACES.
           02 F PIC X(5) VALUE SPACES.
           02 ERR.
               10 ERR-CODE1 PIC X VALUE SPACES.
               10 ERR-CODE2 PIC X VALUE SPACES.
               10 ERR-CODE3 PIC X VALUE SPACES.
               10 ERR-CODE4 PIC X VALUE SPACES.
               10 ERR-CODE5 PIC X VALUE SPACES.
               10 ERR-CODE6 PIC X VALUE SPACES.
       01 BLANK-SPACE PIC X(80) VALUE SPACES.
       77 CHI PIC X VALUE 'Y'.
       77 EOF PIC X VALUE 'N'.
       77 LINEUSED PIC 99 VALUE 0.
       PROCEDURE DIVISION.
       MAIN-PARA.
           OPEN OUTPUT INFILE.
           PERFORM ACCEPT-PARA UNTIL CHI = 'N'.
           CLOSE INFILE.
           OPEN INPUT INFILE OUTPUT OUTFILE.
           PERFORM HEAD-PARA.
           READ INFILE AT END MOVE 'Y' TO EOF.
           PERFORM VALIDATION-PARA UNTIL EOF = 'Y'.
           CLOSE INFILE, OUTFILE.
           STOP RUN.
       ACCEPT-PARA.
           DISPLAY "ENTER THE RECORD CODE".
           ACCEPT RC OF ACC-REC.
           DISPLAY "ENTER THE ACCOUNT NUMBER".
           ACCEPT ACC-NO OF ACC-REC.
           DISPLAY "ENTER THE ACCOUNT DESCRIPTION".
           ACCEPT ACC-DESC OF ACC-REC.
           DISPLAY "ENTER THE ACCOUNT TYPE".
           ACCEPT ACC-TYPE OF ACC-REC.
           DISPLAY "ENTER THE ACCOUNT BALANCE".
           ACCEPT ACC-BALANCE OF ACC-REC.
           WRITE ACC-REC.

           DISPLAY "DO YPU WANT TO CON Y/N".
           ACCEPT CHI.
       HEAD-PARA.
           WRITE OUTREC FROM H1.
           WRITE OUTREC FROM BLANK-SPACE.
           WRITE OUTREC FROM H2.
           ADD 3 TO LINEUSED.
       VALIDATION-PARA.
           IF NOT VALID-RC MOVE 'A' TO ERR-CODE1.
           IF ACC-NO IS EQUAL TO SPACES
           MOVE 'B' TO ERR-CODE2.
           IF ACC-NO OF ACC-REC IS NUMERIC
           MOVE 'C' TO ERR-CODE3.
           IF ACC-DESC OF ACC-REC IS EQUAL TO SPACES
           MOVE 'D' TO ERR-CODE4.
           IF NOT VALID-ACC-TYPE MOVE 'E' TO ERR-CODE5.
           INSPECT ACC-BALANCE
           REPLACING LEADING SPACES BY ZEROS.
           IF ACC-BALANCE IS NOT NUMERIC
           MOVE 'F' TO ERR-CODE6.
           MOVE RC OF ACC-REC TO RC OF D-REC.
           MOVE ACC-NO OF ACC-REC TO ACC-NO-O OF D-REC.
           MOVE ACC-DESC OF ACC-REC TO ACC-DESC-O OF D-REC.
           MOVE ACC-TYPE OF ACC-REC TO ACC-TYPE OF D-REC.
           MOVE ACC-BALANCE OF ACC-REC TO ACC-BALANCE-O OF D-REC.
           WRITE OUTREC FROM D-REC.
           IF LINEUSED > 50
           MOVE 0 TO LINEUSED
           PERFORM HEAD-PARA.
           MOVE SPACES TO ERR-CODE1, ERR-CODE2, ERR-CODE3, ERR-CODE4,
           ERR-CODE5, ERR-CODE6.
           READ INFILE AT END MOVE "Y" TO EOF.


          
          
          

Why Did I Build This Blog

First of all, welcome to my blog. Make yourself at home. Don't hesitate to ask anything about programming. I'm here to try to share all my tips and tricks about programming as well as trying to help each other - including the lucky YOU...

After 5 years of programming, I finally feel how important is it to blog about all my development, problems, and solutions towards programming. Anyway, this blog only suitable for beginners and a bit advance programmer. If you're an expert programmer or so called GURU, this place is not for you. Please leave this place, go and find another place. Not this one - It's nothing if compared to you, experts :P

Why I build this blog? After half a decade, I finally realize that I'm losing so much of my tips and tricks about programming. When I tried to find some solutions on the net - when I found them - use them - and then just let them go. As a result, I forgot how to do this and that. Poor me.

Like others said, experience is expensive. It's priceless. Unfortunately, what has gone will remain gone. Here I stand, to rebuild from scratch, step by step - my personal collections of programming solutions. Hope you find every thing that you are searching for in this blog.

Regards,

Navin Shankaran...

MAKING AN INVISILE FOLDER

 I  wish to tell you about creating a folder with
no-name i.e. blank name. An invisible folder. To add fuel to the fire, wh at if we can make this
folder as Un-deletable? Sounds interesting, huh?
1. Create a  New folder.
2. Right-click on it, then choose rename.
3. After that delete the name New Folder  and press Alt key.Typ e 0160 while holding the Alt key.
Use Num-Pad for typing numerals.
4. That will create invisible space in the folder name, press Enter.
5. Right-click that folder, choose properties, then go to Customize tab.
6. Click Change Icon and then choose invisible icon. As shown in the image.
Now try deleting this invisible folder. Ohh! can’t delete it? So, what can be done to get rid of this
stupid invisible undeletable folder? Here is the trick…
1. Open a Command Prompt window. You will find a command saying:
C:\Users\Tech-Freak Stuff> where Tech-Freak Stuff will be replaced by your Username.
2. Go to the parent directory where you have saved the invisible folder. If you have saved it on
Desktop, then type:
C:\Users\Tech-Freak Stuff>cd desktop And press enter.
3. Then yo u enter  Desktop. Now type:
C:\Users\Tech-Freak Stuff\Desktop>dir/x And press enter.
4. There it will show up all the directories present on the desktop in their DOS format names(8
character names). The invisible undeletable folder will have a name like 0A00~1. Might not be
exactly same.
5. Type  rd/s [DOS NAME OF FOLDER] And press enter. For example:
C:\Users\Tech-Freak Stuff\Desktop>rd/s 0A00~1
6. A question will be asked weather  you are sure or no. Typ e Y and press  Enter. The fold er
should be deleted.

SIMPLE ADDITION

/* Add two numbers  */

#include <stdio.h>

int main(void) 
{
  int first, second;

  printf("Enter two integers > ");
  scanf("%d %d", &first, &second);
  printf("The two numbers are: %d  %d\n", first, second);
  printf("Their sum is %d\n", first+second);
}

PROPER FACTOR OR IMPROPER FACTOR

#include <stdio.h>

int main(void) 
{
  int n, 
    lcv, 
    flag; 
 
  printf("Enter value of N > ");
  scanf("%d", &n);
  for (lcv=2, flag=1; lcv <= (n / 2); lcv++) {
    if ((n % lcv) == 0) {
      if (flag)
 printf("The non-trivial factors of %d are: \n", n);
      flag = 0;
      printf("\t%d\n", lcv);
    }
  }
  if (flag)
    printf("%d is prime\n", n);
}

PRIME NUMBER

#include <stdio.h>

int main(void) {
  int n;
  int i;
  int flag;

  printf("Enter value of N > ");
  scanf("%d", &n);
  flag = 1;
  for (i=2; (i<(n/2)) && flag; ) { 
    if ((n % i) == 0) 
      flag = 0;
    else
      i++;
  }
 
  if (flag)
    printf("%d is prime\n", n);
  else
    printf("%d has %d as a factor\n", n, i);
  return 0;
}

Printing Large Block Letters

#include <stdio.h>

void blockg(void)

int main (void)
{
   printf("\n");
   blockg();
   printf("\n");
}

/* Print out the Block letter g */
void blockg(void) {
  printf("EEEEEE\n");
  printf("E\n");
  printf("E\n");
  printf("EEEEEE\n");
  printf("E\n");
  printf("EEEEEE\n");
}

Computing powers of 2

#include <stdio.h>
#define N 16

int main(void) {
  int n;          
  int val = 1;  

  printf("\t  n  \t    2^n\n");
  printf("\t================\n");
  for (n=0; n<=N; n++) {
    printf("\t%3d \t %6d\n", n, val); 
    val = 2*val;
  }
  return 0;
}

The Hello program

#include <stdio.h>

int main(void) {
  printf("Hello World!\n");
  // return 0; 
}

MATRIX ADDITION

#include<stdio.h>
#include<conio.h>
void main()
{
int c[20],a[20],b[20],i,n;
clrscr();
printf("\n a=:\n");
scanf("%d",&a);
printf("\n b=:\n");
scanf("%d",&b);
for(i=0;i<n;i++)
c[i]=a[i]+b[i]
printf("\n ans=:\n");
for(i=0;i<n;i++)
printf("\n %d",c[i]);
getch();
}

TO CONVERT HOURS INTO SECONDS

#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
int a,b,c,s;
clrscr();
printf("enter the time in hour minutes and seconds");
scanf("%d %d %d",&a,&b,&c);
s=(a*3600)+(b*60)+c;
printf("\n the time in seconds is %d",s);
getch();
}

TO FIND WHETHER THE NUMBER IS FIBONACCI OR NOT

#include<stdio.h>
#include<conio.h>
void main()
{
int num,s=0,x=-1,y=1,flag=0;
clrscr();
printf("Enter The Number:");
scanf("%d",&num);
while (s<num)
    {
    s=x+y;
    if (s==num)
    {
    printf("%d belongs to fibonacci series",num);
    flag=1;
    break;
    }
x=y;
y=s;
}
if (flag==0)
   printf("%d is not in fibonacci series",num);
   getch();
   }

TO PRINT NAME FOR A NO OF TIMES

#include<stdio.h>
#include<conio.h>
void main()
{
int a;
clrscr();
for(a=1;a<=5;a++)
   {
   printf("Sample Name\n");
   }
getch();
}

SWAPING 2 VALUES

#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c;
clrscr();
printf("enter any two values\n");
scanf("%d,%d"a,b);
printf("values before swap:%d,%d"a,b);
c=a;
a=b;
b=c;
printf("\n values after swap: %d,%d"a,b);
getch();
}

TO FIND NO OF VOWELS IN A STRING

#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
int i,len,w=1,c=0,v=0;
char s1[20],ch;
clrscr();
printf("\n \t \t Input:");
printf("\n \t \t _____:");
printf("\n \t \t Enter the text:");
gets(s1);
len=strlen(s1);
for (i=0;i<=len-1;i++)
{
 ch=s1[i];
 switch(ch)
 {
   case 'a':
   case 'e':
   case 'i':
   case 'o':
   case 'u':
     v++;
     break;
     case ' ':
     break;
     default:
     c++;
     }
}
if (s1[i]==' ' && s1[i-1]!=' ')
   {
   w++;
   }
printf("\n the number of vowels is %d",v);
getch();
}

SIMPLE ARRAY

#include<stdio.h>
#include<conio.h>
void main();
{
clrscr();
printf("\n enter no. elements:\n");
scanf("%d",&n);
printf("enter %d number:\n");
for(i=0;i<n;i++);
scanf("%d",&a[i]);
printf("\n given array:\n");
for(i=0;i<n;i++);
printf("\n %d",a[i]);
}

UPPERCASE TO LOWERCASE AND VICE CERSA

#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char a[20],b[20];
clrscr();
printf("\n Enter a word \n");
scanf("%s",a);
printf("\n Enter another Word \n");
scanf("%s",b);
strupr(a);
strlwr(b);
printf("\n After Change= %s",a);
printf("\n After CHange= %s",b);
getch();
}

GCF

#include<stdio.h>
#include<conio.h>
void main()
{
int gcf(int,int);
int a,b,g;
clrscr();
printf("Enter any to Number");
scanf("%d %d",&a,&b);
g=gcf(a,b);
printf("Greatest common factor=%d",g);
getch();
}
int gcf(int first,int second)
{
int t;
while(second>0)
     {
     t=first % second;
     first=second;
     second=t;
     }
return(first);
}

CELSUIUS TO FARANHEIT

#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
float f,c;
clrscr();
printf("Please type the temperature in Fahrenheit");
scanf("%f",&f);
c=(f-32)*5/9;
printf("Temperature in Celsius is %f",c);
getch();
}

TO FIND AGE FROM DOB

#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c;
int x,y,z;
int day,month,year;
clrscr();
printf("Enter ur date of birth\n{DATE MONTH YEAR} ");
scanf("%d %d %d",&a,&b,&c);
printf("Enter today's date\n {DATE MONTH YEAR} ");
scanf("%d %d %d",&x,&y,&z);
year=z-c;
 if (b>y)
    {
    year--;
    month=(12-b)+y;
    }
 else
    {
    month=y-b;
    }
if (a>x)
   {
   month--;
   day=(30-a)+x;
   }
else
   {
   day=x-a;
   }
printf("\n ur age:%dyear(s) %dmonth(s) %ddays(s)",year,month,day);
printf("\n Total days=%d",year*360+month*12+day);
getch();
}

TO FIND ADAM NUMBER

#include<stdio.h>
#include<conio.h>
void main()
{
int reverse(int);
int num,rnum,sq,rsq,rnumsq;
clrscr();
printf("Adam number between 10 and 100\n");
for(num=10;num<=100;num++)
   {
   rnum=reverse(num);
   sq=num*num;
   rnumsq=rnum*rnum;
   rsq=reverse(rnumsq);
   if (rsq==sq)
      printf("%d\n",num);
   }
   getch();
   }
   int reverse(int n)
   {
   int r,rn=0;
   while (n>0)
       {
       r=n%10;
       rn=(rn*10)+r;
       n=n/10;
       }
   return(rn);
   }

FIBONACCI SERIES

#include<stdio.h>
#include<conio.h>
void main()
{
int m=0,n=1,i,s;
clrscr();
printf("%d \t %d",m,n);
for(i=3;i<=15;i++)
{
s=m+n;
printf("\t %d",s);
m=n;
n=s;
}
getch();
}

FACTORIAL OF A NUMBER

       IDENTIFICATION DIVISION.
       PROGRAM-ID. FACTORIAL.
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       77 N PIC 9(4).
       77 A PIC S9(4) VALUE 0.
       77 F PIC 9(4) VALUE 1.
       PROCEDURE DIVISION.
       PARA.
           DISPLAY "ENTER A NUMBER.".
           ACCEPT N.
           PERFORM PARA1 UNTIL A = N.
           DISPLAY "THE FACTORIAL IS".
           DISPLAY F.
           STOP RUN.
       PARA1.
           ADD 1 TO A.
           COMPUTE F = F * A.

SWAPING VALUE OF TWO DATA FIELDS

       IDENTIFICATION DIVISION.
       PROGRAM-ID. SWAP.
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       77 A PIC 9(4).
       77 B PIC 9(4).
       77 C PIC 9(4).
       PROCEDURE DIVISION.
       PARA.
           DISPLAY "ENTER THE VALUE OF A".
           ACCEPT A.
           DISPLAY "ENTER THE VALUE OF B".
           ACCEPT B.
           MOVE A TO C.
           MOVE B TO A.
           MOVE C TO B.
           DISPLAY "AFTER SWAP".
           DISPLAY "THE VALUE OF A IS".
           DISPLAY A.
           DISPLAY "THE VALUE OF B IS".
           DISPLAY B.
           STOP RUN.


ADDITION IN COBOL

       IDENTIFICATION DIVISION.
       PROGRAM-ID. ADDITION.
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       77 A PIC 9(4).
       77 B PIC 9(4).
       77 C PIC 9(4).
       PROCEDURE DIVISION.
       PARA.
           DISPLAY "ENTER THE VALUE OF A".
           ACCEPT A.
           DISPLAY "ENTER THE VALUE OF B".
           ACCEPT B.
           COMPUTE C = A + B.
           DISPLAY "THE RESULTANT VALUE IS".
           DISPLAY C.
           STOP RUN.

A SIMPLE PROGRAM

      *ALWAYS START AT COL 8
       IDENTIFICATION DIVISION.
       PROGRAM-ID. SIMPLEPROGRAM.
       DATA DIVISION.
       PROCEDURE DIVISION.
       PARA1.
      *CONTINUE IN COL 12
           DISPLAY "WELCOME TO COBOL".
           STOP RUN.

BASIC COMCEPTS OF COBOL

COBOL (COmmon Business Oriented Language)

            COBOL was developed in 1959 by a group called COnference on Data Systems Language (CODASYL). First COBOL compiler was released by December 1959. First ANSI approved version   was released on 1968.

KEY FEATURES OF COBOL:-
  1. First language that was developed  for Business application development, which can handle huge volume of data.
  2. Procedure Oriented Language. Program is segmented into several tasks. Each task is written as a Paragraph in Procedure Division and executed in a sequence defined by the user.
  3. Easy to learn, code and maintain.
 COBOL CODING SHEET:-

          The COBOL programs must be written on special coding sheets known as COBOL coding sheet. each line in COBOL coding sheet contains 80 positions and they are divided into various sections, they are

  1. SEQUENCE(1-6).
  2. INDICATOR(7).
  3. AREA A(8-11).
  4. AREA B(12-72).
  5. IDENTIFICATION(73-80).

SEQUENCE:- Page/line numbers Optional (automatically assigned by compiler).

INDICATOR:- The various characters used are Continuity(-), Comment(*), Starting a new page(/), Debugging lines(D).

AREA A:Division, Section, Paragraph, 01,77 declarations must begin here.

AREA B:- All the other declarations/statements begin here.

IDENTIFICATION:- It will be ignored by the compiler but it will be visible in the source listing.


    PRICE LIST

           IDENTIFICATION DIVISION.
           PROGRAM-ID. PRICELIST.
           ENVIRONMENT DIVISION.
           INPUT-OUTPUT SECTION.
           FILE-CONTROL.
               SELECT INFILE ASSIGN TO DISK
               ORGANIZATION IS LINE SEQUENTIAL.
               SELECT OUTFILE ASSIGN TO DISK
               ORGANIZATION IS LINE SEQUENTIAL.
           DATA DIVISION.
           FILE SECTION.
           FD INFILE
               LABEL RECORDS ARE STANDARD
               VALUE OF FILE-ID IS "IN.TXT".
           01 INREC.
               02 ID PIC X(4).
               02 DESC PIC X(20).
               02 PRICE PIC 9(6).
           FD OUTFILE
               LABEL RECORDS ARE STANDARD
               VALUE OF FILE-ID IS "OUT.TXT".
           01 OUTREC PIC X(80).
           WORKING-STORAGE SECTION.
           01 H1.
               02 F PIC X(35) VALUE SPACES.
               02 F PIC X(10) VALUE "PRICE LIST".
           01 H2.
               02 F PIC X(2) VALUE SPACES.
               02 F PIC X(10) VALUE "PRODUCT-ID".
               02 F PIC X(2) VALUE SPACES.
               02 F PIC X(15) VALUE "PRODUCT-DESC".
               02 F PIC X(2) VALUE SPACES.
               02 F PIC X(5) VALUE "PRICE".
           01 H3.
               02 F PIC X(2) VALUE SPACES.
               02 OID PIC X(10) VALUE SPACES.
               02 F PIC X(2) VALUE SPACES.
               02 ODESC PIC X(15) VALUE SPACES.
               02 F PIC X(2) VALUE SPACES.
               02 OPRICE PIC $Z,ZZ,ZZ.99.
           01 H4.
               02 F PIC X(80) VALUE ALL "=".
           01 H5.
               02 F PIC X(20) VALUE SPACES.
               02 F PIC X(20) VALUE "NO.OF RECORDS".
               02 NOR PIC ZZZ.
           01 CH PIC X VALUE "Y".
           01 RC PIC 9(4) VALUE 0.
           PROCEDURE DIVISION.
           PARA.
               OPEN OUTPUT INFILE.
               PERFORM INPARA UNTIL CH = "N".
               CLOSE INFILE.
               OPEN INPUT INFILE OUTPUT OUTFILE.
               PERFORM WRITEPARA.
               PERFORM APARA.
               MOVE RC TO NOR.
               WRITE OUTREC FROM H4.
               WRITE OUTREC FROM H5.
           INPARA.
               DISPLAY " ENTER ID".
               ACCEPT ID.
               DISPLAY " ENTER DESC".
               ACCEPT DESC.
               DISPLAY " ENTER PRICE"
               ACCEPT PRICE.
               ADD 1 TO RC.
               DISPLAY " CONTINUE?"
               ACCEPT CH.
           WRITEPARA.
               WRITE OUTREC FROM H1.
               WRITE OUTREC FROM H4.
               WRITE OUTREC FROM H2.
           APARA.
               READ INFILE AT END GO TO CPARA.
               MOVE ID TO OID.
               MOVE ODESC TO ODESC.
               MOVE PRICE TO OPRICE.
               WRITE OUTREC FROM H3.
               GO TO APARA.
           CPARA.
               CLOSE INFILE OUTFILE.
               STOP RUN.
    Related Posts with Thumbnails