0% found this document useful (0 votes)
29 views1 page

Do It Now

Print Pyramids and Patterns Make a Simple Calculator Using switch...case Display Factors of a Number Display Armstrong Number Between Two Intervals Check Armstrong Number Display Prime Numbers Between Two Intervals Check Whether a Number is Prime or Not Check Whether a Number is Palindrome or Not Calculate the Power of a Number Reverse a Number Join our newsletter for the latest updates. Enter Email Address* Join C Program to Display Factors of a

Uploaded by

M Naveed Abbasi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views1 page

Do It Now

Print Pyramids and Patterns Make a Simple Calculator Using switch...case Display Factors of a Number Display Armstrong Number Between Two Intervals Check Armstrong Number Display Prime Numbers Between Two Intervals Check Whether a Number is Prime or Not Check Whether a Number is Palindrome or Not Calculate the Power of a Number Reverse a Number Join our newsletter for the latest updates. Enter Email Address* Join C Program to Display Factors of a

Uploaded by

M Naveed Abbasi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

#include <stdio.

h>
int main() {
int num, i;
printf("Enter a positive integer: ");
scanf("%d", &num);
printf("Factors of %d are: ", num);
for (i = 1; i <= num; ++i) {
if (num % i == 0) {
printf("%d ", i);
}
}
return 0;
} multiplication, and division.

The Calculator class contains 2 private variables of type double � A and B. A and B
store the numbers on which we are required to perform the operation.

The Calculator class contains 5 public member functions.

set(): This function is used to input 2 numbers. The numbers are stored in private
variables A and B.
add(): This function returns A + B.
sub(): This function returns A � B.
mul(): This function returns A * B.
div(): This function returns A / B. It also checks if B is 0 or not.

#include <stdio.h>
int main() {
char op;
double first, second;
printf("Enter an operator (+, -, *, /): ");
scanf("%c", &op);
printf("Enter two operands: ");
scanf("%lf %lf", &first, &second);

switch (op) {
case '+':
printf("%.1lf + %.1lf = %.1lf", first, second, first + second);
break;
case '-':
printf("%.1lf - %.1lf = %.1lf", first, second, first - second);
break;
case '*':
printf("%.1lf * %.1lf = %.1lf", first, second, first * second);
break;
case '/':
printf("%.1lf / %.1lf = %.1lf", first, second, first / second);
break;
// operator doesn't match any case constant
default:
printf("Error! operator is not correct");
}

return 0;
}

You might also like