Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <math.h>
- int main()
- {
- char selection;
- //declaration for programs:
- //prog1:
- char printing[100];
- //prog2:
- float p1_a,p1_b,area;
- //prog3:
- float value1,value2,meanvalue;
- //prog4:
- float p4_a,p4_b,identity1,identity2;
- //prog5:
- float p5_a,p5_b,p5_c,angle;
- //prog6:
- float x,value;
- printf("This is full exercise 3. Choose which example you want to go to.\nTo terminate program type; q\n");
- printf("-------------------------------\n");
- printf("a) 1. Implement a program which prints on the screen the text inputted by a user with a keyboard.\n");
- printf("b) 1. Implement a program which prints on the screen the text inputted by a user with a keyboard.\n");
- printf("c) 3. Write a program which calculates an arithmetic mean of two any values.\n");
- printf("d) 4. Write a program which checks the following identity: (a+b)(a-b) = a2-b2\n");
- printf("e) 5. Having two legs of a rectangular triangle calculate its hypotenuse and angles in degrees\n");
- 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");
- printf("-------------------------------\n");
- do
- {
- printf("Choose your destiny: ");
- selection=getchar();
- if((selection=='q')||(selection=='Q'))
- {
- printf("Terminating program.\n");
- return 0;
- }
- switch(selection)
- {
- case 'a':
- printf("Executing program %c.\n", selection);
- goto program1;
- break;
- case 'b':
- goto program2;
- break;
- case 'c':
- goto program3;
- break;
- case 'd':
- goto program4;
- break;
- case 'e':
- goto program5;
- case 'f':
- goto program6;
- break;
- default:
- printf("%c is a wrong selection. Try again\n", selection);
- }
- }
- while ((selection!='q') || (selection!='Q'));
- return 0;
- /////////programs:
- program1:
- system("cls");
- printf("Exercise: 1. Implement a program which prints on the screen the text inputted by a user with a keyboard.\n");
- printf("Write something then:\n");
- fflush(stdin);
- gets(printing);
- printf("You have written: %s", printing);
- program2:
- system("cls");
- 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");
- printf("\nEnter value of first side of a figure: ");
- scanf("%f", &p1_a);
- printf("\nEnter value of second side of a figure: ");
- scanf("%f",&p1_b);
- area=p1_a*p1_b;
- printf("\nTotal area of your figure with sides: %fx%f is: %f",p1_a,p1_b,area);
- return 0;
- program3:
- system("cls");
- printf("Exercise: 3. Write a program which calculates an arithmetic mean of two any values.\n");
- printf("\nEnter value of x1; ");
- scanf("%f",&value1);
- printf("\nEnter value of x2; ");
- scanf("%f",&value2);
- meanvalue=(value1+value2)/2;
- printf("\nMean value of %f and %f is; %f",value1,value2,meanvalue);
- return 0;
- program4:
- system("cls");
- printf("Exercise: 4. Write a program which checks the following identity: (a+b)(a-b) = a2-b2\n");
- printf("\nEnter any value of a; ");
- scanf("%f",&p4_a);
- printf("\nEnter any value of b; ");
- scanf("%f",&p4_b);
- identity1=(p4_a+p4_b)*(p4_a-p4_b);
- identity2=p4_a*p4_a-p4_b*p4_b;
- if(identity1==identity2)
- {
- printf("\nFor left side; %f and right side; %f the identity is true", identity1,identity2);
- }
- else
- {
- printf("\nFor left side; %f and right side; %f the identity is false.\n",identity1,identity2);
- }
- return 0;
- program5:
- system("cls");
- printf("Exercise: 5. Having two legs of a rectangular triangle calculate its hypotenuse and angles in degrees\n");
- printf("\nEnter value of the first leg\n");
- scanf("%f", &p5_a);
- printf("\nEnter value of the second leg\n");
- scanf("%f", &p5_b);
- p5_c=sqrt(p5_a*p5_a+p5_b*p5_b);
- angle=acos(p5_b/p5_c)*180;
- printf("Value of a hypotenuse is %.2f and angle between legs is %.2f", p5_c,angle);
- return 0;
- program6:
- system("cls");
- 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");
- printf("\nEnter value for your x: ");
- scanf("%f",&x);
- if((x>='-5')||(x<='5'))
- {
- value=2*x*x+3*x*x-1;
- printf("For x; %f value of your function is: %f\n",x,value);
- }
- if((x<'-5')&&(x>5))
- {
- value=(x+5)*(x+5)-10;
- printf("For x; %f value of your function is: %f\n",x,value);
- }
- return 0;
- system("PAUSE");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement