Beruflich Dokumente
Kultur Dokumente
QUESTION 1
Write a program to print the word Welcome.
#include <iostream>
using namespace std;
int main()
{
cout << "Welcome \n";
return 0;
}
//Output :
Welcome
QUESTION 2
Write a program to print a sentence in a single line and in three lines as like
below.
Hello, welcome to C++ Programming
and
Hello,
welcome to
C++ Programming
#include <iostream>
using namespace std;
int main()
{
cout <<
return 0;
}
//Output :
Hello, welcome to C++ Programming
#include <iostream>
using namespace std;
int main()
{
cout << "Hello,\n welcome to\n C++ Programming\n";
return 0;
}
//Output :
Hello,
welcome to
C++ programming
QUESTION 3
Write a program that prints the sum, difference and product of two integers.
Initialize the integers with the values 14 and 8.
#include <iostream>
using namespace std;
int main()
{
int a,b ;
int sum, difference, product;
a=14;
b=8;
sum= a+b;
difference= a-b;
product= a*b;
cout << sum <<"\n";
cout << difference <<"\n";
cout << product <<"\n;
return 0;
}
// Output:
22
6
112
QUESTION 4
Write a program that prints the sum, difference, product, quotient, and
remainder of two numbers that are input interactively.
#include <iostream>
using namespace std;
int main()
{
int a,b;
int sum, diff, product, quotient, remainder;
" ;
>> a;
" ;
>> b;
sum=a+b;
diff=a-b;
product=a*b;
quotient=a / b;
remainder = a%b;
<< quotient<<"\n";
return 0;
}
//Output :
Please enter a value of a: 34
Please enter a value of b: 27
The sum of a and b is : 61
The difference of a and b is :
QUESTION 5
Write a program to read the floating point number and convert it to integer
//Output_truncate :
Please enter a decimal number : 45.77
The integer number you will get is : 45
{
goto write;
}
else if(value==2)
{
return 0;
}
else
{
cout<<"Error! Please understand the COMMAND!!" <<endl;
goto write;
}
}
or
Press 2 for No
1
Please enter a decimal number : 1000.87
The integer number that you will get after round off is : 1001
Do you want to continue with other decimal number?
or
Press 2 for No
8
Error! Please understand the COMMAND!!
Please enter a decimal number : 194.499
The integer number that you will get after round off is : 194
Do you want to continue with other decimal number?
Press 1 for Yes
or
Press 2 for No
#include <iostream>
#include <cmath>
#include <iomanip>
int main()
{
long double x,value;
int y;
write:
cout << "Please enter a decimal number : ";
cin >>x;
y = long double (x);
cout<< "The integer number you will get is : ";
cout<< fixed << setprecision (0) << x <<endl;
/* fixed is used
setprecision(0),
setprecision(1),
place ,2 decimal
cin>> value;
if(value==1)
{
goto write;
// goto (statement);
}
else if(value==2)
{
return 0;
}
else
{
cout<< "Error! Please understand the COMMAND!!" <<endl;
goto write;
}
}
or
Press 2 for No
1
Please enter a decimal number : 44.78
The integer number you will get is : 45
Do you want to continue with other decimal number?
Press 1 for Yes
or
Press 2 for No
1
Please enter a decimal number : 0.999993
The integer number you will get is : 1
Do you want to continue with other decimal number?
Press 1 for Yes
Press 2 for No
or