-->

program to know a number is prime or composite or not using function.


using codeblock
-----------------------------------------------------------------------------------
//program to know a number is prime or composite or not using function..
#include<stdio.h>                      //header file
void prime_number();                          // function prototype/declaration with return type zero.
int main()                              //main function
{
prime_number();                                     // function calling.
return 0;                                       //returns 0 value
}
void prime_number()                           // function body line ; also called function definition
{
 int i,number,count=0;                    // variable declaration
printf("enter a number\n");               //message display to input a number
scanf("%d",&number);                      //gets input
for(i=2;i<number;i++)                     //executing from 2 to <n
{
    if(number%i==0)                       //testing for next number
    {
        count=1;                        //assigning to  1 to count
   
    }
   
}   
 if(count==0)                                //testing count ;whetehre it has 0 or 1
 {
    printf("%d is prime, ",number);
 } 
 else
 {
     printf("%d is not prime number,i.e. it's a composite",number);
 }
}

---------------------------------------------------------------------------------------------------------
using turbo
--------------------------------------------------------------------------------------------------------
//program to know a number is prime or composite or not using function..
#include<stdio.h>                      //header file
#include<conio.h>
void prime_number();                // function prototype/declaration with return type zero.
int main()                              //main function
{
prime_number();                                     // function calling.
getch();                                       //holds the output
return 0;                                       //returns 0 value
}
void prime_number()                           // function body line ; also called function definition
{
 int i,number,count=0;                    // variable declaration
printf("enter a number\n");               //message display to input a number
scanf("%d",&number);                      //gets input
for(i=2;i<number;i++)                     //executing from 2 to <n
{
    if(number%i==0)                       //testing for next number
    {
        count=1;                        //assigning to  1 to count
   
    }
   
}   
 if(count==0)                                //testing count ;whether it has 0 or 1
 {
    printf("%d is prime, ",number);
 } 
 else
 {
     printf("%d is not prime number,i.e. it's a composite",number);
 }
}

program to find value of y raised to x using function.


using codeblocks
------------------------------------------------------------------------------------------------------------
//program to find value of y raised to x using function.
#include<stdio.h>                      //header file
#include<math.h>                        //for pow() function
void x_power_y();                          // function prototype/declaration with return type zero.
int main()                              //main function
{
x_power_y();                                     // function calling.
return 0;                                       //returns 0 value
}
void x_power_y()                           // function body line ; also called function definition
{
 int x,y,output;                    // variable declaration
printf("enter a number;base(x)\n");    //message display to input a number
scanf("%d",&x);                //gets input
printf("enter power(y)\n");
scanf("%d",&y);                     //gets value for power.
output=pow(x,y);                    //finds power using pow() function
  printf("y raised to x=%d\n",output);    //display of output.
}

------------------------------------------------------------------------------------------------------
using turbo c++
-----------------------------------------------------------------------------------------------------------
//program to find value of y raised to x using function.
#include<stdio.h>                      //header file
#include<math.h>                        //for pow() function
void x_power_y();                          // function prototype/declaration with return type zero.
int main()                              //main function
{
x_power_y();                                     // function calling.
return 0;                                       //returns 0 value
}
void x_power_y()                           // function body line ; also called function definition
{
 int x,y,output;                    // variable declaration
printf("enter a number;base(x)\n");    //message display to input a number
scanf("%d",&x);                //gets input
printf("enter power(y)\n");
scanf("%d",&y);                     //gets value for power.
output=pow(x,y);                    //finds power using pow() function
  printf("y raised to x=%d\n",output);    //display of output.
}
-----------------------------------------------------------------------------------------------------------------

on some online compiler, this program works even without math,h
But Better if we put it.

program to find factorial value of a number using function.

using codeblocks
------------------------------------------------------------------------------------------------------

//program to find factorial value of a number using function.
#include<stdio.h>                      //header file
void factorial();                          // function prototype/declaration with return type zero.
int main()                              //main function
{
factorial();                                     // function calling.
return 0;                                       //returns 0 value
}
void factorial()                             // function body line ; also called function definition
{
 int i,n,facto=1;                    // variable declaration with 1 initialization
printf("enter a number\n");    //message display to input a number
scanf("%d",&n);                //gets input
for(i=1;i<=n;i++)       //loop running from 1 to n with increment 1 each time
{
       facto=facto*i;        //  multiplication of numbers repetitively
}
  
  printf("factorial value=%d\n",facto);    //display of output.
}
------------------------------------------------------------------------------------------------------------

using turboc++
-------------------------------------------------------------------------------------------------------------
//program  to find factorial value of a number using function.
#include<stdio.h>                      //header file
#include<conio.h>
void factorial();                          // function prototype/declaration with return type zero.
void main()                              //main function
{
factorial();                                     // function calling.
getch();                                       //holds the  value
}
void factorial()                             // function body line ; also called function definition
{
 int i,n,facto=1;                    // variable declaration with 1 initialization
printf("enter a number\n");    //message display to input a number
scanf("%d",&n);                //gets input
for(i=1;i<=n;i++)       //loop running from 1 to n with increment 1 each time
{
       facto=facto*i;        //  multiplication of numbers repetitively
}
  
  printf("factorial value=%d\n",facto);    //display of output.
}


----------------------------------------
factorial value of a number 6= 6x5x4x3x2x1 or
                                                 1x2x3x4x5x6

program to print multiplication table of a number using function

using codeblocks
--------------------------------------------------------------------------------------------------------------

//program to print multiplication table of a number using function
#include<stdio.h>                      //header file
void m_table();                          // function prototype/declaration with return type zero.
int main()                              //main function
{
m_table();                                     // function calling.
return 0;                                       //returns 0 value
}
void m_table()                             // function body line ; also called function definition
{
 int i,n;                    // variable declaration
printf("enter a number\n");    //message display to input a number
scanf("%d",&n);                //gets input
for(i=0;i<=10;i++)       //loop running from 0 to 10 with increment 1 each time
{
    printf("%d*%d=%d\n",n,i,n*i);           // displaying all the multiplied numbers
}
     
}

----------------------------------------------------------------------------------------------
using turboc++
--------------------------------------------------------------------------------------------------------
//program to print multiplication table of a number using function.
#include<stdio.h>                      //header file
#include<conio.h>
void m_table();                          // function prototype/declaration with return type zero.
void main()                              //main function
{
m_table();                                     // function calling.
getch();                                       //returns 0 value
}
void m_table()                             // function body line ; also called function definition
{
 int i,n;                    // variable declaration
printf("enter a number\n");    //message display to input a number
scanf("%d",&n);                //gets input
for(i=0;i<=10;i++)       //loop running from 0 to 10 with increment 1 each time
{
    printf("%d*%d=%d\n",n,i,n*i);           // displaying all the multiplied numbers
}
     
}

program to display all even numbers lying 1 and 200 using function.

using codeblocks
-----------------------------------------------------------------------------------------
//program to display all even numbers lying 1 and 200 using function.
#include<stdio.h>                      //header file
void even_number();                          // function prototype/declaration with return type zero.
int main()                              //main function
{
even_number();                                     // function calling.
return 0;                                       //returns 0 value
}
void even_number()                              // function body line ; also called function definition
{
 int i;                    // variable declaration
for(i=0;i<=200;i=i+2)       //loop running from 0 to 200 with increment 2 each time
{
    printf("%d\n",i);           // displaying all the numbers
}
     
}

marking scheme

Dear students,
 Please open the file attached here with.
This file is in google drive.

click here to goto drive.

program to get square root of a number using function.

using codeblocks
-----------------------------------------

//program to get  square root of a number using function.
#include <stdio.h>  //header file
#include<math.h>
void square_root();//function prototype
int main()                 //main function
{
    square_root();          // function calliing
    return 0;             // returning 0 value
}

void square_root()      //function body line/definition
{
    float n,square;       // initilizating value 1
    printf("enter value");// display of those value
    scanf("%f",&n);
   
        square=sqrt(n);            // finding sum of two numbers
        printf("square root=%f\n",square);//display of that sum
     
}
-------------------------------------------------------------------------------------------------
using turbo c++
-------------------------------------------------------------------------------------------------
//program to get  square root of a number using function.
#include <stdio.h>  //header file
#include<math.h>
#include<conio.h>
void square_root();//function prototype
void main()                 //main function
{
    square_root();          // function calliing
    getch();             // holds the output
}

void square_root()      //function body line/definition
{
    float n,square;       // initilizating value 1
    printf("enter value");// display of those value
    scanf("%f",&n);
   
        square=sqrt(n);            // finding sum of two numbers
        printf("square root=%f\n",square);//display of that sum
     
}