0% found this document useful (0 votes)
56 views

Assignment Icp: Submitted By: Nadeem Ahmed Submitted To: Pro. Syed NASIR MEHDI

This document contains the assignment submission of 7 C++ programs by student Nadeem Ahmed to professor Syed Nasir Mehdi. Each program is described briefly and includes the source code and output. The programs cover basics of C++ like accepting user input, performing calculations, variable manipulation and type casting.

Uploaded by

Rao Wasim
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
56 views

Assignment Icp: Submitted By: Nadeem Ahmed Submitted To: Pro. Syed NASIR MEHDI

This document contains the assignment submission of 7 C++ programs by student Nadeem Ahmed to professor Syed Nasir Mehdi. Each program is described briefly and includes the source code and output. The programs cover basics of C++ like accepting user input, performing calculations, variable manipulation and type casting.

Uploaded by

Rao Wasim
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

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>

using namespace std;

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>

using namespace std;

#define MAX_LENGTH 100


int main()
{
char name[MAX_LENGTH]={0};
int age;
cout<<"Enter name of the person: ";
cin.getline(name,MAX_LENGTH);
cout<<"Enter age: ";
cin>>age;
cout<<"Name: "<<name<<endl;
cout<<"Age: "<<age<<endl;

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;

cout<<"Enter temp. in Fahrenheit: ";


cin>>far;
cel = (far - 32) * 5/9;
cout<<"Temp. in Celsius: "<<cel;
return 0;
}
OUTPUT:
5. Write a program in C++ which would swap the values of two variables using the
third variable.

#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:

You might also like