Category Archives: Function

Problem 85: Product

Create a structure named Product with following two fields-

1. name (string)
2. price (double)

Then create a function named printProductInfo() which takes a parameter of Product type and print the information of that Product. Finally, in main function create a variable of structure Product named myProduct and call the printProductInfo() function passing myProduct as the parameter.
code:

 

Struct Problem 1: 101cproblems

Problem 81: Struct GPA

Create a simple structure named Student that holds the following variables-
i. id (integer)
ii. cgpa (float)
iii. name (string)
Now create an instance of that structure named s1 and scan the values from the user. Finally print the id, cgpa and name which user entered.

code:

Source:http://101cproblems.com/problem-81/

Another approach:

 

Typedef Enum Union Project

code:

 

Using function with Struct user defined type also pointer

code:

why we used *sp in one place and sp in another place ?there s a reason behind this
*sp means address is passing where after the local input takeup it will go but if not use  dereferencing then it will not go outside. So to write we need with address.

and in sp it is read only. so to print sp is enough to show.

vid:

Send Array to Function Using Pointer

code:

 

Return More Than one Value in a Function

In function we can’t retun more than one value with return keyword. In this case we need pointer to return more variables than one in function.

code:

Ouput:

 

 

Value: Absolute in Function

code:

 

USD to BDT function in C

code:

 

Find Max Value From 3 Parameters Using Function

code:

Another Logic by me:

Another Logic that is good:

A very very good logic: (Logic Logic)

 

Function Calculator

code:

With Switch Case:

Another easy code:

 

Function Divisor

code:

Formula: https://www.mathsisfun.com/definitions/divisor.html

This formula link will help you to think about the logic.

Got this problem from 101cproblems.com

Recursion Example

code:

 

Void clear in C

We  see lots of void in C. Lets clear why we all use  this.

it means  it will return int type value but will not take any parameters..it is also good to define in function prototype

it means it will return int type value but will take parameters that is defined:

it means it will return nothing and if we use return here it will show error as void can’t return a value

but we can return from a condition here is one example:

 

but if we use return value with int return type it will return 1 as true returning.
example could be written as:

Source: Took some help:
http://stackoverflow.com/questions/1043034/what-does-void-mean-in-c-c-and-c
http://stackoverflow.com/questions/416345/is-fvoid-deprecated-in-modern-c-and-c

Returning From Array Function in C

As I am learning I didn’t find the solution yet when I was trying to make a reusable code for mydigit extracts code to make it functinal.

So here is the code I tried but it’s not working;

 

Solution can be foound from this link:
http://stackoverflow.com/questions/11656532/returning-an-array-using-c

https://www.tutorialspoint.com/cprogramming/c_return_arrays_from_function.htm

http://stackoverflow.com/questions/14297169/how-to-make-an-array-return-type-from-c-function

http://www-ee.eng.hawaii.edu/~tep/EE160/Book/chap7/section2.1.2.html

Find Is It Armstrong Number or Not

code by me:

Logic and Code From the Vids:

Vid: