#include<stdio.h>
#include<stdlib.h>
#include<math.h>
void lucky();
float ctof();
float sqr();
long int fact();
int a;
void main() {
int ch;
while (1) {
printf("\nMENU");
printf("\n1.%cC to %cF conversion\n2.Square root of a number");
printf("\n3.10 Lucky numbers between two numbers");
printf("\n4.Factorial of given number");
printf("\n9.Abandon the program",248,248);
printf("\n\nEnter your choice: ");
scanf("%d", &ch);
switch (ch) {
case 1:
printf("Temp in %cF is: %.2f\n", 248, ctof());
break;
case 2:
printf("Square root of the number is: %.2f\n", sqr());
break;
case 3:
lucky();
break;
case 4:
printf("Factorial of %d! is: %ld\n", a, fact());
break;
case 9:
exit(1);
default:
printf("Invalid choice\n");
}
}
}
float ctof() {
float fah;
float cel;
printf("Enter temp in %cC: ", 248);
scanf("%f", &cel);
fah = (9 * cel + 160) / 5;
return (fah);
}
float sqr() {
float sqr, no;
printf("Enter the number: ");
scanf("%f", &no);
sqr = sqrt(no);
return (sqr);
}
long int fact() {
int i;
long int pro = 1;
printf("Enter the number: ");
scanf("%d", &a);
for (i = 0; (a - i) > 0; i++)
pro = pro * (a - i);
return (pro);
}
void lucky() {
int b, c, i;
printf("Enter the two numbers: \n");
scanf("%d%d", &a, &b);
printf("\n10 Lucky numbers between %d and %d are: \n", a, b);
for (i = 0; i < 10;) {
c = rand();
if ((c > a && c < b) || (c > b && c < a)) {
printf("%-5d", c);
i++;
}
}
printf("\n");
}
WHAT'S NEW?
Loading...
0 comments:
Post a Comment