#Include Using Namespace STD Int Main (
#Include Using Namespace STD Int Main (
Q.1. You have two fractions, a/b and b/c their sum can be obtained:
Write a program that encourages the user to enter two fractions and calculate its sum in fractions.
Your output screen should be.
#include <iostream>
using namespace std;
int main()
{
int a,b,c,d, ans, ans2;
cout <<"Enter first friction";
cin>>a>>b;
cout<<a<<"/"<<b<<endl;
cout <<"Enter second friction";
cin>>c>>d;
cout<<c<<"/"<<d<<endl;
cout<<"``````````````````````````````````````"<<endl;
cout<<"a/b+c/d = " <<a<<"/"<<b<<"+"<<c<<"/"<<d<<endl;
ans= (a*d)+(b*c);
ans2= (b*d);
cout<<"Sum = "<<ans<<"/"<<ans2<<endl;
return 0;
}
Q.2. Write a C++ code which uses the nested loop and display the Multiplication Table? Your
output screen should look like the following Figure?
#include <iostream>
using namespace std;
int main()
{
for (int i=1 ; i<=10 ; i++)
{
for (int j=1 ; j<=10 ; j++)
{
cout<<i*j<<" ";
}
cout<<endl;
}
return 0;
}
Q.3. Write a C++ code that sum the digits entered by the user? For example, number= 245
sum of digits 2+4+5= 11.
#include<iostream>
using namespace std;
int main()
{
int x, n, sum = 0;
cout << "Enter the number : ";
cin >> n;
x=n;
while (x != 0)
{
sum = sum + x % 10;
x = x / 10;
}
cout << "sum of the digits "<<n<<" is "<<sum<<endl;
return 0;
}
Write the code for following output screen and explain the concept of difference in output?
If a user enters the “welcome to edureka” so Programs will print in output just “Welcome”.
Use the string in c++; as a word, not print the sentence. If we will print the sentence so use the
getline command;