function programs example in C language programming near me

In this blog Study we will study about the method of declaration of the user-defined function to and its use In C language. the scope of the variables such as automatic external and static and register is explained. The recursive function is described in this blog with numerous illustrations. The additional details of the function set preprocessor macros haters and standard function are also explained in this blog topic.

In this blog we will study in C language there is no difference between a function and subroutine. The function may or may not take some formal arguments and call a portion of the program. the function is on me not transfer back, value to call function block. it me behave like a traditional subroutine or as function or as both. secondary most high level languages differentiate between a main program and some programs. easy language all modules are called functions and they all have the same structure in programming.

How to define function in C language ?


this blog I will help you to define a function in C language” function definition has name of parenthesis containing zero or more parameters and a body. for each parameter there should be a corresponding declaration that occurs before the body. any parameters not declared is taken to be e an int by default. it is good programming practice to declare all parameters.

so we will see the general format of function definition is given as follows

function_type function_name( data_type argument 1 , data_type augment 2)

{


Body of the function

------------------------------------

-----------------------------------

return statement


}



Local and global variable in C plus plus and C language
1:-Write a program using function Creating a user defined function addition().

Programming 5 axis cnc, java web services rest, java spring tutorial, java rest api,java point, java virtual machine, java executor framework, java for windows 7, restful  web services java, java web services soap, java 8 download, programming game ai by example, programming questions in java, programming quotes, programming for problem solving, programming with mosh, programming near me, programming in visual basic, programming python pdf, programming r, programming aptitude test, c program to find sum of n numbers using for loop, c program to find sum of n numbers using function, sum of numbers from 1 to 100 in c, c program for sum of two numbers, c program to find multiples of a number, c program to find sum of n numbers using array, c program to find sum of 10 numbers using function, how to find multiples of a number in c++,
function

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

int addition (int num1, int num2)

{

int sum;

sum = num1+num2;

return sum;

}

int main ()

{

int var1, var2;

printf("Enter number 1: ");

scanf("%d", &var1);

printf("Enter number 2: ");

scanf("%d", &var2);

int res = addition (var1, var2);

printf ("Output: %d", res);

getch();

}

Output :-

Enter number 1: 100

Enter number 2: 120

Output: 220

Some special and important program of c language and c++

2:- Creating a void user defined function that doesn’t return anything .


#include <stdio.h>

void intro ()

{

printf("Hi\n");

printf("My name is SHIVA\n");

printf("How are you?");

}

int main()

{

Intro ();

return 0;

}

Output:-

Hi

My name is SHIVA

How are you?



3- Write C language program Sum of Natural Numbers Using Recursion function.

#include <stdio.h>

int sum (int n);

int main () {

int number, result;

printf("Enter a positive integer: ");

scanf("%d", &number);

result = sum(number);

printf("sum = %d", result);

return 0;

}

int sum (int n)

{

if (n != 0)

return n + sum(n-1);

else

return n;

}

Output :-

Enter a positive integer:3

sum = 6

4:- Program in c language calculates the factorial of a given number using a recursive function.

#include <stdio.h>

unsigned long long int factorial(unsigned int i) {

if(i <= 1) {

return 1;

}

return i * factorial(i - 1);

}

int main() {

int i = 12;

printf ("Factorial of %d is %d\n", i, factorial(i));

return 0

}

Output:- Factorial of 12 is 479001600

5:- Program of C language generates the Fibonacci series for a given number using a recursive function.

#include <stdio.h>

int fibonacci(int i)

{

If (i == 0) {

return 0;

}

If (i == 1)

{

return 1;

}

return fibonacci(i-1) + fibonacci(i-2);

}

int main() {

int i;

for (i = 0; i < 10; i++) {

printf ("%d", fibonacci(i));

}

return 0;

}

Output:-

0 1 1 2 3 5 8 13 21 34

6:- A C++ program to demonstrate working of recursion function.

#include<stdio.h>

#include <conio.h>

using namespace std;

void printFun(int test)

{

if (test < 1)

return;

else {

cout << test << " ";

printFun(test - 1); // statement 2

cout << test << " ";

return;

}

}

int main()

{

int test = 3;

printFun(test);

}

Output:-

3 2 1 1 2 3

Simple program of c language related to array

Post a Comment

0 Comments