Search This Blog

Saturday, 1 January 2022

Title; Even Or Odd

 

--program--

Title; Even Or Odd

Programm:

#include<iostream>
using namespace std;
int main()
{
    int no;
    cout<<"Enter an integer value:";
    cin>>no;
    switch(no%2)
    {
        case 0:
            cout<<"Evern";
            break;
        case 1:
            cout<<"Odd";
            break;
        default:
            cout<<"NO an issue try later";
            
        
    }
    return 0;
}

Title:- Progam to count the occurrence of a substring in the string

 Title:- Progam to count the occurrence of a substring in the string


Program

/* C Program To Count the Occurrence of a Substring in String  */
#include <stdio.h>
#include<conio.h>
#include <string.h>
 
char str[100], sub[100];
int count = 0count1 = 0;
 
int main()
{
    int ijll1l2;
    
    printf("\nEnter a string : ");
    scanf("%[^\n]s"str);
 
    l1 = strlen(str);
 
    printf("\nEnter a substring : ");
    scanf(" %[^\n]s"sub);
 
    l2 = strlen(sub);
 
    for (i = 0i < l1;)
    {
        j = 0;
        count = 0;
        while ((str[i== sub[j]))
        {
            count++;
            i++;
            j++;
        }
        if (count == l2)
        {
            count1++;                                   
            count = 0;
        }
        else
            i++;
    }    
    printf("%s occurs %d times in %s"subcount1str);
    getch();
}


Title : Reverse the number

Title : Reverse the number 

Program:


 //program to calculate the rteverse tof the enterdnumber;

#include<iostream>
using namespace std;
int main()
{
    int sum,rem,a,num;
    cout<<"Enter the number :";
    cin>>num;
    
    sum=0;
    rem=0;
    cout<<"\nNumber Enterd is = "<<num<<endl;
    while(num>0)
    {
        rem=num%10;
        sum=sum*10+rem;
        num=num/10;
    }
    cout<<"Reverse of Enterd number: "<<sum;
    return 0;
}

Title: Print statement without using semicolan(;)

 Title: Print statement without using semicolan(;)

Program:

#include<iostream>
using namespace std;
int main()
{
    if(cout<<"print this statement")
    {
        
    }
//  switch(cout<<"print another stement")
//  {
//  
//      
//  }
    printf("hi this is dnyaneshwar");
    return 0;
}

Title : Natural Number Without using Loop

 

Title : Natural Number Without using Loop

Program:

#include<iostream>
using namespace std;
int main()
{
    int n,c;
    cout<<"Entert the value of A:";
    cin>>n;
    c=1;
    boss:
        cout<<c<<"\t";
        c++;
        cout<<" \n";
        if(c<n)
        goto boss;
        return 0;
}

Title: Min max without using if else

 

Title: Min max without using if else

Program:

#include<iostream>
#include<math.h>
using namespace std;
int main()
{
    int a=14;int b=33;
    cout<<"max:"<<((a+b)+abs(a-b))/2<<endl;
    cout<<"Min:"<<((a+b)-abs(a-b))/2<<endl;
    return 0;
}

Title :- linear Search

 Title :- linear Search


Program:

#include<iostream>
using namespace std;
int main()
{
    int n,x,i,flag=0,a[10];
    cout<<"Enter the no.of.Elements: ";
    cin>>n;
    cout<<"Enter the elemnts of aarrray: ";
    for(i=0;i<n;i++)
    {
        cin>>a[i];
    }
    cout<<"Enter the elemets for the searching: ";
    cin>>x;
    for(i=0;i<n;i++)
    {
        if(a[i]==x)
            flag=1;
        else
            flag=0;
    }
    if(flag==1)
        cout<<"Elments is found";
    else
        cout<<"Elements is not found";
    return 0;
}

Title: Decimal To Binary

 

Decimal to binary

program:

#include<iostream>
using namespace std;
int main()
{
    int i,n,a[10];
    cout<<"Enter an interger:";
    cin>>n;
    i=0;
    while(n>0)
    {
        a[i]=n%2;
        n=n/2;
        i=i+1;
    }
    for(i=i-1;i>0;i--)
    {
        cout<<a[i];
    }
    return 0;
    
}

Aim : armStrong number

 Aim : armStrong number

Program

//write a program for a armstrong number
#include<iostream>
using namespace std;
int main()
{
    int num,sum,rem,temp;
    sum=0;
    cout<<"Enter the number for searching armstrong number:";
    cin>>num;
    cout<<"Enter nmber is: "<<num;
    *temp=num;
    while(num>0)
    {
        rem=num%10;
        sum=sum+rem*rem*rem;
        num=num/10;
    }
    if(temp==sum)
    {
        cout<<"armstrong number:";
        
    }
    else
    {
        cout<<"\n is not an armastron gnumber:";
    }
    return 0;
}

title: Swap using template

 title: Swap using template

program:

#include<iostream>

using namespace std;

template<class T>

void swapme(T & x, T & y)

{

T temp = x;

x=y;

y=temp;

}

int main()

{

int a,b;

cout<<"Enter the two integer values : ";

cin>>a>>b;

swapme(a,b);

cout<<"After Sapping A ="<<a<<", B = "<<b<<endl;

double p,q;

cout<<"Enter the two double values :";

cin>>p>>q;

swapme(p,q);

cout<<"After the swapping : P ="<<p<<" , Q = "<<q<<endl;

return 0;

}

OUPUT







Title:- WRTYU problem

 Program

#include<stdio.h>

#include<conio.h>

#include<string.h>

#include<iostream>

using namespace std;

int main()

{

char base[48]="1234567890-=qwertyuiop[]\asdfghjkl;'zxcvbnm,./";

char c[100];

int i,l;

cout<<"\n\tEnter the String: ";

gets(c);

l=strlen(c);

strupr(c);

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

{

int j;

for(j=0;j<47;j++)

{

if((base[j]==c[i]) && c[i]!='q' && c[i]!='a' && c[i]!='z')

{

cout<<base[j-l];

}

else if(c[i] == ' ')

{

cout<<" ";

break;

}

}

}

return 0;

}


output









Aim:-Fibonacci series

 Aim:-Fibonacci series

program

#include<iostream>

#include<stdio.h>

#include<conio.h>

using namespace std;

int main()

{

long int fibb1=0,fibb2=1,n,a,b,i,c=0;

long int sum;

cout<<"\tEnter th einput for A:";

cin>>a;

cout<<"\tEnter the input for B:";

cin>>b;

cout<<"\tA is: "<<a<<"\t B is: "<<b;

n=b;

cout<<"\n\t Fibnacci series :";

while(b>0)

{

sum=fibb1+fibb2;

if(sum>a&&sum<n)

{

c++;

cout<<"\t"<<sum;

}

fibb1=fibb2;

fibb2=sum;

b--;

}

cout<<"\n\n\tOutput Count = "<<c;

return 0;

}

Output:




implementation of stack

Title: implementation of stack

 Aim: a study of the implementation of stack

Theory:

What is stack in CPP
A stack is a standard C++ container adapter, designed to be used in a LIFO context, and is implemented with an interface/wrapper to the type passed to it as a template argument, which defaults to a deque. It is so simple, that it can be described with just a sample interface: C++ Standard Library. Input/output.
for  creating a stack:
For creating a stack, we must include the <stack> header file in our code. We then use this syntax to define the std::stack:
template <class Type, class Container = deque<Type> > class stack;
Type â€“ is the type of element contained in the std::stack. It can be any valid C++ type or even a user-defined type.

Container â€“ is the Type of underlying container object.

Member Types:-

value_type- The first template parameter, T. It denotes the element types.

container_type- The second template parameter, Container. It denotes the underlying container type.

size_type- Unsigned integral type.

The functions associated with stack are: 
empty() â€“ Returns whether the stack is empty – Time Complexity: O(1) 
size() â€“ Returns the size of the stack – Time Complexity: O(1) 
top() â€“ Returns a reference to the topmost element of the stack – Time Complexity: O(1) 
push(g) â€“ Adds the element ‘g’ at the top of the stack – Time Complexity: O(1) 
pop() â€“ Deletes the topmost element of the stack – Time Complexity: O(1)


Program:

#include <iostream>

#include<conio.h>

using namespace std;


 int stack[100], n=100,top=-1;

void push(int val)

{

    if(top >=n-1)

    {

        cout<<"stack is Overflow";

    }

    else

    {

        top++;

        stack[top]=val;

    }

}


void pop()

{

    if(top <=-1)

    {

        cout<<"Stack is Underflow";

    }

    else

    {

        cout<<"The Popped Element is "<<stack[top];

        top--;

    }

}


void display()

{

    if(top >=0)

    {

        cout<<"Stack Elements are:";

        for(int i=top;i>=0;i++)

        {

            cout<<stack[i]<<" ";

            cout<<endl;

        }

    }    

    else

    {    

            cout<<"Stack is Empty:";

        

    }

}


int main()

{

    int ch,val;

    cout<<"1) Push in Stack"<<endl;

    cout<<"2) Pop in Stack"<<endl;   

    cout<<"3) Display Stack"<<endl;   

    cout<<"4) Exit"<<endl;

    do{

        cout<<"Enter Choice:"<<endl;

        cin>>ch;

        switch(ch)

        {

            case 1:

            {

                cout<<"Enter Value to be Pushed:"<<endl;

                cin>>val;

                push(val);

                break;

            }

            case 2:

            {

                pop();

                break;

            }

            case 3:

            {

                display();

                break;

            }

            case 4:

            {

                cout<<"Exit"<<endl;

                break;

            }

            default:

        {

                cout<<"Wrong Choice"<<endl;

            }

        }

    }

    while(ch!=4);

    return 0;

}


OutPut


3n+1 problem solving program in CPP

  3n+1 problem solving program in CPP

#include <iostream>

#include<conio.h>

using namespace std;


int cycle(long int n)//LOW 

{

    long int i=1;

    while(n!=1)

    {

        if(n%2 == 0)

        {

            n=n/2;

        }

        else

        {

            n=(3*n)+1;

        }

        i++;

    }

    return i;

}


int main()

{

    int a,b,low,high,count;

    std::cout << "Enter the series of numbes:" << std::endl;

    while(std::cin >> a>>b)

    {

        if(a<b)

        {

            low=a;

            high=b;

        }

        else

        {

            low=b;

            high=a;

        }

        int max = cycle(low);

        for(int i=low+1;i<=high;i++)

        {

            int l=cycle(i);

            if(l>max)

            {

                max=l;

            }

        }

        cout<<a<<" \t "<<b<<" \t "<<max<<"\n";

}

}

    

output:









Trip program in CPP

 Trip program in CPP

#include <iostream>

#include<conio.h>

using namespace std;


int main()

{

    int i,n;

    float avg, per, total=0, arr[100];

    

    cout<<"Enter Number of Students:";

    cin>>n;

    

    for(i=1;i<=n;i++)

    {

        cout<<"Enter for"<<" "<<i<<" "<<"Student:";

        cin>>arr[i];

    }

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

    {

        total=total+arr[i];

    }

    cout<<"\nTotal cost:\n"<<total;

    

    avg=total/n;

    cout<<"\nAverage Cost:\n"<<avg;

    

    for(i=1;i<=n;i++)

    {

        if(avg>arr[i])

        {

            per=avg-arr[i];

            cout<<"\n Student "<<i<<" Paid "<<arr[i]<<" Will Give: "<<per<<"\n";

        }

        else if(avg<arr[i])

        {

            per=arr[i]-avg;

            cout<<" Student "<<i<<" Paid "<<arr[i]<<" Will Take: "<<per<<"\n";

        }

        else if(avg=arr[i])

        {

            cout<<" Student "<<i<<" Paid sufficient Amount "<<"\n";

        }

    }

}


output:




Title: Implementation of java.util package.

 Title: Implementation of java.util package.

Aim: - To study Scanner class in Java.

Theory:-

Package

                A java package is a group of similar types of classes, interfaces, and sub-packages. Package in java can be categorized in two forms, built-in package, and user-defined package.

There are many built-in packages such as java, java.lang, java.awt, java.swing, java.net, java.io, java.util, java.sql etc.

Advantage of Java Package

1) Java package is used to categorize the classes and interfaces so that they can be easily maintained.

2) Java package provides access protection.

3) Java package removes naming collision.

Java Scanner:- 

                Scanner class in Java is found in the java.util package. Java provides various ways to read input from the keyboard, the java.util.Scanner class is one of them. The Java Scanner class provides nextXXX() methods to return the type of value such as nextInt(), nextByte(), nextShort(), next(), nextLine(), nextDouble(), nextFloat(), nextBoolean(), etc. To get a single character from the scanner, you can call next().charAt(0) method which returns a single character.


                How to get Java Scanner:- To get the instance of Java Scanner which reads input from the user, we need to pass the input stream (System. in) in the constructor of the Scanner class. Syntax: Scanner in = new Scanner(System.in);

Program:-

1st program

package Section7; 

import javax.lang.model.element.Name; 

import java.util.Scanner; 

public class Main { 

    public static void main(String[] args) 

    

        String name; 

        int Roll_No; 

        float Percentage; 

        long Mobile_No; 

        char Gender; 

        double cgpa; // Creating Object for scanner class Scanner 

        sc = new Scanner(System.in); 

        System.out.println("Enter Your Name: "); 

        name = sc.next(); 

        System.out.println("Enter Roll No: "); 

        Roll_No = sc.nextInt(); 

        System.out.println("Enter Percentage: "); 

        Percentage = sc.nextFloat(); 

        System.out.println("Enter Mobile Number: "); 

        Mobile_No = sc.nextLong(); 

        System.out.println("Enter Gender: "); 

        Gender = sc.next().charAt(0); 

        System.out.println("Enter CGPA: "); 

        cgpa = sc.nextDouble(); 

        System.out.println("Name: " + name + " Roll No: " + Roll_No + " Percentage: " + Percentage + "                 Mobile No: " + Mobile_No + " Gender: " + Gender + " CGPA: " + cgpa); 

    

}


Output:





2nd Program: Even Or Odd

package Section7; 
import java.util.Scanner; 
public class EvenOddProgram {
     public static void main(String args[])
     { 
        / / Creating Object Of Scanner Class Scanner 
            Number = new Scanner(System.in); 
            System.out.println("Enter An Integer Number: "); 
            int Num = Number.nextInt(); 
            if (Num % 2 == 0)
             {
                     System.out.println("Even Number: " + Num); 
                }
             else
             {
                     System.out.println("Odd Number: " + Num);
                 }
       
}

Output:


3rd Program:Linear Search

package Section7; 
import java.util.Scanner; 
public class LinearSearch 
{
     public static void main(String args[]) 
     {
             int n, x, flag=0, i;
             // Creating Object Of Scanner Class Scanner 
            Sc = new Scanner(System.in); 
            System.out.println("Enter Number Of Elements: ");
             n = Sc.nextInt(); 
            int a[] = new int[n]; 
            System.out.println("Enter Elements of An Array: ");
             for (i = 0; i < n; i++)
             {
                 a[i] = Sc.nextInt(); 
              
            System.out.println("Enter Element To Be Searched: ");
             x = Sc.nextInt(); 
            for (i = 0; i < n; i++)
             { 
                    if (a[i] == x) 
                    
                            flag = 1; 
                            break; 
                    }
                     else
                     {
                             flag = 0; 
                    
                }
                 if (flag == 1) 
                {
                         System.out.println("Element Is Present: ");
                 }
                 else
                 {
                             System.out.println("Element Not Present: ");
                 }
          }
 }
 Out Put:


Title: Implementation of jolly jumper sequence problem.

Title: Implementation of jolly jumper sequence problem.
Aim: - To study the jolly jumper sequence problem using an array.
Theory:-

            A sequence of n > 0 integers is called a jolly jumper if the absolute values of the difference between successive elements take on all the values 1 through n-1. For instance,
1 4 2 3
            Is a jolly jumper, because the absolute differences are 3, 2, and 1 respectively. The definition implies that any sequence of a single integer is a jolly jumper. You are to write a program to determine whether or not each of a number of sequences is a jolly jumper.

Input
Each line of input contains an integer n <= 3000 followed by n integers representing the sequence.
Output
For each line of input, generate a line of output saying "Jolly" or "Not jolly".
Sample Input
4 1 4 2 3
5 1 4 2 -1 6
Sample output
Jolly
Not jolly


Program:

#include<iostream>
#include<cmath>
using namespace std;
bool isItJolly(int diff[],int n)
{
for(int i=0;i<n-1;i++)
{
if(diff[i] == 0 || diff[i] >= n)
return false;
}
return true;
}
int main()
{
int n,num[3000],i=0,difference[3000];
cout<<"Enter Number Of Elements :";
while(cin)
{
cin>>n;
while(i<n)
{
cin>>num[i];
i++;
}
for(int j=1;j<n;j++)
difference[j-1] = fabs(num[j-1]-num[j]);
if(isItJolly(difference,n))
cout<<"It is Jolly.";
else
cout<<"It is not Jolly";
}
return 0;
}

Output:





Search This Blog

Contact Form

Name

Email *

Message *

Popular Posts