0% found this document useful (0 votes)
40 views12 pages

Function Declaration

The document contains C code examples demonstrating the use of functions with different parameter passing mechanisms - without arguments and without return value, with arguments and no return value, without arguments and with return value, with arguments and with return value. It also contains examples of function prototypes, passing arguments by reference to swap values, using arrays and pointers within functions to manipulate data, and a function to transpose a 2D array.

Uploaded by

Girija
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
Download as docx, pdf, or txt
0% found this document useful (0 votes)
40 views12 pages

Function Declaration

The document contains C code examples demonstrating the use of functions with different parameter passing mechanisms - without arguments and without return value, with arguments and no return value, without arguments and with return value, with arguments and with return value. It also contains examples of function prototypes, passing arguments by reference to swap values, using arrays and pointers within functions to manipulate data, and a function to transpose a 2D array.

Uploaded by

Girija
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1/ 12

#include <stdio.

h>
void sum (void); // function declaration
int main()
{
prinf(“hi calling the sum function\n”);
sum();
printf(“end of calling”);
return 0;
}
void sum (void)
{ int a,b,c; //local variables
printf(“enter the values of a and b\n”):
scanf(“%d %d”,&a,&b);
c= a+b;
printf(“sum =%d”, c);
}
// With arguments and no return values
#include <stdio.h>
void sum (int, int ); // function declaration
int main()
{
int n1,n2, res;
prinf(“hi calling the sum function\n”);
printf(“enter the value\n”);
scanf(“%d %d”, &n1,&n2); 5 10
sum(n1,n2); sum(5,10) n1=5 n2 =10
printf(“end of calling”);
return 0;
}
void sum (int a, int b) a=5 b=10
{
int c =a+b;
printf(result =%d”,c);
}
// Without arguments and with return value
#include <stdio.h>
int sum (void ); // function declaration
int main()
{
int res;
prinf(“hi calling the sum function\n”);
res= sum();
res1 = sum();
printf(“sum= %d”,res);
printf(“end of calling”);
return 0;
}

int sum (void)


{
Int a,b,c;
printf(“enter the value\n”);
scanf(“%d %d”, &a,&b);
c =a+b;
return c;
}
// With arguments and with return value
#include <stdio.h>
int sum (int a, int b ); // function declaration
int main()
{
int res, a,b;
prinf(“hi calling the sum function\n”);
printf(“Enter the values\n”);
scanf(“%d%d”, &a,&b);
res= sum(a,b);
printf(“sum= %d”,res);
printf(“end of calling”);
return 0;
}

int sum (int a, int b)


{
return (a+b);
}
#include<stdio.h>
// function prototype, also called function declaration
void swap(int *a, int *b);
 
int main()
{
    int m = 22, n = 44; 2010, 2020 m=44 n=22
    //  calling swap function by reference
    printf("values before swap m = %d \n and n = %d",m,n); 22 44
    swap(&m, &n);   swap(2010, 2020);
printf("values After swap m = %d \n and n = %d",m,n); 44 22
}
 void swap(int *a, int *b) a=2010 , b=2020
{
    int tmp;
    tmp = *a; tmp = 22
    *a = *b;
    *b = tmp;
    printf("\n values after swap a = %d \nand b = %d", *a, *b); 44 22
}
//To find the area of triangle and circle
#include <stdio.h>
#define pi 3.14; //Pre-processor directives or macro directives, symbolic cons
void area (void); // function declaration
int main()
{
printf(“hi calling the sum function\n”);
area();
printf(“end of calling”);
return 0;
}
void area (void)
{ int b,h,r;
float a1,a2; //local variables
printf(“enter the values \n”);
scanf(“%d %d %d”,&b,&h,&r);
a1= 0.5*b*h;
a2 = pi *r *r;
printf(“area of triangle =%d\t area of circle =%d”, a1,a2);
}

Respected Sir
I take this opportunity to thank the management and the principal for
motivating the faculties to handle the online classes which prompted me to
explore the avenues to do the online classes. I have been taking the online
classes for the II semester- Programming for Problem solving (18CS23) and IV
semester – Verilog HDL(18EC44). The constant interest shown by the students
is the additional encouraging factor for the smooth conduction of the classes.
The platform used by me is Zoom application along with, using the softwares –
Vivado-2018 for executing the Verilog programs, DOS Box for running the C-
program and PPT’s for the contents. Since the free software is used for the
classes will be for 40minutes later the connection needs to be established
using another ID that is small glitch to be encountered every day. The number
of students joining the class is nearly 85%, they are interactive in the class and
some shy students clarify their queries in what’s up. The materials shared with
the students are ppt and the recording of the sessions. Online teaching is the
best considering the present situation but however this practice will not give
complete satisfaction to the students as well as for the tutor. In the near future
would like to explore more platform to evaluate the performance of the
student.
I
int x=100; x
int *ptr ; 2020
200
ptr =&x; (ptr =2020)
*ptr =200; ptr
2020
2050
Printf(“%d”, x);
X= x+10; * -dererefernce (value at that address

float x= 20.33;
float *fp;
fp = &x;
*fp =*fp +20.22
20.33 +20.22 =40.55
int a[3]; a[0] -2020
a[1] -2022
a[2] -2024

float a[3];
ptr =&a;
ptr++; a[0] -2020
a[1] -2024
a[2] -2028
by default pointer is created who is name same as the array
name and initialized to first location
float *fp =&f[0]; //Base address

#include<stdio.h>
void display(int a[], int n);
void bubble_sort(int a[], int n);
int main()
{
int a[100], n,i;
printf(“enter the size of the array\n”);
scanf(“%d”,&n);
printf(“enter the array elements\n”);
for(i=0; i<n; i++)
scanf(“%d”,&a[i]);
printf(“Array before sorting\n”);
display(a,n);
bubble_sort(a,n);
printf(“Array after sorting\n”);
display( a, n);
return 0;
}
void display(int x[], int m)
{ int i;
for(i=0; i<m; i++)
printf(“%d\t”, x[i]);
}

void bubble_sort(int a[], int m)


{ int i,j,t;
for(i=0; i<m-1; i++)
{
for(j=0; j<m-i-1; j++)
{
if (a[j]>a[j+1])
{
t= a[j];
a[j] =a[j+1];
a[j+1] =t;
}
}
}
}
#include<stdio.h>
void display(int a[3][3]);
void transpose(int a[3][3]);
int i, j, t[3][3]; // Global variable
int main()
{
int a[3][3];
printf(“enter the array elements\n”);
for(i=0; i<3; i++)
for(j=0; j<3; j++)
scanf(“%d”,&a[i][j]);
printf(“Array before transpose\n”);
display(a);
transpose(a);
printf(“Array after transpose\n”);
display( t);
return 0;
}
void transpose(int x[3][3])
{ for(i=0; i<3; i++)
for(j=0; j<3; j++)
t[i][j] = x[j][i];
}
void display (int x[3][3])
{
for(i=0; i<3; i++)
for(j=0; j<3; j++)
printf(“%d\t”, x[i][j]);
}

You might also like