Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I have two problems about C programming Could you give me the answers Thanks a l

ID: 3622820 • Letter: I

Question

I have two problems about C programming
Could you give me the answers
Thanks a lot


Q1
Write a program that
i. Counts the number of keys pressed until the user presses the ‘.’ key
ii. Keeps a separate count of the number of keys pressed (ie 1,2,3,4,5,6,7,8,9,0)
iii. When the ‘.’ key is pressed the program displays the total key-press count on
the screen together with the percentage of number keys pressed.

Q2
Given polar co-ordinates in the form of r (the distance from the origin) and ? (Theta)
the corresponding Cartesian values for X and Y can be determined using the following
equations
x ?= r cos(? ) , y =? r sin(? )
You are required to write a program that prompts the user to enter the values for r &
Theta. These values should then be passed to a single function which returns values for
x and y via the argument list. The calculated values of x & y are to be displayed in
main().

Thanks again !

Explanation / Answer

// Question 1 answer

 

#include<stdio.h>
#include<conio.h>
#include<math.h>
int main()
{
static int k,p;
float w;
char c;
int loop=0;
while(!loop)
{
if(kbhit())
{
c = getch();
printf("%c",c);
if(c==46) loop=1;
k++;
if(c>=48 && c<=57) p++;
}
}
printf(" no of keys u pressed %d",k);
w = (float)p/k;
printf(" percentage of numbers u pressed %f %",w*100);
getch();
return 0;
}

 

// Question 2 answer

 

#include<stdio.h>
#include<conio.h>
#include<math.h>
void cart(int,int,double *,double *);
int main()
{
int r,t;
double x,y;
printf("enter values of r and theta (in degrees) :");
scanf("%d %d",&r, &t);
cart(r,t,&x,&y);
printf("cartesian coordiantes are x = %lf y = %lf", x,y);
getch();
return 0;
}
void cart(int r, int t,double *x,double *y)
{
*x = r*cos(t*3.141529/180);
*y =r*sin(t*3.141529/180);
}