This looks suspiciously like homework to me, so I'll give you a few pointers:
The formula for the circumference of a circle is 2{pi}r, and the area is {pi}r2.
As you'll be using floating point and mathematical functions, you'll need to link with the math library (eg cc -lm -o circles circles.c)
I don't think there's a built in pi (having done very little programming in c with trignometric functions I can't be sure), so I use:
double pi = acos(-1.0);
as cos({pi}) = -1.
Your main loop will entail printing a suitable message, getting the input, checking an exit condition, converting the input to a double and then passing that to a function to calculate and print the circumference and areas. The function itself could do extra checking, eg for zero or negative radius and return an error code.
Don't forget to include the necessary header files.
How do you write a algorithm for finding maximum of 2 numbers in c?
You can use the ternary operator, in an expression such as:
result = a > b ? a : b;
This is equivalent to:
if (a > b)
result = a;
else
result = b;
What is the Program to find sum of first 10 natural numbers in c?
/* Obvious method: */
#include <stdio.h>
int main(int argc, char *argv[]){
int n, tally = 0;
for(n = 1; n <= 10; n++){
tally += n;
}
printf("the total is %i.\n", tally);
return 0;
}
/* Better method: */
#include <stdio.h>
int main(int argc, char *argv[]){
int numyears = 10;
printf("the total is %i.\n", numyears * (numyears + 1) >> 1);
return 0;
}
Name any uses for dot product or cross product in video games?
The cross product is used to find surface normals of triangles (the building blocks of objects in 3D games). Those surface normals can then be used in dot product tests with the camera to test if the normal is facing the camera or not. If the dot product angle is positive then the normal is facing the same direction as the camera, so the triangle does not need to be drawn (because it cannot be seen). If the angle is negative, then the two vectors are pointing at each other and the triangle may need to be rendered. These methods not only apply to camera viewing, but also to lighting and physics calculations as well.
What is c code to check a number is real or not?
#include
double complex complex_value;
if (cimag (complex_value)==0.0)) puts ("Real");
What is the answer to Convert the binary number 11000101 to its equivalent decimal number?
11000101 = 197
/*
I'm using four spaces instead of tab because I'm writing this on an iPhone.
*/
#include
#include
int main() {
int num1, num2, num3, num4, sum;
printf("Please enter first number: ");
scanf("%d", num1);
printf("Please enter second number: ");
scanf("%d", num2);
printf("Please enter third number: ");
scanf("%d", num3);
printf("Please enter fourth number: ");
scanf("%d", num4);
sum = pow(num1, 2) + pow(num2, 2) + pow(num3, 2) + pow(num4, 2);
printf("The answer is %d", sum);
return 0;
}
How do you print the distance between 2 points in c language?
void PrintDist (double d)
{
printf ("the distance is %g", d);
}
Why does array index begins with 0 not with 1?
It is because array name implies its address and if you want to access first element of it pointer address logic is as below:
Arrays first element address = array base address + 0
Arrays second element address = array base address + 1
How do you convert a number value to hexadecimal?
Hint, read your text book. It is not that hard to do.
How do you write the program to find absolute value using if else in c language?
I'll help you with some pseudo-code (NOT ACTUAL CODE, DO NOT TRY TO COMPILE):
int absvalue(int x)
if x is below 0
return x * -1
else
return x
Also, I suggest you do your homework yourself.
if(x 9)
{
}
Write a program in C to find the complex number of a given number?
There is no such thing; you seem to have misunderstood something.
Any real number can be regarded as a complex number with zero imaginary part, eg.: 5 = 5+0i
Problem Statement for LCM:
Enter Two digits by a user and get its LCM
Answer:
#include
#include
void main()
{
int x,y,i,j;
clrscr();
printf("Enter Two Digits");
scanf("d",&x,&y);
for(i=1;i<=x;i++)
{
for(j=1;j<=y;j++)
{
if(y*i==x*j)
{
printf("LCM is %d\n",y*i);
i=i+x;
}
}
}
getch();
}
OR
there will be another easy way to solve it...
Answer:
#include
#include
void main()
{
int x,y,i,;
clrscr();
printf("Enter Two Digits = ");
scanf("d",&x,&y);
for(i=1;i<=x*y;i++) {
if(i%x==0&&i%y==0)
{
printf(LCM is %d",i);
break;
}
}
getch();
}
How can you create your own variable named while and make it hold a function value?
You cannot create a variable named "while", since that is a reserved word.
Why people are using Hexadecimal rather than binary numbers while doing programs?
hexadecimal can express 16 bit binary in 4 place form, not 16.
Write a program to number the lines in a file?
You can number the lines in a file using a simple Python program. Here's an example:
with open('input.txt', 'r') as infile, open('output.txt', 'w') as outfile:
for line_number, line in enumerate(infile, start=1):
outfile.write(f"{line_number}: {line}")
This code reads from input.txt, numbers each line, and writes the numbered lines to output.txt. The enumerate function is used to keep track of the line numbers, starting from 1.
How do you write a program in C to check whether a number is a palindrome or not?
The simplest method is to reverse the digits of the original number and check to see if the reversed number is equal to the original. This is not an efficient way of doing it but, for ints or long ints, it works well enough.
void main()
{
// get the number to check
long int n;
printf("ENTER A NUMBER: ");
scanf("%ld",&n);
long int n1,mod;
// make a copy of the original number in n1
n1=n;
// store the reversal in rev
long int rev=0;
while(n>0)
{
// grab the rightmost digit of n
mod = n%10;
// shift all digits of rev left, then add in the new digit
rev = rev * 10 + mod;
// shift all digits of n to the right (removing the rightmost one)
n = n / 10;
}
// after the loop, rev will have the opposite digit ordering of n1;
// if these two values are equal, then we have a palindrome
if (n1 == rev)
printf("%ld is a palindrome\n",n1);
else
printf("%ld is not a palindrome\n",n1);
}
Alternate method:
Split the number into its digits, as on the example below: Number: 3592 1st digit: 3592%10 = 2 3592/10=359. ... 2nd digit: 359%10 = 9 etc. Store these into an integer array, then check if all digits correspond to digits at the reflected position.
Is it any valid printable ascii character can be used inan identifier?
In programming languages, identifiers are used to name variables, functions, etc. In most languages, identifiers must start with a letter (uppercase or lowercase) or an underscore, followed by letters, digits, or underscores. Therefore, not all printable ASCII characters can be used in an identifier. Symbols such as @, #, $, and % are typically not allowed in identifiers.