--program--
Title; Even Or Odd
Programm:
Easy programming and better way to learn the programming . if you like the scorce code do like like share and subscribe the chennel.
--program--
Title; Even Or Odd
Programm:
Title:- Progam to count the occurrence of a substring in the string
Program
Title : Reverse the number
Program:
//program to calculate the rteverse tof the enterdnumber;
Title: Print statement without using semicolan(;)
Program:
Title : Natural Number Without using Loop
Program:
Title: Min max without using if else
Program:
Title :- linear Search
Program:
Decimal to binary
program:
Aim : armStrong number
Program
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
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
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:
Title: implementation of stack
Aim: a study of the implementation of stack
Theory:
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
#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
#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.
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: