Skip to main content

Posts

Showing posts from August, 2020

C Programs : Basic Problems And Its Output

C Basics Programs 1.Check a string is a palindrome or not? Program:- #include<stdio.h> #include<string.h> void isPalindrome(char *str) { int i,l,h; l=strlen(str); i=0; h=l-1; while(h>i) { if(str[i++]!=str[h--]) { printf("Not Palindrome"); return; } } printf("Palindrome"); } int main() { int i,l,flag=0; char str[20]; printf("Enter a string:-"); scanf("%s",str); isPalindrome(str);    return 0; } Output :- Enter a string:- abcdcba Palindrome 2.Find the maximum frquency of a character in a string. Program:- #include<stdio.h> #include<string.h> //#define ASCII_SIZE 256 char string_freq(char *str) { int i,j,l,cmax=0,count; char s; l=strlen(str); for(i=0;i<l;i++) { count=1; for(j=i+1;j<l;j++) { if(str[i]==str[j]) { count++; } } if(cmax<count) { cmax=count; s=str[i]; } } printf("\n%d",cmax); return s; } in...

Fibonacci Series : C Program To Find The Index Of an Input Number

What is Fibonacci Series The problem is to find the index of a number that occurs in the Fibonacci series. Fibonacci series starts from zero. Sequence such as 0 1 1 2 3 5 8 13 21 34 55.......etc. The sequence is the sum of two previous values in the series.                                                                                 Algorithm :- Enter the number, you want to find the index in the Fibonacci series, read as n. Declare three integer variable, read as a, b, c, res, these variables are used to find the Fibonacci series. Initialize the variable a=0, series start from zero, b=1, c=1 and res=1,here res is the index of the Fibonacci series. We have to check, if n is less than or equal to one then return 1; else run the while loop in the next. For while loop variables a, b, c are ...

Merge Arrays : Merge Two Arrays Of Different Size In C++

Merge Two Arrays C++ Program C++ program to merge two arrays of different size. First array size is m and second array size is n. The size of the first array is greater than the first array i.e. m>n.                               Algorithm :- Enter the size of first array m. Enter the size of 2nd array n. Enter the elements of 1st and 2nd array and number of elements of first array should be greater than the number of elements of second array. After m index of first array, insert the element of second array into the first array up to m+n-1. Sort the merge array of size m+n. Display the first array, which will display all the elements of the merge array of size m+n. Program: - #include<iostream> using namespace std; int main() { int i,n,m,a[15],b[5],j;//array a[] and b[] are declared cout<<"Enter the size 1st array:-"<<endl; cin>>m; cout<<"Enter the size of 2nd array(n<m...

C++ Vector : Basics Of Vector in C++ STL

In C++, Vector is unlike array, it stores different data types such as int, double, string, float, etc. It works like the dynamic array with the ability to resize automatically itself. Vector stores data in the contiguous memory location. Two functions are needed to traverse from starting to end that is begin() and end() functions.                               Syntax of the vector declaration:-             vector<data_type> variable_name (number_of_elements);  Here number_of_elements is optional, we can also declare a vector with empty vector that contains zero elements. The data_type in the angle-brackets indicates any type of data type which is valid in c++. Vector declaration examples:- vector<int> numbers (10); //In this example, we declared a vector name number of 10 integers. vector<string> names;  //In this, a vector name declared of string. In eve...