Skip to content

Instantly share code, notes, and snippets.

@nazmul629
Last active March 8, 2019 13:33
Show Gist options
  • Save nazmul629/e619afc59f94de3861fed36886a583bb to your computer and use it in GitHub Desktop.
Save nazmul629/e619afc59f94de3861fed36886a583bb to your computer and use it in GitHub Desktop.
Introduction of C programming Functions
  • Problem 1
Simple Function Use to do Summation and Subtraction.
#include<stdio.h>
 int main()
 {
     int num1,num2;
     printf("Enter Two Number : ");
     scanf("%d %d",&num1,&num2);
     sum(num1,num2);

 }

 void sum(int num1,int num2)
 
     printf("Summation = %d \n",num1+num2);
     printf("Subtraction = : %d " ,num2-num1);
 }

  • Problem 2
Simple Function Use to do Square.
#include<stdio.h>

int main()
{
    int num;
    printf("Enter any Integer Number: ");
    scanf("%d",&num);

    Square(num);

}

void Square(int num)
{
    printf("Square = %d",num*num);
}

  • Problem 3
Creat a Function This function willl be do Triangle area
#include<stdio.h>


double Trianglearea(double b, double h);
int main()
{
    double base,hight;
    printf("Enter Base :");
    scanf("%lf",&base);
    printf("Enter Hight : ");
    scanf("%lf",&hight);

   double area =Trianglearea(base,hight);

    printf("Area = %.2lf \n", area);
}

double Trianglearea(double b, double h)
{
   return  .5*h*b;
}

  • Problem 4
Write a program that will be do X to the power Y
#include<stdio.h>

 int main()
 {
    double base,exp,result=1,i;
    printf("Enter Base : ");
    scanf("%lf",&base);

    printf("Enter Exponent : ");
    scanf("%lf",&exp);

   for(i=1;i<=exp;i++)
   {
       result = result*base;
   }

    printf("%.2lf",result);

}

Write a program that will be do X to the power Y Use pow() Function.
#include<stdio.h>

 int main()
 {
    double base,exp,result;
    printf("Enter Base : ");
    scanf("%lf",&base);

    printf("Enter Exponent : ");
    scanf("%lf",&exp);

   result =  pow(base,exp);

    printf("%.2lf",result);
}

  • Problem 5
Creat a Function Program That program will be Find All number of array, and finding Maximum Number And Minimum Number.
#include<stdio.h>

//Creating The Functions
 void display(int x[])
{
    int i;
    for(i=0;i<5;i++)
    {
        printf(" %d ",x[i]);
    }
}
// functions of Maximum ;
int maximum(int x[])
{
    int max = x[0],i;
    for(i=1;i<8;i++)
    {
        if (max < x[i])
            max = x[i];

    }
   return max;

}
//Functions of minimum

int minimum(int x[])
{
    int i,mini = x[0];
    for (i=1;i<8;i++)
    {
        if (mini> x[i])
            mini= x[i];
    }
    return  mini;
}


// main Function
int main()
{
    int num[]={10,20,300,40,50,60,70,-4};
    display(num);  //Call The Display Functions;
    int maximumValu = maximum(num); //Call The maximum Functions;
    printf(" \nMaximum = %d \n",maximumValu);

    int minimumValu = minimum(num);/Call The Mminimum  Functions;
    printf("Minimum Value is %d \n",minimumValu);
}

  • Problem 6
Printing String
#include<stdio.h>

void Display(char s[])
{
    int i = 0;
    while(s[i] != '\0')
    {
        printf("%c",s[i]);
        i++;

    }
} 

 int main()
 {
     char str[]= "Nazmul Islam";
     Display(str);
 }

  • Problem 7
Recursieve Funciton
#include<stdio.h>

int fact(int n)
{
    if(n==1)
        return 1;
    else
        return n*fact(n-1);
}

 int main()
 {
     int num,result;
     printf("Enter a Integer Number : ");
     scanf("%d",&num);

     result = fact(num);
     printf("Factorial of %d  is %d",num, result);
 }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment