Welcome To Uday Satya Blog

41 - 45 PROGRAMS


                                                                                                                                               /*****************************************************
    41. To Print Multiplication Table of a Number using for loop
   *************************************************** */

 
#include<*stdio.h>
   #include<*conio.h>

   void main()
    {
    int n,i;
    clrscr();
    printf("\n Enter n,To Print Multiplication Table of it : ");
    scanf("%d", &n);
    for(i = 1;i <= 10;i++)
    printf("\n %d * %d = %d \n", n, i, n*i);
    getch();
    }

   Output :
   Enter n,To Print Multiplication Table of it : 5
   5 * 1 = 5
   5 * 2 = 10
   5 * 3 = 15
   5 * 4 = 20
   5 * 5 = 25
   5 * 6 = 30
   5 * 7 = 35
   5 * 8 = 40
   5 * 9 = 45
   5 * 10 = 50
                                                                                                  

 *************************************************
     42. To Find Factorial of a Given Number using for loop
    ********************************************** */

  
#include<*stdio.h>
   #include<*conio.h>

   void main()
    {
    int n,s = 1,i;
    clrscr();
    printf("\n Enter n,To Find Faactorial of it : ");
    scanf("%d", &n);
    for(i = 1;i <=n;i++)
        s = s * i;
    printf("\n\n Factorial of %d is : %d", n, s);
    getch();
    }

   Output :

   Enter n,To Find Factorial of it : 5

   Factorial of 5 is 120

                                                                                                                                                 
/* **********************************************
     43. To Print n fibonacci numbers using for loop
   ********************************************* */

  
#include<*stdio.h>
   #include<*conio.h>

   void main()
    {
    int n,a = 0,b = 1,c,i;
    clrscr();
    printf("\n Enter n,To Print First n Fibonacci Series Numbers : ");
    scanf("%d", &n);
    printf("\n %d \n", a);
    printf("\n %d \n", b);
    for(i = 2;i < n;i++)
        {
        c = a + b;
        printf("\n %d \n", c);
        a = b;
        b = c;
        }
    getch();
    }

   Output :
 
   Enter n,To print First n Fibonacci Series Numbers : 6
   0
   1
   1
   2
   3
   5
                                                                                                                                        
                                                                                                                                                  /* ****************************************
        44. To Check for a Prime Number or not
    *************************************** */

   #include<*stdio.h>
   #include<*conio.h>
   void main()
    {
    int n,i,s = 0;
    clrscr();
    printf("\n Enter any Number,To Check for Prime Number : ");
    scanf("%d", &n);
    for(i = 2;i < n;i++)
        if(n % i == 0)
            s++;
    if(s==0)
        printf("\n\n %d is a Prime Number", n);
    else
        printf("\n\n %d is not a Prime Number", n);
    getch();
    }

   Output :
  
   Enter any Number,To Check for Prime Number : 5

   5 is not a Prime Number
                                                                                                                                                  /* **************************************
      45. To Check for a Perfect Number or not
    ************************************** */

 
#include<*stdio.h>
   #include<*conio.h>

   void main()
    {
    int n,i,s = 0;
    clrscr();
    printf("\n Enter any Number,To Check for Perfect Number : ");
    scanf("%d", &n);
    for(i = 1;i < n;i++)
        if(n % i == 0)
            s = s + i;
    if(n == s)
        printf("\n\n %d is a Perfect Number", n);
    else
        printf("\n\n %d is not a Perfect Number", n);
    getch();
    }

   Output :

   Enter any Number,To Check for Perfect Number : 6

   6 is a Perfect Number

0 comments:

Post a Comment