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


Search This Blog

Contact Form

Name

Email *

Message *

Popular Posts