Assignment Icp: Submitted By: Nadeem Ahmed Submitted To: Pro. Syed NASIR MEHDI
Assignment Icp: Submitted By: Nadeem Ahmed Submitted To: Pro. Syed NASIR MEHDI
ROLLNO: SP19-MCS-016
1.Write a program that accepts a character from the user and display
its ASCII Value.
#include<iostream>
int main ()
{
char c;
cout << "Enter a character : ";
cin >> c;
cout << "ASCII value of " << c <<" is : " << (int)c;
return 0;
}
OUTPUT:
2.Write a program in C++ that inputs name, age from the user and then displays
these values on the
Screen?
#include <iostream>
return 0;
}
OUTPUT:
3. Write a program that reads a four digit number from user, then the
program separates digits of the
number e.g. 4567 to displayed as:
4
5
6
7
#include <iostream>
using namespace std;
int main()
{
int num;
cout << "Enter a four-digit number: ";
cin >> num;
cout <<num /1000<< endl;
num =num % 1000;
cout <<num /100<<endl;
num =num % 100;
cout<<num /10<<endl;
num =num % 10;
cout<<num <<endl;
return 0;
}
OUTPUT:
4. Write a program that take temperature in Fahrenheit from user and show the
equivalent temperature
in Celsius.
FORMULA:
[c = (f - 32) * 5/9; ]
Convert Fahrenheit to Celsius in C++
#include<iostream>
using namespace std;
int main()
{
float cel, far;
#include <iostream>
using namespace std;
int main()
{
int a = 5, b = 10, temp;
cout << "Before swapping." << endl;
cout << "a = " << a << ", b = " << b << endl;
temp = a;
a = b;
b = temp;
cout << "\nAfter swapping." << endl;
cout << "a = " << a << ", b = " << b << endl;
return 0;
}
OUTPUT:
6. Write a program in C++ which would swap the values of two variables without
using the third variable.
#include<iostream>
using namespace std;
int main()
{
int a,b;
cout<<"Enter the first no=:";
cin>>a;
cout<<"\n\nEnter the second no=:";
cin>>b;
cout<<"\na"<<" is ="<<a<<"\nb"<<" is ="<<b<<endl;
a=a+b;
b=a-b;
a=a-b;
cout<<"after swap number";
cout<<"\n\na="<<a<<"\nb="<<b;
return 0;
}
OUTPUT:
7.Check the output of the following piece of code on compiler and explain why is
it so:
ANS= in this program swap the value using of two number .
#include<iostream>
using namespace std;
int main()
{
char c = 'a';
int n = 'a';
cout << "c = " << c << endl;
cout << "n = " << n << endl;
return 0;
}
OUTPUT: