Posts

Write a function isprime() which takes a number and returns 1 if the number is prime and 0 otherwise.

Image
    What is a prime number in definition? A prime number is a whole number is greater than 1whose only factors are 1 and itself. A factors a whole number that can be  divided evenly into another number. The first few prime number are : 2, 3, 5, 7, 11, 13, 17, 19 and  23  etc.  The following program check the input number is prime or not. #include <stdio.h> int isprime( int ); int main() {     int num;     printf( "Enter the Number check it is prime or not :" );     scanf( "%d" ,&num);     if (isprime(num))     {         printf( "%d is prime number.\n" , num);     }     else     {         printf( "%d is not a prime number.           \n" ,num);     }     return 0 ; } int isprime( int n) {     int i = 2 ;     while (i<n)     { ...

Program of Palindrome number.

Image
  What is Palindrome number  ? A palindrome  number is a number  that remains same when digits are reversed. For example, the number 1551 is a palindrome number, but 1541 is not a palindrome number.  * note : Negative number can not be palindrome. Now here we understand the following program is palindrome or not. #include <stdio.h> int reverse( int ); int palindrome( int ); int main() {     int num;     printf( "Enter the number check it isPalindrome or not : " );     scanf( "%d" ,&num);     if (palindrome(num)) // 1 for true or 0 for false     {         printf( "%d is palindrome.\n" ,num);     }     else     {         printf( "%d is not palindrome." ,num);     }     return 0 ; } int palindrome( int n) {     if (n==reverse(n)) // if reverse and the number is equal then it isPalindrome...

program to convert a binary number to a decimal number.

Program to convert a binary to decimal number. #include <stdio.h> int main() {     int n, sn, i = 1 , dec = 0 , rem;     printf( "Enter a binary number:\t" );     scanf( "%d" , &n);     sn = n;     while (n > 0 ) /* work when number is greater than 0.*/     {         rem = n % 10 ; // reminder is 0 or 1 only         if (rem == 1 || rem == 0 ) //binary number         {             dec = dec + rem * i;             i *= 2 ; // power of 2's.             n = n / 10 ;         }     }     printf( "Decimal Equivalent of %d is %d " , sn, dec);     return 0 ; } Output : Enter a binary number: 1101 Decimal Equivalent of 1101 is 13 for this we extract binary digits from right and add them after multiplying power of ...

Write a program that accepts marks in five subjects and calculates the total percentage marks.

program find out the percentage of a student. In this program we have take marks of student out off  100 where marks in real form then be use float type variable declare 5 variable m1,m2,m3,m4,m5 float type. Now we find out the percentage of a student in five subjects. take a variable store the value of %age as float type. firstly, find sum of marks gain by the student, then after % = (sum/500)*100 we can also write sum/5 ; #include <stdio.h> int main() {     float m1,m2,m3,m4,m5,per,sum;     printf( "Marks in English:" );     scanf( "%f" ,&m1);     printf( "Marks in Hindi:" );     scanf( "%f" ,&m2);     printf( "Marks in Physics:" );     scanf( "%f" ,&m3);     printf( "Marks in Maths:" );     scanf( "%f" ,&m4);     printf( "Marks in Chemistry:" );     scanf( "%f" ,&m5);     sum=m1+m2+m3+m4+m5;     per=sum/ 5 ;     p...

Delimiters In C

 Delimiters :  A delimiter is one or more character that separate text string. when a program stores sequential or tabular data, it delimits each items of data with a predefine character.  Delimiters are used  for syntactics in C. :           colon                               used  for label         ;           semicolon                       end of statement ()          parentheses                   used in expression []          square brackets           used for array {}        curly braces                   used for block of...

Digraph and Trigraph characters in C

Digraph Character : The Diagraph are sequence of two character that the compiler replaces with their corresponding punctuation character. Digraph sequence Symbol <% { left brace %> } right brace <: [ left bracket :> ] right bracket %: # hash %: include <stdio.h> int main() <%     printf( "Hello world!" );     return 0 ; %> which is treated the same as :- #include <stdio.h> int main() {       printf( "Hello world!" );     return 0 ; } Trigraph Character : Trigraph are sequence of three characters (introduced by two consecutive Question marks ) that the compiler replaces with their corresponding punctuation characters.  some keywords may not have all the characters from the C character set. C supports the facility of "trigraph sequence" to print these characters. These trigraph sequences have three characters. First two are '??' and third character from C character set. some trigraph sequences are as given...

Escape Sequences/Execution characters

 Escape Sequence / Execution Character Some characters such as newline, tab, backspace cannot be displayed like other normal characters. C supports the combination of backslash (\) and some characters from the C character for representing these character in our C programs. These character combinations are  known as escape sequences and are represented by two characters. The first character is "\" and second character is from the C character set. some escape sequences are given below - Escape sequence Meaning purpose \a Beep /alert Produce an audible and visible alert \b Backspace Move the cursor to the previous position of the current line. \f Form feed Moves the cursor to the initial position of the next logical page. \r Carriage return Moves the cursor to the beginning of the current line \t Tab (horizont...