C++ Assignment
C++ Assignment
Start
Input i, j
Avg=i+j/2
Display Avg
Stop
3, Swap the contents of two variables using a third variable.
Start
Input x,y
z=x
x=z
y=z
Print x, y
Stop
4, Swap the content of two variables without using a third variable.
Start
Input x, y
x=x+y
y=x-y
x=x-y
Print x, y
Stop
5, Read 10 integers from the keyboardin the range 0 – 100, and cout how many of them are larger than
50, and display the result.
Start
n=0
N=0
Output n N = 100?
no
yes
Stop ARRAY[N] > 50?
no
n=n+1
N=N+1
6, Take an integer from the user and display the factorial of that number.
Start
Read m
i=1
fact = 1
false
I <= m
fact = fact * i
i=i+1
Write fact
Stop
1. //Write a program to check whether the given number is even or odd.
#include <iostream>
#include <stdlib.h>
int main()
system("color 0a");
int n;
cin >> n;
if ( n % 2 == 0)
else
return 0;
#include<iostream>
#include <stdlib.h>
int main()
system("color 0a");
double n1,n2,n3;
else
else
else
return 0;
3./* Write a program which accepts days as integer and display total number of
Output
Years: 2
Months: 2
Days: 6 */
#include<iostream>
#include <stdlib.h>
int main()
{
system("color 0a");
int days,y,m,d;
cin>>days;
y=days/365;
days=days%365;
m=days/30;
d=days%30;
return 0;
4. /*Write a program that calculates a random number 1 through 100. The program then asks
If the user guesses too high or too low then the program should output "too high" or "too
low" accordingly.
The program must let the user continue to guess until the user correctly guesses the
number*/
#include <iostream>
#include <stdlib.h>
int main()
system("color 0a");
int guess;
if (guess < 0)
else if
else
return 0;
#include<iostream>
#include <stdlib.h>
int main()
system("color 0a");
cin>>num;
n=num;
do
if(n == rev)
else
return 0;
6. /*A prime number is an integer greater than one and divisible only by itself
and one.
The first seven prime numbers are 2, 3, 5, 7, 11, 13, and 17. Write a program that displays all the
#include <iostream>
#include <stdlib.h>
int isPrimeNumber(int);
int main()
{
system("color 0a");
bool isPrime;
isPrime = isPrimeNumber(n);
if(isPrime == true)
cout<<n<<" ";
return 0;
int isPrimeNumber(int n)
if (n%i == 0) {
isPrime = false;
break;
return isPrime;
7./* Write a C++ program that counts the number of digits in an integer number.
#include<iostream>
#include <stdlib.h>
using namespace std;
int main()
system("color 0a");
cin>>num;
while(num!=0)
num = num/10;
count++;
cout<< count;
a)
#include <iostream>
#include <stdlib.h>
int main()
system("color 0a");
int n=6;
int i, j;
{
//print * equal to row number
return 0;
b)
#include<iostream>
#include <stdlib.h>
int main()
system("color 0a");
int rows=7;
int i, j, space;
else
return 0;
c)
#include<iostream>
#include <stdlib.h>
system("color 0a");
int rows=6;
int i, j, space;
return 0;
d)
e)
#include<iostream>
#include <stdlib.h>
int main()
system("color 0a");
cout<< "*";
else
cout<<endl;
int rows=10;
}
for (int b = (2 - a); b < (2 - a) + (2 * a - 1); b++) {
f)