|
Response Details:
please rate - thanks
1 version
#include <stdio.h>
#include<conio.h>
int main()
{double d,m,v,v2,p1,p2;
int num;
printf("Do you want to find density or pressure?\n");
printf("1 to find density\n2 find pressure\n3 exit");
scanf("%d",&num);
switch(num)
{case 1:printf("Enter the value for m: ");
scanf("%lf",&m);
printf("Enter the value for v: ");
scanf("%lf",&v);
printf("The density is %lf\n", m/v);
break;
case 2:printf("Enter the value for p1: ");
scanf("%lf",&p1);
printf("Enter the value for v1: ");
scanf("%lf",&v);
printf("Enter the value for v2: ");
scanf("%lf",&v2);
printf("The pressure is %lf\n", (p1*v)/v2);
break;
case 3: return 0;
default: printf("Invalid Input-program aborted\n");
}
getch();
return 0;
}
2nd version-keeps looping
#include <stdio.h>
#include<conio.h>
int main()
{double d,m,v,v2,p1,p2;
int num;
printf("Do you want to find density or pressure?\n");
printf("1 to find density\n2 find pressure\n3 exit\n");
scanf("%d",&num);
while(num!=3)
{
switch(num)
{case 1:printf("\nEnter the value for m: ");
scanf("%lf",&m);
printf("Enter the value for v: ");
scanf("%lf",&v);
printf("The density is %lf\n", m/v);
break;
case 2:printf("\nEnter the value for p1: ");
scanf("%lf",&p1);
printf("Enter the value for v1: ");
scanf("%lf",&v);
printf("Enter the value for v2: ");
scanf("%lf",&v2);
printf("The pressure is %lf\n", (p1*v)/v2);
break;
default: printf("Invalid Input-program aborted\n");
}
printf("\nDo you want to find density or pressure?\n");
printf("1 to find density\n2 find pressure\n3 exit\n");
scanf("%d",&num);
}
return 0;
}
|