Friday, February 23, 2024

1. WAP to print the sum and product of digits of an integer.

 #include <stdio.h>


int main()

{

    int n;

    int dig, sum,pro;

     

    printf("\nEnter an integer number :");

    scanf("%d",&n);

  

    /*Calculating Sum and Product*/

    sum=0;

    pro=1;

     

    while(n>0)

    {

        dig=n%10; /*get digit*/

        sum+=dig;

        pro*=dig;

        n=n/10;

    }

     

    printf("\nSUM of all Digits is : %d",sum);

    printf("\nPRODUCT of all digits: %d",pro);

    return 0;

}


WEST BENGAL STATE UNIVERSITY computer science NEP Syllabus

 WEST BENGAL STATE UNIVERSITY computer sciecne NEP Syllabus 


SEMESTER 2 computer sciecne NEP Syllabus 



COMJPUTER SCIECNE NEP SYLLABUS WBSU SEM2
MAJOR THEORYData Structures using C++ CLICK HERE
MAJOR PRACTICALData Structures using C++ CLICK HERE
SECPython ProgrammingCLICK HERE
MDC

WEST BENGAL STATE UNIVERSITY NEP Syllabus for B.Sc. Computer Science Major, Minor and Interdisciplinary

CMSACOR02T: Data Structures using C++ 
Theory: 45 Lectures

 Introduction (5 Lectures) 
Data Object, Abstract Data Type, Data Structures and Data Types. Types of Data Structures – Linear and non-linear Data Structures.Single and Multi-dimensional Arrays, Address Calculations, Sparse Matrices (Array Representation). 

Linked Lists (7 Lectures) 
Singly, Doubly and Circular Lists (Array and Linked representation); Operations on Lists. Sparse Matrices (Linked Representation). 

Stacks and Queues (9 Lectures) 
Implementing single / multiple stack/s in an Array; Prefix, Infix and Postfix expressions, Utility and conversion of these expressions from one to another; Applications of stack; Limitations of Array representation of stack. Array and Linked representation of Queue, De-queue, Priority Queues

 Recursion (5 lectures)
Developing Recursive Definition of Simple Problems and their implementation; Advantages and Limitations of Recursion; Understanding what goes behind Recursion (Internal Stack Implementation)

 Binary Trees (10 Lectures) 
Introduction; Properties, Binary Trees Traversals (Recursive and Non-Recursive), Binary Search Trees (Insertion, Deletion), Recursive and Iterative Traversals on Binary Search Trees; Threaded Binary Trees (Concept only); Height-Balanced Trees (Concept only). Searching, 

Sorting and Hashing (9 Lectures)
Linear Search, Binary Search, Comparison of Linear and Binary Search, Selection Sort, Insertion Sort, Bubble Sort, Comparison of Sorting Techniques. Introduction to Hashing, Resolving collusion by Open Addressing, Coalesced Hashing, Separate Chaining and simple examples.

WEST BENGAL STATE UNIVERSITY computer science NEP Syllabus

 SEMESTER 1

WEST BENGAL STATE UNIVERSITY computer sciecne NEP Syllabus 


SEMESTER 1 computer sciecne NEP Syllabus 



COMJPUTER SCIECNE NEP SYLLABUS WBSU SEM1
MAJOR THEORYComputer Fundamentals and programming with CCLICK HERE
MAJOR PRACTICALComputer Fundamentals and programming with CCLICK HERE
SECR ProgrammingCLICK HERE
MDCComputer Fundamentals

Wednesday, February 21, 2024

WAP to calculate GCD of 2 number (i) with recursion (ii) without recursion

 #include <iostream>

using namespace std;


class cl

{

private:

int n1,n2;

public:

void input()

{

cout<<"\nEnter 2 nunbers: ";

cin>>n1>>n2;

}

void gcd()


{

int g;

for(int i=1;i<=n1 && i<=n2;i++)

{

if(n1%i==0 && n2%i==0)

g=i;

}

cout<<"GCD= "<<g;

}

int gcd(int a, int b)

{

// Everything divides 0

if (a == 0)

return b;

if (b == 0)

return a;


// base case

if (a == b)

return a;


// a is greater

if (a > b)

return gcd(a-b, b);

return gcd(a, b-a);

}

};

int main()

{

cl ob;

int ch,m,n;



do

{

    cout<<"**GCD of 2 numbers**\n\n1.using Recursion \n2. Not using Recursion\n3.Exit";

cout<<"\n\nEnter ur Choice: ";

cin>>ch;

switch(ch)

{

case 1:

cout<<"\nEnter 2 numbers: ";

cin>>m>>n;

cout<<"GCD= "<<ob.gcd(m,n);

break;


case 2:

ob.input();

ob.gcd();

break;


case 3:

cout<<"\nEXIT";

break;


default:

cout<<"\nSorry! Invalid Choice";

}

}

while(ch!=3);

return 0;

}

WAP to display Fibonacci series (i)using recursion, (ii) using iteration

 #include<iostream>

using namespace std;


class cl

{


public:

int a=0,b=1,l;

void input()

{


cout<<"\nEnter the Length of Fibonacci series: ";

cin>>l;

}

void fib()

{


for(int i=0;i<l;i++)

{

int c=a+b;

cout<<" "<<a;

a=b;

b=c;

}

}

int fib(int x)

{

if((x==1)||(x==0))

{

return(x);

}

else

{

return(fib(x-1)+fib(x-2));

}

}

};

int main()

{

cl ob;

int ch,n,i=0;



do

{

  cout<<"\nFibonacci series \n\n1.using Iteration \n2.using Recursion\n3.Exit";  

cout<<"\nEnter ur Choice: ";

cin>>ch;

switch(ch)

{

case 1:

ob.input();

ob.fib();

break;


case 2:

ob.input();

cout << "\nFibonnaci Series : ";

i=0;

while(i<ob.l)

{

cout << " "<<ob.fib(i);

i++;

}

break;


case 3:

cout<<"\nEXIT";

break;


default:

cout<<"\nSorry! Invalid Choice";

}

}

while(ch!=3);


return 0;

}

WAP to implement Diagonal Matrix using one-dimensional array.

 // C++ Program to print the Diagonals of a Matrix


#include <bits/stdc++.h>

using namespace std;

#define MAX 20




// Function to print the Principal Diagonal

void printPrincipalDiagonal(int mat[][MAX], int n)

{

cout << "Principal Diagonal: ";


for (int i = 0; i < n; i++) {

for (int j = 0; j < n; j++) {


// Condition for principal diagonal

if (i == j)

cout << mat[i][j] << ", ";

}

}

cout << endl;

}


// Function to print the Secondary Diagonal

void printSecondaryDiagonal(int mat[][MAX], int n)

{

cout << "Secondary Diagonal: ";


for (int i = 0; i < n; i++) {

for (int j = 0; j < n; j++) {


// Condition for secondary diagonal

if ((i + j) == (n - 1))

cout << mat[i][j] << ", ";

}

}

cout << endl;

}


// Driver code

int main()

{

int n ;

int a[20][20]; 

cin>>n;

cout<<"enter eleents";

for (int i = 0; i < n; i++) {

for (int j = 0; j < n; j++) {


cin>> a[i][j] ;

}

}


printPrincipalDiagonal(a, n);

printSecondaryDiagonal(a, n);

return 0;

}


WAP to reverse the order of the elements in the stack using additional Queue.

 #include<stdio.h> 

#include<stdlib.h> 


#define MAX_SIZE 100


struct Queue

{

  int items[MAX_SIZE];

  int front;

  int rear;

};


struct Stack

{

  int items[MAX_SIZE];

  int top;

};


void enqueue (struct Queue *q, int item)

{

  if (q->rear == MAX_SIZE - 1)

    {

      printf ("Queue overflow\n");

      return;

    }


  if (q->front == -1)

    {

      q->front = 0;

    }


  q->rear++;

  q->items[q->rear] = item;

}


int dequeue (struct Queue *q)

{

  if (q->front == -1)

    {

      printf ("Queue underflow\n");

      return -1;

    }


  int item = q->items[q->front];

  q->front++;


  if (q->front > q->rear)

    {

      q->front = q->rear = -1;

    }


  return item;

}


void display (struct Queue *q)

{

  if (q->rear == -1)

    {

      printf ("Queue is empty\n");

      return;

    }


  for (int i = q->front; i <= q->rear; i++)

    {

      printf ("%d ", q->items[i]);

    }

  printf ("\n");

}


void push (struct Stack *s, int item)

{

  if (s->top == MAX_SIZE - 1)

    {

      printf ("Stack overflow\n");

      return;

    }


  s->top++;

  s->items[s->top] = item;

}


int pop (struct Stack *s)

{

  if (s->top == -1)

    {

      printf ("Stack underflow\n");

      return -1;

    }


  int item = s->items[s->top];

  s->top--;


  return item;

}


int main ()

{

  struct Queue q;

  q.front = -1;

  q.rear = -1;


  struct Stack s;

  s.top = -1;


  enqueue (&q, 1);

  enqueue (&q, 2);

  enqueue (&q, 3);

  enqueue (&q, 4);


  printf ("Queue before reversing:\n");

  display (&q);


  while (q.front != -1)

    {

      push (&s, dequeue (&q));

    }


  while (s.top != -1)

    {

      enqueue (&q, pop (&s));

    }


  printf ("Queue after reversing:\n");

  display (&q);


  return 0;

}

WAP to reverse the order of the elements in the stack using additional stack

 #include <stdio.h>  

 #define MAXSIZE 10  


 struct Stack {  

    int top;  

    int array[MAXSIZE];  

} st;  

  


 void initialize() {  

 st.top = -1;  

}  


int isFull() {     

    if(st.top >= MAXSIZE-1)  

        return 1;  

    else  

        return 0;  

}  

  

int isEmpty() {  

 if(st.top == -1)  

     return 1;  

 else  

     return 0;  

}  

   


void push(int num) {  

    if (isFull())  

        printf("Stack is Full...\n");  

    else {  

        st.array[st.top + 1] = num;  

        st.top++;  

    }  

}  

   


int pop() {  

    if (isEmpty())  

        printf("Stack is Empty...\n");  

    else {  

     st.top = st.top - 1;  

        return st.array[st.top+1];  

    }  

}  

   


void printStack(){  


 if(!isEmpty())  

{  

     int temp = pop();  

     printStack();  

     printf(" %d ", temp);  

     push(temp);  

    }  

}  


void insertAtBottom(int item) {  

    if (isEmpty()) {  

        push(item);  

    } else {  

       int top = pop();  

        insertAtBottom(item);  

        push(top);  

    }  

}  

 

void reverse() {  

    if (!isEmpty()) {  

         int top = pop();  

        reverse();  

        insertAtBottom(top);  

    }  

}  

  

int getSize(){  

 return st.top+1;  

}  


 int main() {  

 initialize(st);    

  push(1);     

    push(2);    

    push(3);  

    push(4);      

    push(5);    

    printf("Original Stack\n");  

    printStack();  

    reverse();  

    printf("\nReversed Stack\n");  

    printStack();  

    return 0;  

}  

Find out whether a list is a palindrome.

 

Find out whether a list is a palindrome.

my_reverse(L1,L2) :- my_rev(L1,L2,[]).


my_rev([],L2,L2) :- !.

my_rev([X|Xs],L2,Acc) :- my_rev(Xs,L2,[X|Acc]).

is_palindrome(L) :- reverse(L,L).