Posts

Showing posts from November, 2021

bubble sort program in cpp c++

#include<iostream> using namespace std ; int main() { int n, i, arr[50], j, temp; cout << "Enter the Size (max. 50): " ; cin >>n; cout << "Enter " <<n<< " Numbers: " ; for (i=0; i<n; i++) cin >>arr[i]; cout << " \n Sorting the Array using Bubble Sort Technique.. \n " ; for (i=0; i<(n-1); i++) { for (j=0; j<(n-i-1); j++) { if (arr[j]>arr[j+1]) { temp = arr[j]; arr[j] = arr[j+1]; arr[j+1] = temp; } } } cout << " \n Array Sorted Successfully! \n " ; cout << " \n The New Array is: \n " ; for (i=0; i<n; i++) cout <<arr[i]<< " " ; cout << endl ; return 0; }

cpp program binary search program in c++

#include<iostream> using namespace std ; int main() { int i, arr[10], num, first, last, middle; cout << "Enter 10 Elements (in ascending order): " ; for (i=0; i<10; i++) cin >>arr[i]; cout << " \n Enter Element to be Search: " ; cin >>num; first = 0; last = 9; middle = (first+last)/2; while (first <= last) { if (arr[middle]<num) first = middle+1; else if (arr[middle]==num) { cout << " \n The number, " <<num<< " found at Position " <<middle+1; break ; } else last = middle-1; middle = (first+last)/2; } if (first>last) cout << " \n The number, " <<num<< " is not found in given Array" ; cout << endl ; return 0; }

cpp c++ program for linear search

#include<iostream> using namespace std ; int main() { int arr[10], i, num, location; cout << "Enter 10 Numbers: " ; for (i=0; i<10; i++) cin >>arr[i]; cout << " \n Enter a Number to Search: " ; cin >>num; for (i=0; i<10; i++) { if (arr[i]==num) { Location = i; break; } } cout << " \n Found at location : " <<location; cout << endl ; return 0; }

array in php

Image

conditional statements in php

Image

looping statements in php

Image

factorial c++ without recursion

#include <iostream> using namespace std; int main() { unsigned int num; //unsigned is used for not taking negetive values. unsigned long long factorial = 1; //Since the factorial a number can be large, so long long data type is used. cout << "Give me any positive number : "; cin >> num; for (int i = 1; i <= num; i++) { factorial = factorial * i; } cout << "Factorial of the given number is: " << factorial; }

fibonacci series program in C++ without recursion.

#include <iostream>    using   namespace  std;   int  main() {      int  n1=0,n2=1,n3,i,number;      cout<< "Enter the number of elements: " ;      cin>>number;      cout<<n1<< " " <<n2<< " " ;  //printing 0 and 1        for (i=2;i<number;++i)  //loop starts from 2 because 0 and 1 are already printed       {       n3=n1+n2;       cout<<n3<< " " ;       n1=n2;       n2=n3;      }         return  0;      }  

fibonacci series using recursion cpp

#include <iostream> using namespace std ; int fib ( int x ) {     if (( x == 1 )||( x == 0 )) {       return ( x );     } else {       return ( fib ( x - 1 )+ fib ( x - 2 ));     } } int main () {     int x , i = 0 ;    cout << "Enter the number of terms of series : " ;    cin >> x ;    cout << "\nFibonnaci Series : " ;     while ( i < x ) {       cout << " " << fib ( i );       i ++;     }     return 0 ; }

Factorial Using Recursion c++

# include <iostream> using namespace std ; int factorial ( int n) ; int main () { int n; cout << "Enter a positive integer: " ; cin >> n; cout << "Factorial of " << n << " = " << factorial(n); return 0 ; } int factorial ( int n) { if (n > 1 ) return n * factorial(n - 1 ); else return 1 ; }

c++ program for sum of 10 array elements

include<iostream> using namespace std ; int main ( ) { int arr [ 10 ] , n, i, sum = 0 , pro = 1 ; cout << "Enter the size of the array : " ; cin >> n ; cout << " \n Enter the elements of the array : " ; for ( i = 0 ; i < n ; i ++ ) cin >> arr [ i ] ; for ( i = 0 ; i < n ; i ++ ) { sum + = arr [ i ] ; pro * = arr [ i ] ; } cout << " \n Sum of array elements : " << sum ; cout << " \n Product of array elements : " << pro ; return 0 ; }