Advertisement
Guest User

Untitled

a guest
Jun 29th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 4.79 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <math.h>
  4.  
  5. int main()
  6. {
  7.  
  8.     char selection;
  9.  
  10.     //declaration for programs:
  11.     //prog1:
  12.     char printing[100];
  13.     //prog2:
  14.     float p1_a,p1_b,area;
  15.     //prog3:
  16.     float value1,value2,meanvalue;
  17.     //prog4:
  18.     float p4_a,p4_b,identity1,identity2;
  19.     //prog5:
  20.     float p5_a,p5_b,p5_c,angle;
  21.     //prog6:
  22.     float x,value;
  23.  
  24.  
  25.     printf("This is full exercise 3. Choose which example you want to go to.\nTo terminate program type; q\n");
  26.     printf("-------------------------------\n");
  27.     printf("a) 1.   Implement a program which prints on the screen the text inputted by a user with a keyboard.\n");
  28.     printf("b) 1.   Implement a program which prints on the screen the text inputted by a user with a keyboard.\n");
  29.     printf("c) 3.   Write a program which calculates an arithmetic mean of two any values.\n");
  30.     printf("d) 4.   Write a program which checks the following identity:  (a+b)(a-b) = a2-b2\n");
  31.     printf("e) 5.   Having two legs of a rectangular triangle calculate its hypotenuse and angles in degrees\n");
  32.     printf("f) 6.   Write a program which calculates values of the following function: f(x)=2x^2+3x-1 for xe<-5,5> & f(x)=(x+5)^2-10 for x<-5 v x>5\n");
  33.     printf("-------------------------------\n");
  34.     do
  35.     {
  36.         printf("Choose your destiny: ");
  37.         selection=getchar();
  38.         if((selection=='q')||(selection=='Q'))
  39.         {
  40.             printf("Terminating program.\n");
  41.             return 0;
  42.         }
  43.         switch(selection)
  44.         {
  45.         case 'a':
  46.             printf("Executing program %c.\n", selection);
  47.             goto program1;
  48.             break;
  49.         case 'b':
  50.             goto program2;
  51.             break;
  52.         case 'c':
  53.             goto program3;
  54.             break;
  55.         case 'd':
  56.             goto program4;
  57.             break;
  58.         case 'e':
  59.             goto program5;
  60.         case 'f':
  61.             goto program6;
  62.             break;
  63.         default:
  64.             printf("%c is a wrong selection. Try again\n", selection);
  65.  
  66.         }
  67.  
  68.     }
  69.     while ((selection!='q') || (selection!='Q'));
  70.     return 0;
  71.  
  72. /////////programs:
  73.  
  74. program1:
  75.     system("cls");
  76.     printf("Exercise: 1.    Implement a program which prints on the screen the text inputted by a user with a keyboard.\n");
  77.     printf("Write something then:\n");
  78.     fflush(stdin);
  79.     gets(printing);
  80.     printf("You have written: %s", printing);
  81.  
  82. program2:
  83.     system("cls");
  84.     printf("Exercise: 2.    Write a program which calculates the area of  one figure. Parameters of the figure are inputted by the user with a keyboard.\n");
  85.     printf("\nEnter value of first side of a figure: ");
  86.     scanf("%f", &p1_a);
  87.     printf("\nEnter value of second side of a figure: ");
  88.     scanf("%f",&p1_b);
  89.     area=p1_a*p1_b;
  90.     printf("\nTotal area of your figure with sides: %fx%f is: %f",p1_a,p1_b,area);
  91.     return 0;
  92.  
  93. program3:
  94.     system("cls");
  95.     printf("Exercise: 3.    Write a program which calculates an arithmetic mean of two any values.\n");
  96.     printf("\nEnter value of x1; ");
  97.     scanf("%f",&value1);
  98.     printf("\nEnter value of x2; ");
  99.     scanf("%f",&value2);
  100.     meanvalue=(value1+value2)/2;
  101.     printf("\nMean value of %f and %f is; %f",value1,value2,meanvalue);
  102.     return 0;
  103.  
  104. program4:
  105.     system("cls");
  106.     printf("Exercise: 4.    Write a program which checks the following identity:  (a+b)(a-b) = a2-b2\n");
  107.     printf("\nEnter any value of a; ");
  108.     scanf("%f",&p4_a);
  109.     printf("\nEnter any value of b; ");
  110.     scanf("%f",&p4_b);
  111.     identity1=(p4_a+p4_b)*(p4_a-p4_b);
  112.     identity2=p4_a*p4_a-p4_b*p4_b;
  113.     if(identity1==identity2)
  114.     {
  115.         printf("\nFor left side; %f and right side; %f the identity is true", identity1,identity2);
  116.     }
  117.     else
  118.     {
  119.         printf("\nFor left side; %f and right side; %f the identity is false.\n",identity1,identity2);
  120.     }
  121.     return 0;
  122.  
  123. program5:
  124.     system("cls");
  125.     printf("Exercise: 5.    Having two legs of a rectangular triangle calculate its hypotenuse and angles in degrees\n");
  126.     printf("\nEnter value of the first leg\n");
  127.     scanf("%f", &p5_a);
  128.     printf("\nEnter value of the second leg\n");
  129.     scanf("%f", &p5_b);
  130.     p5_c=sqrt(p5_a*p5_a+p5_b*p5_b);
  131.     angle=acos(p5_b/p5_c)*180;
  132.     printf("Value of a hypotenuse is %.2f and angle between legs is %.2f", p5_c,angle);
  133.     return 0;
  134.  
  135. program6:
  136.     system("cls");
  137.     printf("Exercise: 6.    Write a program which calculates values of the following function: f(x)=2x^2+3x-1 for xe<-5,5> & f(x)=(x+5)^2-10 for x<-5 v x>5\n");
  138.     printf("\nEnter value for your x: ");
  139.     scanf("%f",&x);
  140.     if((x>='-5')||(x<='5'))
  141.     {
  142.         value=2*x*x+3*x*x-1;
  143.         printf("For x; %f value of your function is: %f\n",x,value);
  144.     }
  145.     if((x<'-5')&&(x>5))
  146.     {
  147.         value=(x+5)*(x+5)-10;
  148.         printf("For x; %f value of your function is: %f\n",x,value);
  149.     }
  150.     return 0;
  151.  
  152.  
  153.     system("PAUSE");
  154.     return 0;
  155. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement