Write A C Program To Simulate A Simple Calculator Using Switch Statement

Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

Write a C program to simulate a simple calculator using switch statement.

AIM:

To simulate a simple calculator using switch statement.


PROGRAM:

#include<stdio.h>
int main ()
{
int a, b, result;
char op;
printf ("Enter an expression: ");
scanf ("%d%c%d", &a, &op, &b);
switch(op)
{
case '+':
result = a + b;
break;
case '-':
result = a - b;
break;
case '*':
result = a * b;
break;
case '/':
result = a / b;
break;
}
printf ("Result = %d", result);
return 0;
}
Input:
Enter an expression: 35*65
Output:
Result=2275

RESULT: A simple calculator is created and calculated.

11
BONACCI SERIES

Write a C program to Find Fibonacci Series Up to 100.

AIM:

To Find Fibonacci Series Up to 100.

PROGRAM:

#include<stdio.h>
int main ()
{
int n1=0,n2=1,n3,i,number;
printf ("Enter the number of elements:");
scanf("%d",&number);
printf ("\n%d %d",n1,n2);
for(i=2;i<number;++i)
{
n3=n1+n2;
printf (" %d",n3);
n1=n2;
n2=n3;
}
return 0;
}

Input:
Enter the number of terms: 15
Output:
Fibonacci Series: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34,55,89,144,233,377

RESULT: Fibonacci Series Up to 100 has been found.

You might also like