Want this question answered?
read num1 read num2 sum = num1 num2 print highest value
num1 <<= 1; /* shift left */
int main() { int num1; int num2; int result = num1 + num2; return 0; }
'*** PROGRAM: Compare 2 numbers using both min/max functions; ' then, output which number is max/and, which is min. '*** declare variables... min = 0 max = 0 number1 = 342 number2 = 256 '*** main program... CLS '...(CL)ear the Output (S)creen PRINT "Minimum = "; findMin(number1, number2) PRINT "Maximum = "; findMax(number1, number2) END '...END of program/halt program code execution FUNCTION findMax (num1, num2) answer = 0 IF num1 > num2 THEN answer = num1 ELSE answer = num2 findMax = answer END FUNCTION FUNCTION findMin (num1, num2) answer = 0 IF num1 < num2 THEN answer = num1 ELSE answer = num2 findMin = answer END FUNCTION ---program output... Minimum: 256 Maximum: 342
$vi sum.sh echo "enter the 1st no." read num1 echo "enter the 2nd no." read num2 sum= 'expr $num1 + $num2' echo "sum of the numbers is $sum"
read num1 read num2 sum = num1 num2 print highest value
You can do this by creating a forwarddeclaration of the function. You can call the forward drclared function inside the main to use it.int result(float num1, float num2);intmain(void){int value = result(3.14, 2.74);return (0);}intresult(float num1, float num2){int value = 0;// function codes goes here// you can alter the value of variable 'value'return (value);}The returning value of the 'result()' function is assigned to variable 'value' in 'main()'.
#include<stdio.h> main() { long int num1, num2; long int sum=0; printf("Enter Value="); scanf("%ld", &num1); printf("Enter Value="); scanf("%ld", &num2); sum=num1+num2; printf("The Result is=%ld", sum); }
int num1 = 5; int num2 = 5; printf ("%d/%d=%d\n", num1, num2, num1/num2); and if you want to enter during the program then int num1; int num2; printf ("what is the first number?"); scanf ("%d", &num1); printf ("what is the second number?"); scanf ("%d", &num2); printf ("%d/%d=%d\n", num1, num2, num1/num2); i hope this helped
Using a temporary variable: #include<stdio.h> #include<conio.h> void main() { int a,b,temp; clrscr(): printf("Enter the first number a\n"); scanf("%d",&a); printf("Enter the second number b\n"); scanf("%d",&b); printf("Before swapping a=%d b=%d",a,b); temp=a; a=b; b=temp; printf("The swapped values are: a=%d b=%d",a,b); getch(); } Without using a temporary variable: #include<stdio.h> #include<conio.h> void main() { int a,b; clrscr(); printf("Enter the first number a\n"); scanf("%d",&a); printf("Enter the second number b\n"); scanf("%d",&b); printf("Before swapping a=%d b=%d",a,b); a=a+b; b=a-b; a=a-b; printf("The swapped values are: a=%d b=%d\n"); getch(); }
Variables in Qbasic are divided into two groups. There are numerical variables and string variables. This is how you would use a numerical variable: CLS INPUT "Enter your first number"; num1 INPUT "Enter your second number"; num2 num3 = num1 * num2 CLS PRINT "The product of the two numbers is"; num3 END This example just has the user input 2 variables (num1 and num2) and store them as numerical variables. Num3 is defined by multiplying the two user-imputed variables. The text displayed with PRINT contains normal text with a semi colon to display the result. This is a string variable example: CLS INPUT "What is my name?"; name$ PRINT "Hi I'm"; name$ END Instead of inputting just the variable name, you add a dollar sign to signify that it's a string variable. String variables contain letters rather than numbers. For string variables, you simply put the $ after the variable name every time it's used. Other than that, it's much like a numerical variable. That's a basic outline of how the variables work. Manipulating the string variables is a different story.
#include <stdio.h>int main(){ int num1, num2, max; printf("Enter two positive integers: "); scanf("%d %d", &num1, &num2); max=(num1>num2) ? num1 : num2; while(1) { if(max%num1==0 && max%num2==0) { printf("LCM of %d and %d is %d", num1, num2,max); break; } ++max; } return 0;}
#include<stdio.h> main() { int num1; int num2; int a; printf("Enter any two numbers :"); scanf("%d%d",&num1,&num2); for(a=num1;num1<=num2;a++) { if ( a % 2 == 1); { printf("%d",a); } } getch(); }
if num1>num2 return num1 else return num2
num1 <<= 1; /* shift left */
QBASIC operators are listed as follows.../along with some example QBASIC code... ->LOGICAL OPERATORS AND OR NOT EXAMPLE QBASIC CODE:- A=1 B=1 IF (A AND B) THEN PRINT "Result: True" ELSE PRINT "Result: False" ...output... Result: True A=1 B=2 IF (A AND B) THEN PRINT "Result: True" ELSE PRINT "Result: False" ...output... Result: False -> MATHEMATICAL OPERATORS + plus - minus * multiply / divide MOD division remainder ^ raise to the power EXAMPLE QBASIC CODE:- num1=4 num2=2 PRINT num1 + num2 PRINT num1 - num2 PRINT num1 * num2 PRINT num1 / num2 PRINT num1 MOD num2 PRINT num1 ^ num2 ...output... 6 2 8 2 0 16 -> COMPARISON OPERATORS = equals > greater than < lesser than >= greater than/or, equals <= lesser than/or, equals <> not EXAMPLE QBASIC CODE:- num1 = 6 num2 = 8 IF num1 = num2 THEN PRINT "Equal to" IF num1 > num2 THEN PRINT "Greater than" IF num1 < num2 THEN PRINT "Lesser than" IF num1 >= num2 THEN PRINT "Greater than/or, equal to" IF num1 <= num2 THEN PRINT "Lesser than/or, equal to" IF num1 <> num2 THEN PRINT "NOT equal" ...output... Lesser than Lesser than/or, equal to NOT equal
first you make 3 integer variables. lets called them sum1, num1 and num2 then you get user imput that will assign num1 and num2 with values or make a statment giving them valvues such as num1=5 num2=3 then you make a statement that assigns sum1 a valvue, sum1=num1 + num2 Thats it.