Subject
Programming Fundamental
Assignment No 01 Marks 20
Q1: Write a program which asks the user to enter Hours, minutes and
seconds and then calculate
the total time in seconds and display it.
(5)
Q2: Write a program which accepts a character and display its ASCII
value. (5)
Q3: Write a program to swap the values of two variables without using
third variable. (10)
Question 1: Write a program which asks the
user to enter Hours, minutes and seconds and then
calculate the total time in seconds and display it
Answer:
PROGRAM
#include<iostream.h>
#include<conio.h>
int main()
int x , y, z, total;
cout<<" enter the value of x = hour y = minutes and z = seconds \n";
getch();
}
Output:
QUESTION 2:Which program accepts a character
and display its ASCII value?
Answer:
Program:
#include<iostream.h>
#include<stdlib.h>
int main()
char ascii;
int numeric;
cout << "Give character: ";
cin >> ascii;
cout << "Its ascii value is: " << (int) ascii << endl;
cout << "Give a number to convert to ascii: ";
cin >> numeric;
cout << "The ascii value of " << numeric << " is " << (char) numeric;
system(PAUSE);
}
Output:
Question 3: Write a program to swap the values of two
variables without using third variable
Answer:
Program:
#include <iostream.h>
#include <stdlib.h>
int main()
{
int x, y, temp;
x = 10;
y = 20;
cout<<"Before exchange" <<endl;
cout<<"x = "<< x << endl;
cout<<"y = "<< y << endl;
temp = x;
x = y;
y = temp;
cout<<"After exchange" <<endl;
cout<<"x = "<< x << endl;
cout<<"y = "<< y << endl;
system("PAUSE");
}
Output: