Posts

Showing posts from March 4, 2018

C Programming Code To Settle Increasing And Decreasing Order Using Switch Case And Bubble Shot | C Programming

Image
C programming code to settle increasing and decreasing order using switch case and bubble shot | C Programming #include<stdio.h> int main() { int i,j,n,temp,a[100]; char choice; { printf("Press a for ascending and d for descending:"); scanf("%c",&choice);    printf("How many numbers to be inputed?"); scanf("%d",&n);      printf("\n\nEnter number one by one:\n"); for(i=0;i<n;i++) { scanf("%d",&a[i]); } switch(choice)    { case'a': for(i=0;i<n;i++) { for(j=0;j<n-i-1;j++) { if(a[j]>a[j+1]) { temp=a[j]; a[j]=a[j+1]; a[j+1]=temp; } } } printf("\n\nThe number in ascending order is:\n"); for(i=0;i<n;i++) { printf("%d\n",a[i]); } break; case 'd': for(i=0;i<n;i++) { for(j=0;j<n-i-1;j++)

C Program For Binary Search | C Programming

Image
C Program For Binary Search #include<stdio.h> int main() {     int a[100],i,n,item,flag=0,low,high,mid,j,temp;     printf("How many numbers\n");     scanf("%d",&n);     printf("Enter the value in array:-\n");     for(i=0;i<n;i++)     {         scanf("%d",&a[i]);     }     for(i=0;i<n-1;i++)     {         for (j=i+1;j<n;j++)         {             if(a[i]>a[j])              {                 temp=a[i];                 a[i]=a[j];                  a[j]=temp;             }          }     }      printf("Enter item to be searched:\n");      scanf("%d",&item);      low=0;      high=n-1;      do      {         mid=(low+high)/2;         if(item>a[mid])         {             low=mid+1;             flag=0;          }         else if (item<a[mid])         {             high=mid-1;             flag=0;          }         else         {             flag=1;             break;         }     }     while(it

C Program To Count Vowel,consonant, Special Character & Digits | C Programming

Image
C Program To Count Vowel,consonant, Special Character & Digits //Program to count vowel,consonant, special character & digits #include<stdio.h> #include<string.h> int main() { int i, vowel=0, cons=0, digit=0, sp=0, digits=0; char str[100]; printf("Enter string:\n"); gets(str); for (i=0;i< strlen(str);i++) { if (str[i]=='A'||str[i]=='a'||str[i]=='e'||str[i]=='E'||str[i]=='i'||str[i]=='I'||str[i]=='o'||str[i]=='O'||str[i]=='u'||str[i]=='U') { vowel++; } else if ((str[i]>=0&&str[i]<=47)||(str[i]>=58&&str[i]<=64)||(str[i]>=91&&str[i]<=96)||(str[i]>=123&&str[i]<=127)) { sp++; } else if (str[i]>=48&&str[i]<=57) { digits++; } } cons=strlen(str)-vowel-sp-digits; printf("vowel=%d\nConsonant=%d\nDigits=%d\n)Special Character=%d\n",vowel,cons,digits,sp); } OUTPUT

C program to check whether the word is palindrome or not

Image
#include <stdio.h> #include <string.h> int main() { char string1[20]; int i, length; int flag = 0; printf("Enter a string:"); /*scanf("%s", string1);*/ gets(string1); length = strlen(string1); for(i=0;i < length ;i++){ if(string1[i] != string1[length-i-1]){ flag = 1; break; } } if (flag==1) { printf("%s is not a palindrome", string1); } else { printf("%s is a palindrome", string1); } return 0; } OUTPUT

Linear Search in C Programming | C Programming

Image
Linear search in C Programming Linear search in C programming: The following code implements linear search (Searching algorithm) which is used to find whether a given number is present in an array and if it is present then at what location it occurs. It is also known as sequential search. It is straightforward and works as follows: We keep on comparing each element with the element to search until it is found or the list ends. Linear search in C language for multiple occurrences  and using  function . Linear search C program  span style="color: #339933;">#include<stdio.h> int main ( ) { int array [ 100 ] , search , c , n ; printf ( "Enter the number of elements in array \n " ) ; scanf ( "%d" ,& n ) ; printf ( "Enter %d integer(s) \n " , n ) ; for ( c = 0 ; c < n ; c ++ ) scanf ( "%d" , & array [ c ] ) ; printf ( "Enter the number to search \n " )

Function Templates and Class Templates in C++ Programming | C++ Programming

Templates in C++ Programming  Function templates in C++ Programming  Function templates are special functions that can operate with generic types. This allows us to create a function template whose functionality can be adapted to more than one type or class without repeating the entire code for each type. In C++ this can be achieved using template parameters. A template parameter is a special kind of parameter that can be used to pass a type as argument: just like regular function parameters can be used to pass values to a function, template parameters allow to pass also types to a function. These function templates can use these parameters as if they were any other regular type. The format for declaring function templates with type parameters is: template  function_declaration; template  function_declaration; The only difference between both prototypes is the use of either the keyword class or the keyword typename. Its use is indistinct, since both expressions have