Monday, January 18, 2021

BlueJ Program To Check A Number For Perfect Square Or Not


import java.util.*;
class Sw
{
   Scanner sc=new Scanner(System.in);
   int i,n,x;
   void show() 
   {
       System.out.println("\nEnter the number: ");
       n=sc.nextInt();
       for(i=2;i<n;i++)
       {
           if(n%i==0 && i==n/i)
           break;
        }
        if(i==n)
        System.out.println(n+ " is not a perfect square number");
        else
        System.out.println(n+ " is a perfect square number");            
    }

}

C Program for order billing in a restaurant using an array of structures

 #include< stdio.h >
struct restaurant
{
 int no;
 float total;
 char item [20];
 };
 void main ()
 {
 struct restaurant bill [20];
 int i,x=0,d;
 char ch;
 double tot=0;
    clrscr ();
  printf("\n     Menu Card   \n");
  printf("\n     Item              Price/Plate   \n");
  printf("\n1.   Chicken Byriani  Rs.120   \n");
  printf("\n2.   Mutton Byriani   Rs.150   \n");
  printf("\n3.   Mutton Chap      Rs.100   \n");
    printf("\n4.  Chicken Leg      Rs.75   \n");
    for (i=0;i<20;i++)
    {
   printf ("Enter the Item No: ");
   scanf("%d",&d);
   if(d==1)
strcpy(bill[i].item, "Chicken Byriani");
else if(d==2)
strcpy(bill[i].item, "Mutton Byriani");
else if(d==3)
strcpy(bill[i].item, "Mutton Chap");
else if(d==4)
strcpy(bill[i].item, "Chicken Leg");
    printf ("Enter the number of plates : ");
  scanf ("%d", &bill [i].no);
  if(d==1)
  bill[i].total=bill[i].no*120;
  else if(d==2)
  bill[i].total=bill[i].no*150;
  else if(d==3)
  bill[i].total=bill[i].no*100;
  else if(d==4)
  bill[i].total=bill[i].no*75;
  printf("\nAny More Item (y/n):");
   ch=getche();
   if(ch=='n')
   break;
   }
   x=i+1;
   for(i=0;i<x;i++)
   {
   tot+=bill[i].total;
     printf ("\n%s   %d   %.2f",bill[i].item, bill[i].no, bill[i].total);
   }
    printf("\nTotal Payable Amount: %.2f",tot);

  getch ();

  }


Display Two Categories Of Marks Separately From 1 D Array

 
 In this program Roll Number and 4 subject marks of 5 students will be entered in separate 1 d arrays and display students equal to or above 80 % and below 80% separately

import java.io.*;
class Marks
{
   BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
    int roll[]=new int[5];
    int eng[]=new int[5];
    int math[]=new int[5];
    int phy[]=new int[5];
    int chem[]=new int[5];
    int i,f,sum;
    double av=0;
    void take() throws IOException
    {
        for(i=0;i<5;i++)
        {
            System.out.print("\nRoll Number of Student Number "+(i+1)+":");
            roll[i]=Integer.parseInt(br.readLine());;
            System.out.print("\nEnglish Marks:");
            eng[i]=Integer.parseInt(br.readLine());
            System.out.print("\nMath Marks:");
            math[i]=Integer.parseInt(br.readLine());
            System.out.print("\nPhysics Marks:");
            phy[i]=Integer.parseInt(br.readLine());
            System.out.print("\nChemistry Marks:");
            chem[i]=Integer.parseInt(br.readLine());
        }
        System.out.println("\nResult Sheet:");
         System.out.println("\nRoll  Eng  Math  Phy   Chem");
        for(i=0;i<5;i++)
        {
            if(roll[i]<10)
            System.out.print("0"+roll[i]+"   ");
            else
            System.out.print(roll[i]+"   ");
            if(eng[i]<10)
            System.out.print("00"+eng[i]+"   ");
            else if (eng[i]<100)
            System.out.print("0"+eng[i]+"   ");
            else
            System.out.print(eng[i]+"   ");
            if(math[i]<10)
            System.out.print("00"+math[i]+"   ");
            else if (math[i]<100)
            System.out.print("0"+math[i]+"   ");
            else
            System.out.print(math[i]+"   ");
            if(phy[i]<10)
            System.out.print("00"+phy[i]+"   ");
            else if (phy[i]<100)
            System.out.print("0"+phy[i]+"   ");
            else
            System.out.print(phy[i]+"   ");
            if(chem[i]<10)
            System.out.print("00"+chem[i]+"   ");
            else if (chem[i]<100)
            System.out.print("0"+chem[i]+"   ");
            else
            System.out.print(chem[i]+"   ");
            
            System.out.println();
           // System.out.print("\n"+roll[i]+" "+eng[i]+" "+math[i]+" "+phy[i]+" "+chem[i]);
        }
        f=0;
        System.out.print("\nStudents above 80%\n");
        for(i=0;i<5;i++)
        {
            sum=eng[i]+math[i]+phy[i]+chem[i];
            av=sum/4.0;
            if(av>=80)
            {
                f=1;
            System.out.println("\n "+roll[i]+": "+av);
        }
                
            }
            if(f==0)
            System.out.println("\nNo Student above 80%");
            f=0;
            System.out.print("\n\nStudents below 80%\n");
        for(i=0;i<5;i++)
        {
            sum=eng[i]+math[i]+phy[i]+chem[i];
            av=sum/4.0;
            if(av<80)
            {
                f=1;
            System.out.println("\n "+roll[i]+": "+av);
        }
        if(f==0)
            System.out.println("\nNo Student below 80%");
                
            }
        }
public static void main(String args[]) throws IOException
{
 Marks ob=new Marks();
ob.take();
}

    }

Sunday, January 17, 2021

Converting Values From Double To Int Using Array

 
In this program, 10 double values will be stored in a single array A and truncate fractional part of array A and store integer part in array B

import java.util.*;
class Arr
{
  
    Scanner sc=new Scanner(System.in);
    int B[]=new int[10];
    double A[]=new double[10];
    int i;
    void take()
    {
        for(i=0;i<10;i++)
        {
            System.out.print("\nDouble Value:");
            A[i]=sc.nextDouble();
        }
            System.out.print("\nDouble values as follows:");
            for(i=0;i<10;i++)
        {
            System.out.print(" "+A[i]);
           
        }
         for(i=0;i<10;i++)
        {
            B[i]=(int)A[i];
           
        }
            System.out.print("\nInteger values as follows:");
            for(i=0;i<10;i++)
        {
            System.out.print(" "+B[i]);
           
        }        
        }
public static void main(String args[])
{
Arr ob=new Arr();
ob.take();
}
    }

Saturday, January 16, 2021

Write a C program to copy one linked list to another and count the number of node

 # include <stdio.h>
# include <stdlib.h>
struct list
{
char info[20];
struct list *next;
struct list *prev;
};
struct list *new1,*node;
void create(struct list *s,struct list *e)
{
char ch;
node=s;
printf("\nWant to create a node(y/n):");
ch=getche();
while (ch != 'n')
{
node->next = (struct list *) malloc(sizeof(struct list));
node->next->prev= node;
node = node->next;
printf("\n Enter the string value:- ");
gets(node->info);
node->next = e;
e->prev=node;
printf("\n Enter choice--'n' for break: ");
ch = getche();
}
}
void displayL (struct list *s,struct list *e)
{
node = s->next;
while (node!=e)
{
printf(" %u--%s", node,node->info);
node = node->next;
}
printf("\n");
}
void displayR (struct list *e,struct list *s)
{
node = e->prev;
while (node!=s)
{
printf("  %s",node->info);
node = node->prev;
}
printf("\n");
}
void merge(struct list *s,struct list *e, struct list *s1,struct list *e1)
{
int i=0;
s=s->next;

while(s!=e)
{
s1->next=(struct list*)malloc(sizeof(struct list));
s1->next->prev=s1;
s1=s1->next;
 strcpy(s1->info,s->info);
 s=s->next;
 s1->next=e1;
e1->prev=s1;

 i++;
}
printf("\nNumber of Nodes: %d",i);
}
void main()
{
struct list *start,*end,*start1,*end1;
clrscr();
start= (struct list *) malloc(sizeof(struct list));
start->next=NULL;
end= (struct list *) malloc(sizeof(struct list));
end->next=NULL;
start1= (struct list *) malloc(sizeof(struct list));
start1->next=NULL;
end1= (struct list *) malloc(sizeof(struct list));
end1->next=NULL;
create(start,end);
printf("\n Created list is as follows(L ->R)\n");
displayL(start,end);
printf("\n Created list displayed from R->L\n");
displayR(end,start);
merge(start,end,start1,end1);
printf("\n Copied List from L ->R\n");
displayL(start1,end1);
printf("\n list from R to L after deletion\n");
displayR(end1,start1);

getch();

}


Deletion Of All Nodes From A Doubly Linked List

 
# include < stdio.h>
# include < stdlib.h>
struct link
{
char info[20];
struct link *next;
};
struct link *start,*p,*node;
int i=1;
void create()
{
char ch='y';
node=start;
while(ch != 'n')
{
node->next = (struct link* ) malloc(sizeof(struct link));
node = node->next;
printf("\n Enter string for node: %d: ",i);
scanf("%s", node->info);
node->next = NULL;
i++;
printf("\n Enter choice-- 'n' for break: ");
ch = getche();
}
}
void display(struct link *n)
{
node=n;
while(node)
{
printf("\n 0x%x ", node);
printf("%s\n",node->info);
node=node->next;
}
}
void delNodes(struct link *n)
{
node=n;
p = n->next;

while(p)
{

node->next = p->next;
printf("Deleting %s\n",p->info);
free(p);
p = node->next;
}
do
{
free(start);
start=start->next;
}while(start);
}

void main()
{
clrscr();
start = (struct link* ) malloc(sizeof(struct link));
printf("\n Enter string for node: %d: ",i);
scanf("%s", start->info);
start->next = NULL;
create();
printf("\nAfter Creation...");
display(start);
delNodes(start);
printf("\nAfter Deletion...");
display(start);
getch();

}


Subject Marks In One D Array And Promotion

 

In this program Roll Number and marks on English, Mathematics, Physics, Chemistry of 'n' number of students are taken in separate 1 d arrays. Promotion is granted according to the following criterias:
The candidate must have passed in English and in at least any two subjects of Mathematics, Physics, Chemistry. Pass marks is 35.
 
import java.util.*;
class Promition
{
    Scanner sc=new Scanner(System.in);
    int n;
    int roll[];
    int eng[];
    int math[];
    int phy[];
    int chem[];
    int i,f;
    void take()
    {
System.out.print("\nHow many Students: ");
n=sc.nextInt();
roll=new int[n];
 eng=new int[n];
 math=new int[n];
 phy=new int[n];
chem=new int[n];
        for(i=0;i<n;i++)
        {
            System.out.print("\nRoll Number of Student Number "+(i+1)+":");
            roll[i]=sc.nextInt();
            System.out.print("\nEnglish Marks:");
            eng[i]=sc.nextInt();
            System.out.print("\nMath Marks:");
            math[i]=sc.nextInt();
            System.out.print("\nPhysics Marks:");
            phy[i]=sc.nextInt();
            System.out.print("\nChemistry Marks:");
            chem[i]=sc.nextInt();
        }
        System.out.println("\nResult Sheet:");
         System.out.println("\nRoll  Eng  Math  Phy   Chem");
        for(i=0;i<n;i++)
        {
            if(roll[i]<10)
            System.out.print("0"+roll[i]+"   ");
            else
            System.out.print(roll[i]+"   ");
            if(eng[i]<10)
            System.out.print("00"+eng[i]+"   ");
            else if (eng[i]<100)
            System.out.print("0"+eng[i]+"   ");
            else
            System.out.print(eng[i]+"   ");
            if(math[i]<10)
            System.out.print("00"+math[i]+"   ");
            else if (math[i]<100)
            System.out.print("0"+math[i]+"   ");
            else
            System.out.print(math[i]+"   ");
            if(phy[i]<10)
            System.out.print("00"+phy[i]+"   ");
            else if (phy[i]<100)
            System.out.print("0"+phy[i]+"   ");
            else
            System.out.print(phy[i]+"   ");
            if(chem[i]<10)
            System.out.print("00"+chem[i]+"   ");
            else if (chem[i]<100)
            System.out.print("0"+chem[i]+"   ");
            else
            System.out.print(chem[i]+"   ");            
            System.out.println();
           // System.out.print("\n"+roll[i]+" "+eng[i]+" "+math[i]+" "+phy[i]+" "+chem[i]);
        }
        for(i=0;i<n;i++)
        {
            f=0;
            if(eng[i]>=35)
             {
                  if(math[i]>=35)
                 f++;
                 if(phy[i]>=35)
                 f++;
                 if(chem[i]>=35)
                 f++;
                }
                if(f>=2)
                System.out.println("\n "+roll[i]+": Promition is Granted...");
                else
                System.out.println("\n "+roll[i]+": Promition is not Granted...");
            }
        }
public static void main(String args[])
{
Promotion ob=new Promotion();
ob.take();
}
}    }

Friday, January 15, 2021

Python Directory Methods

 

Method

Description

clear()

Removes all the elements from the dictionary

copy()

Returns a copy of the dictionary

fromkeys()

Returns a dictionary with the specified keys and value

get()

Returns the value of the specified key

items()

Returns a list containing a tuple for each key value pair

keys()

Returns a list containing the dictionary's keys

pop()

Removes the element with the specified key

popitem()

Removes the last inserted key-value pair

setdefault()

Returns the value of the specified key. If the key does not exist: insert the key, with the specified value

update()

Updates the dictionary with the specified key-value pairs

values()

Returns a list of all the values in the dictionary


Subscribe via email

Enter your email address:

Delivered by FeedBurner