Wednesday, 22 December 2021

function

 // functions are besic tools by using them we will be able to

break our programme in small segments.

// funtion can be called multiple times and can provide our
c programme reusebility & modularity.
// function is also known as subroutine and procedure.
because by using this we break intire routine into small
sub-routine.
// we can avoid logic rewriting through function.
// we can devide wrok among programmer using functions.
// we can easily debug programme by finding the function
with error.
// function with bug will needed to debug and rest won't
need to be change.

// declaration, defining & calling a function.
// A function is declared to tell the compiler about its existence.
// declaration of a function is the process of calling
the compiler about it's existence.
(compiler ko function ke bare me batana)
// A function is defined to get some task done.
(It means when we define function we write
whole code of that function. In this actual implementation
of function is done.)
// (exectly function {code} he kya)
// defining a function is to get some certain task done
// A function is called in order to be used.
// (function ko use hone ke liya bulana)
// calling a function is to use it.
// types of function 1.library function 2.user defined function
// library functions are predefined functions of a programming
language.(basiclly include in header files)
// user defined function also known as created by user function
to reduse the hustle & complexcibility of a c-programme.
// besic function code example
// 1.without argument(condition,input) and return value.
// 2.with argument (condition,input) but without return value.
// 3.without argument (condition,input) but with retuen value.
// 4.with argument (condition,input) and return value.

#include <stdio.h>
int sum(int a, int b); // with argument and return value.
void printstar (int n);//without argument but retuen value.
int takenumber();//with argument but without return value.
void myname()
{
    printf ("my name is hemansh");
}
int main()
{
    int a,b,c,d,n;
    a = 46;
    b = 34;
    c = sum(a,b);

    // d=takenumber();
    // printstar(1);
    // printf ("he sum is %d",c);
    // printf ("The number entered is %d.",d);
    myname();

    return 0;
}

 int sum(int a, int b)
{
    return a+b;
}


 void printstar (int n)
{
    for (int i = 0; i < n; i++)
    {
        printf ("%c",'*');
        // ""ke ander string & ''ke andar character
lete he.
       
    }
}


 int takenumber()
{
    int i;
    printf ("Enter a number: \n");
    scanf ("%d", &i);
    return i;
}

//additional
#include <stdio.h>
void name()
{
    printf ("My name is Hemansh.\n");
   
}
void printhash (int n)
{
    int i;
    for ( i = 0; i < n; i++)
    {
        printf ("%c\n",'#');

    }
   
}
int enternum()
{
    int num;
    printf ("enter a number: \n");
    scanf ("%d",&num);
    return num;
}
int sumnum()
{
    int a;
    int b;
    printf ("Enter the first number: ");
    scanf ("%d", &a);

    printf ("Enter the second number: ");
    scanf ("%d", &b);

    return a+b;
}

int main()
{
    name();
    printhash(4);
    int c;
    c=enternum();
    printf ("The number entered is %d.\n",c);
    int a,b,d;
   
    d = sumnum(a,b);
    printf ("The sum is %d.\n",d);
   
    return 0;
}
output:_
My name is Hemansh. # # # # enter a number: 23 The number entered is 23. Enter the first number: 81 Enter the second number: 256 The sum is 337.


No comments:

Post a Comment

here we are to help you.you can watch videos and get information about :- (1) scientific facts (2) education (3) gaming (4) music (5) lyrics (6) cartoons and many more.So keep watching keep learning, thank you.

Recurtions

  //Why are recursions? //We can solve difficult long iteratively can be solved simply recursively. // there are some problems which suite...