FORTRAN (FORmula TRANslation) is a programming language that was first developed in the 1950s for scientific and engineering applications. It is one of the oldest high-level programming languages still in use today. FORTRAN is known for its ability to efficiently handle mathematical operations and manipulation of large arrays of data. It is commonly used in scientific and engineering applications such as numerical weather forecasting, structural analysis, and computational fluid dynamics. FORTRAN is still used today in many scientific and engineering communities and has been standardized by the American National Standards Institute (ANSI) and the International Organization for Standardization (ISO).
write the c++ program of the following out put
*
**
***
****
*****
Write a C program to input three different numbers and check whether the input number is positive, negative or zero.
Answer:
#include <stdio.h>
int main()
{
int num1, num2, num3;
printf("Enter three different numbers: ");
scanf("%d %d %d", &num1, &num2, &num3);
if (num1 > 0)
printf("%d is a positive number\n", num1);
else if (num1 < 0)
printf("%d is a negative number\n", num1);
else
printf("%d is zero\n", num1);
if (num2 > 0)
printf("%d is a positive number\n", num2);
else if (num2 < 0)
printf("%d is a negative number\n", num2);
else
printf("%d is zero\n", num2);
if (num3 > 0)
printf("%d is a positive number\n", num3);
else if (num3 < 0)
printf("%d is a negative number\n", num3);
else
printf("%d is zero\n", num3);
return 0;
}
Explanation:
#include <stdio.h>
#define check(x) (((x > 0) ? "Positive" : ((x < 0) ? "Negative" : "Zero")))
int main(int argc, char* argv[]) {
//Variables and get user input.
int a,b,c; scanf("%d %d %d", &a, &b, &c);
//Print the result.
printf("%s\n%s\n%s", check(a), check(b), check(c));
return 0;
}
Assume the user responds with a 4 for the first number and a 6 for the second number.
a number. ")
answerA=input("Enter
answerB=input("Enter
a second number. ")
numberA= int(answerA)
numberB= int(answerB)
result = numberA - numberB/2
print ("The result is", result)
What is the output?
I
The result is
Answer:
1.0
Explanation:
Even though both numbers are integers, numberB is divided by 2 using float division which results in a float
6/2 = 3.0 which is a float
When you execute 4 - 3.0, the integer 4 is converted to float.
So it becomes 4.0 - 3.0 = 1.0
not 1
On the other hand if it were numberA - numberB//2 then
the // indicates an integer division 6//2 = 3
So the result becomes 4 - 3 = 1
These are subtle differences