Assignment #1: Programming Fundamentals
Assignment #1: Programming Fundamentals
Assignment #1
Character blends comprising of a backslash (\) trailed by a letter or by a mix of digits are
designated "get away from successions.". Getaway arrangements are commonly used to
determine activities, for example, carriage profits and tab developments for terminals and
printers. They are likewise used to give exacting portrayals of nonprinting characters and
characters that typically have uncommon implications, for example, the double quotation
mark ("). Many programming dialects use get away from arrangements in strings to speak to
unique characters. Getaway arrangements are groupings of at least two characters
beginning with a backslash (\).
\a Bell (alert)
\b Backspace
\f Form feed
\n New line
\r Carriage return
\t Horizontal tab
\v Vertical tab
if-end
if-end selection structures are used when only one boolean condition is necessary. In if-end
structures, a process will be only be performed if the boolean condition is true.
If-else
if-else selection structures are used when only one boolean condition is necessary. In if-else
structures, a specific action will be performed if the boolean condition is true and another
action, if the condition is false.
Elseif
elseif structures are a way to combine multiple boolean conditions into a single selection
structure.
Q3: Read two positive numbers N1 and N2. Test whether the larger number is exactly
divisible by the smaller one.
#include<iostream>
int main()
int a;
int b;
cin>>a>>b;
if(a%b==0)
else
system ("pause");
return 0;
}
Q4: Read a number from the user (within range 1-100). Then check whether the number is
greater than, less than or equal to 50
#include<iostream>
int main()
int a;
cin>>a;
else if (a==50)
else
system ("pause");
return 0;
Q5: Take the lengths of the two legs of a right triangle as input and calculates area and
hypotenuse.
Hypotenuse = √ leg12+leg 22
#include <iostream>
#include <math.h>
int main()
cout << "The area of triangle is = " << area << endl;
system ("pause");
return 0;
}
Q6: Read two numbers N1, N2 and a character OP (+,-,*,/), then perform calculation
depending upon the type of character entered by user and display result in format:
N1 op N2 = result
#include<iostream>
int main()
char op;
float num1;
float num2;
cin>>op;
cin>>num1;
cin>>num2;
switch(op)
case '+':
break;
case '-':
break;
case '*':
break;
case '/' :
break;
default:
break;
system ("pause");
return 0;
Q7: Find maximum and minimum of three numbers. Use proper string messages to make
your program readable.
#include<iostream>
int main()
float n1;
float n2;
float n3;
cin>>n1>>n2>>n3;
else
else
system ("pause");
return 0;
}
Q8: Discuss the role and requirement of data types in programming languages.
All variables use data-type during statement to limit the type of data to be put away.
Subsequently, we can say that data types are utilized to tell the variables the type of data it
can store. At whatever point a variable is characterized in C++, the compiler allots some
memory for that variable dependent on the data-type with which it is proclaimed. Each data
type requires an alternate amount of memory. Data types help the related variables
understand the type of data they can store into them.
THE END