Basic Programming Lab
Basic Programming Lab
Basic Programming Lab
— — 0x10
Function Declaration
Syntax:
return_data_type function_name (parameters)
{
//code
}
#include <stdio.h>
void Greet();
int main()
{
Greet();
return 0;
}
void Greet()
{
printf("\nHello World");
}
Function Types
1 - Library Functions
- printf
- scanf
- sqrt
- main
Category of Function
#include <stdio.h>
void Sum_Of_Two_Nos_1(void);
int main()
{
Sum_Of_Two_Nos_1();
return 0;
}
void Sum_Of_Two_Nos_1()
{
int Number_1, Number_2, Result;
printf("\nEnter First Number: ");
scanf("%d", &Number_1);
printf("\nEnter Second Number: ");
scanf("%d", &Number_2);
Result = Number_1 + Number_2;
printf("\nFirst Number + Second Number = %d\n",Result);
}
2- With arguments but no return value
#include <stdio.h>
int main()
{
int Number_1, Number_2;
printf("\nEnter First Number: ");
scanf("%d", &Number_1);
printf("\nEnter Second Number: ");
scanf("%d", &Number_2);
Sum_Of_Two_Nos_2(Number_1, Number_2);
return 0;
}
int Sum_Of_Two_Nos_3();
int main()
{
int Result;
Result = Sum_Of_Two_Nos_3();
printf("\nFirst Number + Second Number = %d\n",Result);
return 0;
}
int Sum_Of_Two_Nos_3()
{
int Number_1, Number_2;
printf("\nEnter First Number: ");
scanf("%d", &Number_1);
printf("\nEnter Second Number: ");
scanf("%d", &Number_2);
return Number_1 + Number_2;
}
4- With arguments and return value
#include <stdio.h>
int main()
{
int Number_1, Number_2;
int Result;
printf("\nEnter First Number: ");
scanf("%d", &Number_1);
printf("\nEnter Second Number: ");
scanf("%d", &Number_2);
Result = Sum_Of_Two_Nos_4(Number_1, Number_2);
printf("\nFirst Number + Second Number = %d\n",Result);
return 0;
}
#include<stdio.h>
int Sum_of_Natural_Numbers(int Number);
int main()
{
int Number, Result;
Result = Sum_of_Natural_Numbers(Number);
/*
--------------------------------------------------
|Author : Your_Name |
|Roll No: Your_Roll_No |
|Department: Your_Department |
--------------------------------------------------
*/