Author: learnconline

Arithmetic calculator using switch statement 9

Arithmetic calculator using switch statement

#include #include void main() { int choice, no1, no2, result; clrscr(); printf(“\n\n*********************”); printf(“\nArithmetic Calculator”); printf(“\n*********************”); printf(“\n\n1. Addition\n2. Subtraction”); printf(“\n3. Multiplication\n4. Division”); printf(“\n\nEnter your choice: “); scanf(“%d”,&choice); switch(choice){ case 1: printf(“\nEnter the two number:”); scanf(“%d %d”, &no1, &no2); result = no1 + no2; printf(“\nThe Addition of %d and %d is %d”, no1, no2, result); break; case 2: printf(“\nEnter the two number:”); scanf(“%d %d”, &no1, &no2); result = no1 – no2; printf(“\nThe Subtaction of %d and %d is %d”, no1, no2, result); break; case 3: printf(“\nEnter the two number:”); scanf(“%d %d”, &no1, &no2); result = no1 * no2; printf(“\nThe Multiplication of %d...

Program to generate Fibonacci series 3

Program to generate Fibonacci series

#include #include #include void main() { clrscr(); //Declare an initialize the variables int firstNum = 0, secondNum = 1, fibNum, temp; //Accept a number from the user printf(“\nEnter the number: “); scanf(“%d”, &fibNum); /*Exit if value is less than 2*/ if(fibNum

Program to calculate Factorial of a given number 4

Program to calculate Factorial of a given number

#include<stdio.h> #include<stdlib.h> int main() { int num, fact = 1; /*Accept a number from the user*/ printf(“\nEnter the number: “); scanf(“%d”, &num); /*Calculate the factorial*/ for(int i=1; i<=num; i++) { fact = fact * i; } /*Display the result*/ printf(“The factorial of %d is %d”, num, fact); return 0; } Output: Enter the number: 5 The factorial of 5 is 120

Program in C to add numbers using call by reference 8

Program in C to add numbers using call by reference

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...

C Programming Examples 22

C Programming Examples

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...

Program in C to add two numbers using function (Pass by value method) 7

Program in C to add two numbers using function (Pass by value method)

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...

FREE C Cheatsheet - Speed Up Your C Programming.

FREE C Cheatsheet - Speed Up Your C Programming.

Download a 7-page free cheat sheet for easy and quick access to C Concepts, Snippets, and Syntax.

Thank you! Check you inbox and access your cheat-sheet