Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
27
Task/Call-an-object-method/C/call-an-object-method.c
Normal file
27
Task/Call-an-object-method/C/call-an-object-method.c
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
#include<stdlib.h>
|
||||
#include<stdio.h>
|
||||
|
||||
typedef struct{
|
||||
int x;
|
||||
int (*funcPtr)(int);
|
||||
}functionPair;
|
||||
|
||||
int factorial(int num){
|
||||
if(num==0||num==1)
|
||||
return 1;
|
||||
else
|
||||
return num*factorial(num-1);
|
||||
}
|
||||
|
||||
int main(int argc,char** argv)
|
||||
{
|
||||
functionPair response;
|
||||
|
||||
if(argc!=2)
|
||||
return printf("Usage : %s <non negative integer>",argv[0]);
|
||||
else{
|
||||
response = (functionPair){.x = atoi(argv[1]),.funcPtr=&factorial};
|
||||
printf("\nFactorial of %d is %d\n",response.x,response.funcPtr(response.x));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue