Program : Write a program to call function through for loop in C
Today we will write a program in C programming language in which we will call a user define function with the help of for loop. This user define function can return any value, because you will get the same type of result as the instructions written in it.
First we will see a small example in which we will print a string, but this string will be printed only after calling the function by loop. This means that in this small example we will see how a function is called with the help of a for loop. So let's see a small example.
Also Read :
This is a small example showing how we can print a string when a function is called through for loop. In this, we have created a small function out of which a string will be returned when the function is called. The return type of the function is char because we are returning a string.
The statement written under the for loop in the main function has to be executed 10 times. So every time the printf statement is executed the same time myFun function will be called. And each time myFun will return a string. So now you must understand how the function is called by for loop and how the value returns.
full width
In the above program, we saw how the function is called by loop. And the above program was a bit too simple. But in this program we will print a table, and this program of the table will follow the program exactly above and return an integer value.
In the PrintTable function, we have declared two variables, of which 2 is assigned to variable a, which means that a table of 2 will be printed when the function is called. And multiply assigned A and n in variable b. And after that we have returned the value of b.
Write a program to call function through for loop in C
Print a table by call a function through for loop
In the PrintTable function, we have declared two variables, of which 2 is assigned to variable a, which means that a table of 2 will be printed when the function is called. And multiply assigned A and n in variable b. And after that we have returned the value of b.
Also Read :
Program to print Fibonacci series by call a function through loop
This program is very important as well as simple, Fibonacci series is a series in which the sum of the last two numbers is the next number. To print the Fibonacci series we have created a function, in which some condition is kept, and this function is called again by this function. Now you will understand that we have used Recursion Technic to solve this problem. Below you will see a program. In which the function is called by loop.This program has a function called FibSeries, which returns elements of the Fibonacci series. This function has been called 10 times by loop. This means that only 10 elements will be printed before the Fibonacci series. You can also change its value.
Conclusion: In this post we saw how we can call a function with the help of for loop. If you have any program related to C language which you are not coming, you comment it, your problem will definitely be solved.and don’t forgot to share this post with friends.
TAGS :
program to call function through loop
Write a program to call function through for loop in C,
call a function using for loop
0 Comments
Hey , Comment Your Query or Suggestion