Skip to main content

Posts

Showing posts with the label C Programming

Graphics in C: Using Colors in Text Mode

Graphics in C/C++: Using Colors in Text Mode In Advance Learning Tutorial, today we will learn about the colors in C / C + +. So far, you have used only two colors in your program Black and White, Black color in Background and White color foreground, i.e. to print the character. By default, all compilers use these two colors. But if you want to print any character on your screen from the color of your choice, then you can do it with the help of the functions described below. Keep in mind that the functions described below will only run on Text Mode. Using the colors, you can make your program more attractive in C /C++. Total 15 colors have been defined in C++. To use any color, you can use the name of that color or the corresponding value of that color. This value is already defined in the compiler. All the 15 colors and their values are given in the table below. Values of Colors 1. BLACK 0 2. BLUE 1 3. GREEN 2 4. CYAN 3 5. RED 4 6...

Difference between C and C++

Difference between C and C++ C & C++  are computer programming languages that are used to write programs to communicate with computer. Here we will learn what is C and C++ programming languages and what are the differences between them. Firstly we have to know, what is computer programming language? A computer programming language is the medium of communication between computer hardware and user, where user instruct to the computer through some instructions (written in any programming language) to perform some specific types. Now a day there are many popular computers programming languages like – Assembly, C, C++, Java, Android, Ruby, Python etc. C and C++ programming differences C programming language C is a middle level computer programming language developed at Bell Lab at 1972 by Dennis Ritchie, C is considered as Middle Level Language because of its features. C language contains features of Low Level Language as well as High Level Language. C++ programmi...

Palindrome number in C

Palindrome number in C #include <stdio.h>   int   main ( ) {     int   n ,   reverse   =   0 ,   t ;       printf ( "Enter a number :  \n " ) ;     scanf ( "%d" ,   & n ) ;      t   =   n ;       while   ( t   !=   0 )     {       reverse   =   reverse   *   10 ;       reverse   =   reverse   +   t % 10 ;       t   =   t / 10 ;     }       if   ( n   ==   reverse )         printf ( "%d is a palindrome number. \n " ,   n ) ;     else         printf ( "%d isn't a palindrome number. \n " ,   n ) ;       return   0 ; } Output : Enter a number : 12321 12321  is a palindrome number.

C Program to Check whether a given Number is Armstrong

C Program to Check whether a given Number is Armstrong /* * C Program to Check whether a given Number is Armstrong */ #include <stdio.h> #include <math.h>   void main ( ) { int number , sum = 0 , rem = 0 , cube = 0 , temp ;   printf ( "enter a number : " ) ; scanf ( "%d" , & number ) ; temp = number ; while ( number != 0 ) { rem = number % 10 ; cube = pow ( rem , 3 ) ; sum = sum + cube ; number = number / 10 ; } if ( sum == temp ) printf ( "The given no is armstrong no" ) ; else printf ( "The given no is not a armstrong no" ) ; } Output : enter a number : 370 The given no is armstrong no enter a number : 1500 The given no is not a armstrong no

Fibonacci series C program

Fibonacci series C program #include <stdio.h>   int  main ( ) {    int  n ,  first  =   0 ,  second  =   1 ,  next ,  c ;      printf ( "Enter the number of terms \n " ) ;    scanf ( "%d" ,   & n ) ;      printf ( "First %d terms of Fibonacci series are: \n " ,  n ) ;      for   ( c  =   0 ;  c  <  n ;  c ++ )    {      if   ( c  <=   1 )       next  =  c ;      else      {       next  =  first  +  second ;       first  =  second ;       second  =  next ;      }      printf ( "%d \n " ,  next ) ;    }      return   0 ; } Output : Ent...

C Programming convert decimal number to binary

C Programming convert decimal number to binary Examples // convert decimal number to binary #include #include long long convertDecimalToBinary(int n); int main() { int n; printf("Enter a decimal number: "); scanf("%d", &n); printf("%d in decimal = %lld in binary", n, convertDecimalToBinary(n)); return 0; } long long convertDecimalToBinary(int n) { long long binaryNumber = 0; int remainder, i = 1, step = 1; while (n!=0) { remainder = n%2; printf("Step %d: %d/2, Remainder = %d, Quotient = %d\n", step++, n, remainder, n/2); n /= 2; binaryNumber += remainder*i; i *= 10; } return binaryNumber; } Output Enter a decimal number: 19 Step 1: 19/2, Remainder = 1, Quotient = 9 Step 2: 9/2, Remainder = 1, Quotient = 4 Step 3: 4/2, Remainder = 0, Quotient = 2 Step 4: 2/2, Remainder = 0, Quotient = 1 Step 5: 1/2, Remainder = 1, Quotient = 0 19 in decimal...

c programming convert binary to decimal

c programming Convert Binary Number to Decimal Examples // Convert Binary Number to Decimal #include #include int convertBinaryToDecimal(long long n); int main() { long long n; printf("Enter a binary number: "); scanf("%lld", &n); printf("%lld in binary = %d in decimal", n, convertBinaryToDecimal(n)); return 0; } int convertBinaryToDecimal(long long n) { int decimalNumber = 0, i = 0, remainder; while (n!=0) { remainder = n%10; n /= 10; decimalNumber += remainder*pow(2,i); ++i; } return decimalNumber; } Output Enter a binary number: 110110111 110110111 in binary = 439

C programming - Calculate Average Using Arrays

C programming - Calculate Average Using Arrays Examples #include int main() { int n, i; float num[100], sum = 0.0, average; printf("Enter the numbers of elements: "); scanf("%d", &n); while (n > 100 || n Output Enter the numbers of elements: 6 1. Enter number: 45.3 2. Enter number: 67.5 3. Enter number: -45.6 4. Enter number: 20.34 5. Enter number: 33 6. Enter number: 45.6 Average = 27.69

C Reverse a Sentence Using Recursion

C Reverse a Sentence Using Recursion Examples #include void reverseSentence(); int main() { printf("Enter a sentence: "); reverseSentence(); return 0; } void reverseSentence() { char c; scanf("%c", &c); if( c != '\n') { reverseSentence(); printf("%c",c); } } Output Enter a sentence: margorp emosewa awesome program