Category: Programming Examples in C
This program in C will accept 2 numbers and perform addition of two numbers using call by reference method. The below program accepts 2 numbers from the user and stores the value in num1 and num2. The program then makes a call to add function. We are passing address/reference of num1 and num2 as function parameters and hence the name, call by reference (also known as – pass by reference) #include <stdio.h> #include <stdlib.h> int main(){ int num1, num2, result; /*Accept the numbers from the user*/ printf(“\nEnter the two number: “); scanf(“%d %d”, &num1, &num2); /* Pass the value of...
In this section you will find some useful C Programs. These programs have been written and tested in Turbo C. In case of any queries, do post a comment. Program to add two numbers using function (Pass by value method) Program to add two numbers using call by Reference Progarm to calculate Factorial of a given number Program to generate Fibonacci series Arithmetic calculator using switch statement Addition of Array elements Search first occurrence of element in an array Sort array in ascending order Sort array in descending order Reverse a given Number Calculate Length of a String (without using...
The below program in C accepts 2 integer numbers and calculates the sum of those 2 numbers using add function. add function accepts two integer parameters namely nos1 and nos2. This function then calculates the sum and return the result to the calling main function. Once the result is received, main function prints the addition of those two numbers #include <stdio.h> #include <stdlib.h> int main(){ int num1, num2, result; /*Accept the numbers from the user*/ printf(“\nEnter the two number: “); scanf(“%d %d”, &num1, &num2); /* Pass the value of num1 and num2 as parameter to function add. The value returned...
An array in C is a collective name given to a group of similar variables. C arrays can be 1-Dimensional, 2-Dimensional, 3-Dimensional and so on. In this topic, we will discuss 1-Dimensional (1D) arrays in C. So lets start with 1D array in C. Let us understand C arrays with the help of an example. void main(){ int arr[3],i; printf(“Enter 3 values\n”); for(i=0;i<3;i++) { scanf(“%d”,&arr[i]) } printf(“The entered values are:\n”); for(i=0;i<10;i++) { printf(“%d\t”,arr[i]) } } Explanation: int arr[3] statement declares an array capable of holding 3 integer values. The first value can be accessed using arr[0]. Similarly second value can...