-->

program with FUNCTION WITH ARGUMENTS AND RETURNING NO VALUES.

FUNCTION WITH  ARGUMENTS AND  RETURNING NO VALUES.


click the link for program(below).
----------------------------------------------------------------------------------------------------------

1) WAP to pass array as parameter to input any five numbers and then find their sum.

                                                                                                                                        solution

2) wap to get length of string by passing string as parameter.
                                                                                                                                        solution


3)WAp to find greatest number among ten numbers. PAss array as parameter.

                                                                                                                                        solution

4)WAP to input weight of 100 students and count number of students who have weight in between 40 and 60 kg. Pass Weight as an array as parameter.


                                                                                                                                        solution


5)WAP to search a number in a list of numbers using array as a parameter.

                                                                                                                                           solution



6)WAP to input 'n' numbers and sort them in an order. PAss array as a parameter.
                                                 
                                                                                                                                           solution


7)WAP to input strings and sort them in alphabetical order. Pass string as a parameter.

                                                                                                                                         solution

8)WAp to find transpose of a matrix. Here , pass matrix as parameter.
 
                                                                                                                                        solution

9)WAP to find sum of two matrices. Here pass matrix as parameter.

                                                                                                                          solution

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
}
     
}