Skip to main content

Posts

Showing posts from July, 2021

C Program to Generate and Print Fibonacci series upto a given inputted number

 C Program to Generate and Print Fibonacci series upto a given inputted number     In this example, we will generate and print fibonacci series upto a the upper limit entered by the user. To solve this problem we should have a proper concept on Fibonacci series and while loop.  What is a Fibonacci Series? Fibonacci series is the sum of the two preceding numbers, starting from 0 and 1.     For Example: 0,1,1,2,3,5,8,13,....,etc  PROGRAM #include <stdio.h> #include <conio.h> void   main () {      int   n , x1 , x2 , x3 = 0 ;      printf ( "Enter the limit upto which fibonacci series to be generated : " );      scanf ( " %d " ,& n );      x1 = 0 ;      x2 = 1 ;      printf ( " %d \t %d " , x1 , x2 );      x3 = x1 + x2 ;      while ( x3 <= n )     {          printf ( " \t %d " , x3 );          x1 = x2 ;          x2 = x3 ;          x3 = x1 + x2 ;     }      getch (); } OUTPUT: Enter the limit upto which fibonacci series to be g

C Program to Check Whether a given Number is Prime or Not

 C Program to Check Whether a given Number is  Prime or Not     In this example, we will check whether a given number is Prime or Not. To solve this problem we should know about Prime Numbers. What is a Prime Number?      Prime Numbers are those numbers which can only be divisible by 1 and the number itself.          For Example: 2,3,5,7,etc are prime numbers, as these numbes are only divisible by 1 and the number itself.   PROGRAM: #include <stdio.h> #include <conio.h> int   main () {      int   x , i , count = 0 ;      printf ( " \n Enter the number : " );      scanf ( " %d " ,& x );      for ( i = 1 ; i <= x ; i ++)     {          if ( x % i == 0 )              count ++;     }      if ( count == 2 )     {          printf ( " \n %d  is a Prime Number" , x );     }      else     {          printf ( " \n %d  is Not a Prime Number" , x );     } } OUTPUT:  Enter the number : 5  5 is a Prime Number NOTE:   You Can Comment You

C Program to Check a given Number is Armstrong or Not

 C Program to Check a given Number is Armstrong or Not.     In this example, we will check a number entered by the user whether it is an Armstrong number or not. To solve this program we should have a proper concept on Armstrong number, while loop and if-else statement. What is an Armstrong Numer?           An Armstrong number is a positive number that is equal to the sum of the power of the digits. For Example: Let's take 153:  1 3  + 5 3  + 3 3                                                                    = 1 + 125+ 27                                                                   = 153     which means 153 is an Armstrong number. PROGRAM #include <stdio.h> #include <conio.h> int   main () {      int   num , a , r , sum = 0 ;      printf ( " \n  Enter the Number : " );      scanf ( " %d " ,& num );      a = num ;      while ( a > 0 )     {          r = a % 10 ;          sum = sum + r * r * r ;          a = a / 10 ;     }      if (

C Program to Print first N Even Natural Number/in Reverse Order

  C Program to Print first N Even Natural Number.     In this example, we will find and print the first N even natural. Here we have used for loop to solve this program.      What are Natural Numbers? Natural Numbers are all positive numbers starting from 1 to infinity.      For Example:  1,2,3,4,5,6,.............................,n are all natural numbers. What are Even Numbers? Even numbers are those numbers whose remainder is 0 when divided by 2.     For Example: 2,4,6,8,10,.....,n are all even numbers.   PROGRAM: #include <stdio.h> #include <conio.h> void   main () {      int   i , x ;      printf ( "Enter the value of N : " );      scanf ( " %d " ,& x );      for ( i = 1 ; i <= x ; i ++)     {          printf ( " %d " , 2 * i );     }      getch (); } OUTPUT: C Program to Print First N Even Natural Number in Reverse Order. PROGRAM 123 #include <conio.h> #include <stdio.h> int   main () {      int   i , x ;      printf

C Program to Check a Whether a Number is Divisible by 5 or Not

 C Program to Check a Whether a Number is Divisible by 5 or Not            In this program we will check a number entered by the user will be divisible by 5 or Not. We have solved this problem using if-else statement. Program: #include <stdio.h> #include <conio.h> int  main() {      int  x;     printf( "Enter a number" );     scanf( "%d" ,&x);      if (x% 5 == 0 )         printf( "The number %d is divisible by 5" ,x);      else         printf( "The number %d is not divisible by 5" ,x);      return   0 ; } Output: NOTE:   You Can Comment Your Code if you have solved differently and we will pin it in the comment section.  Let's Learn together.  MOTTO:  You Learn, I Learn together We Learn.  

C Program to Check Even or Odd Without Modulous and Bitwise Operator

  C Program to Check Even or Odd Without Modulous and Bitwise Operator                   In this example we will check even or odd without Modulous Operator. To do this program we should know what is even and odd number.                   Even Number: Even numbers are those numbers which are divisible by 2. That means if we divide a number by 2 and if its remainder appears 0 then it is an even number.                                 For Example: 2,4,6,8,10,12,.... are all even numbers.                                                 Odd Number: Odd numbers are those numbers which are not divisible by 2. That means if we divide a number by 2 and if its remainder appears 1 then it an odd number.                                 For Example: 1,3,5,7,9,11,........ are all odd numbers.                                                                 Program: #include <stdio.h> #include <conio.h> int  main() {      int  x;     printf( "\nEnter two num

C Program to Generate Multiplication Table according to User Choice.

 C Program to Generate Multiplication Table according to User Choice.     In this program, we will learn how to print a multiplication table according to any positive number entered by the user. This program uses for loop to solve this problem.  C PROGRAM TO GENERATE MULTIPLICATION TABLE: # include < stdio.h > # include < conio.h > int   main () {      int   i , num , res = 0 ;      printf ( "\n Enter the multplication table you want :  " );      scanf ( " %d " ,& num );      printf ( "\n\n\n\t MULTIPLICATION TABLE OF  %d \t" , num );      printf ( "\n -------------------------------------------------- \n" );      for ( i = 1 ; i <= 10 ; i ++)      {          res = num * i ;          printf ( "\t %d   x  %d  =  %d \n" , num , i , res );      }      printf ( "\n\n" );      return   0 ; } OUTPUT: NOTE:   You Can Comment Your Code if you have solved differently and we will pin it in the comment section.  Let&

C Program to determine the Range and Average of the values entered by the user(to terminate enter -1).

C Program to determine the Range and Average of the values entered by the user(to terminate enter -1).     This is a program to calculate the range and average of the values entered by the user and to terminate it by entering -1 and it will determine the highest-value, lowest-value, range, average and also it will count the number of values entered by the user. PROGRAM: #include <stdio.h> #include <math.h> int   main () {      int   count = 0 ;      float   value , high , low , average , range , sum = 0 ;      printf ( "Enter the values (to terminate enter -1) : \n " );      while ( 1 )     {          scanf ( "%f" ,& value );          if ( value !=- 1 )         {              count ++;              sum = sum + value ;              if ( count == 1 )             {                  low = high = value ;             }              else   if ( value > high )             {                  high = value ;             }              else   if ( value <

C Program To Swap Two Numbers Without Using/Using Third Variable

  C PROGRAM TO SWAP TWO NUMBERS.   In this example, we will learn how to swap two numbers using third variable.   FLOWCHART TO SWAP TWO NUMBERS:         PROGRAM:   #include <stdio.h> int   main () {      int   a , b , c ;      printf ( "Enter the value of a : " );      scanf ( "%d" ,& a );      printf ( "Enter the value of b : " );      scanf ( "%d" ,& b );      printf ( " \n Before swapping values of a=%d and b=%d" , a , b );      c = a ;      a = b ;      b = c ;      printf ( " \n After swapping values of a=%d and b=%d" , a , b ); }   OUTPUT:     C PROGRAM TO SWAP TWO NUMBERS WITHOUT USING THIRD VARIABLE.                Here, we will see how to swap two numbers without using third variable.             FLOWCHART TO SWAP TWO NUMBERS WHITHOUT USING THIRD VARIABLE:     PROGRAM:   #include <stdio.h> int   main () {      int   a , b ;      printf ( "Enter t

C program to calculate area of a circle using function.

C program to calculate area of a circle. In this example we will learn to calculate the area of a circle. Here in this program we will use 3.14 as the value of pi.  The formula to calculate the area of a circle is:                                                         area=   π  r² Flowchart To Calculate the Area of a Circle: PROGRAM: #include <conio.h> #include <stdio.h> int   main () {      float   radius , area ;      printf ( "Enter the radius of the circle : " );      scanf ( "%f" ,& radius );      area = 3.14 * radius * radius ;          printf ( "Area of the circle is : %.2f" , area );      return   0 ; } OUTPUT: C program to calculate area of a circle using function.           Here, we will learn how to calculate the area of a circle using function. Program: #include <conio.h> #include <stdio.h> float   circle ( float ); int   main () {      float   radius , area ;      printf ( "Enter the radius of the circle :