C++ program (using a function) to print its cube.

Q36. Write a program (using a function) to accept a number and print its cube.

Ans.

#include<iostream.h>

#include<conio.h>  //for clrscr()

float cube(float); //Function cube’s declaration

void main()

{

float num;

clrscr();//for clear screen

cout<<“\n Enter a number: “; Read More …

C++ program to display ASCII code of a character and vice versa.

Q35. Write a c++ program to display ASCII code of a character and vice versa.

Ans.

#include<iostream.h>

#include<conio.h>   //for clrscr()

void main()

{

char ch=’A’;    //assign ASCII code for ‘A’ to ch

int num=ch;     //store same code in an int

clrscr();  //for clear screen

cout<<“\n The ASCII code for “<<ch<<” is “<<num; Read More …

C++ program that generates output as 5 10 9.

Q33. Write a program that generates the following output:

        5

        10

        9

Assign value 5 to a variable using =. Multiply it with 2 to generate 10 and subtract 1 to generate 9.

Ans.

#include<iostream.h>

#include<conio.h>  //for clrscr()

void main()

{

int value;

value=5;

clrscr();   //for clear screen

cout<<“\n “<<value; Read More …

C++ program that read values of w, x, y and z and display the value of P.

Q28. Write a program to read values of w, x, y and z and display the value of P, where

P= w+x / y-z

Ans.

#include<iostream.h>

#include<conio.h>   //for clrscr()

void main()

{

int w,x,y,z,P;

clrscr();          //for clear screen

cout<<“\n Enter the value of w: “;

cin>>w;

cout<<“\n Enter the value of x: “; Read More …

Write a C++ program to accept percentage and print division accordingly.

Q22. Write a C++ program to accept percentage and print division accordingly.

Solution:

#include<iostream.h> //standard input/output header file

#include<conio.h> //for clrscr()

 

int main()

{

int per;

 

clrscr(); //for clearing the screen

 

cout<<“\n Enter the percentage: “;

cin>>per;

 

per>=60? cout<<“\n I Division.” : per<60&&per>=45? cout<<“\n II Division.” :per>=36? cout<<“\n III Division.” : cout<<“\n Fail.”;

 

getch(); //holds the screen until any key is pressed

return 0; //makes main() finish

}

 

OUTPUT:

CASE 1:

Enter the percentage: 78

 

I Division.

 

CASE 2:

Enter the percentage: 57

 

II Division.

 

CASE 3:

Enter the percentage: 33

 

Write a C++ program to accept a number and if it is less than 50 and greater than 20 than print its square value.

Q21. Write a C++ program to accept a number and if it is less than 50 and greater than 20 than print its square value.

Solution:

#include<iostream.h> //standard input/output header file

#include<conio.h> //for clrscr()

 

int main()

{

int a;

 

clrscr(); //for clearing the screen

 

cout<<“\n Enter a number: “;

cin>>a;

 

a<50&&a>20? cout<<“\n The square of number is “<<a*a<<“.” : cout<<“\n The number is “<<a<<“.”;

 

getch(); //holds the screen until any key is pressed

return 0; //makes main() finish

}

 

 

OUTPUT:

CASE 1:

Enter a number: 45

 

The square of number is 2025.

 

CASE 2:

Enter a number: 78

 

The number is 78.

Write a C++ program to accept a number and if it is less than 10 then print its square value.

Q20. Write a C++ program to accept a number and if it is less than 10 then print its square value.

Solution:

#include<iostream.h> //standard input/output header file

#include<conio.h> //for clrscr()

 

int main()

{

int a;

 

clrscr(); //for clearing the screen

 

cout<<“\n Enter a number: “;

cin>>a;

 

a<10? cout<<“\n The square of number is “<<a*a<<“.” : cout<<“\n The number is “<<a<<“.”;

 

getch(); //holds the screen until any key is pressed

return 0; //makes main() finish

}

 

OUTPUT:

CASE 1:

 

Enter a number: 9

 

The square of number is 81.

 

CASE 2:

Enter a number: 11

 

The number is 11.

 

Write a C++ program to accept a number and determine whether it is even or odd.

Q19. Write a C++ program to accept a number and determine whether it is even or odd.

Solution:

#include<iostream.h> //standard input/output header file

#include<conio.h> //for clrscr()

 

int main()

{

int a;

 

clrscr(); //for clearing the screen

 

cout<<“\n Enter a number: “;

cin>>a;

 

a%2==0? cout<<“\n It is an even number.” : cout<<“\n It is an odd number.”;

 

getch(); //holds the screen until any key is pressed

return 0; //makes main() finish

}

 

OUTPUT:

CASE 1:

Enter a number: 7

 

It is an odd number.

 

CASE 2:

Enter a number: 6

 

It is an even number.

Write a C++ program to accept a character and determine whether its number, alphabet or symbol.

Q18. Write a C++ program to accept a character and determine whether its number, alphabet or symbol.

Solution:

#include<iostream.h> //standard input/output header file

#include<conio.h> //for clrscr()

 

int main()

{

char a;

 

clrscr(); //for clearing the screen

 

cout<<“\n Enter any character: “;

cin>>a;

 

a>=65&&a<=90||a>=97&&a<=122? cout<<“\n It is an alphabet.” : a>=48&&a<=57? cout<<“\n It is a number.” : cout<<“\n It is a symbol.”;

 

getch(); //holds the screen until any key is pressed

return 0; //makes main() finish

}

 

OUTPUT:

CASE 1:

Enter any character: d

 

It is a alphabet.

 

 

CASE 2:

Enter any character: 3

 

It is a number.

 

CASE 3:

Enter any character: $

 

It is a symbol.

Write a C++ program to accept a character and determine whether it’s upper case or lower case.

Q17. Write a C++ program to accept a character and determine whether it’s upper case or lower case.

Solution:

#include<iostream.h> //standard input/output header file

#include<conio.h> //for clrscr()

 

int main()

{

char a;

 

clrscr(); //for clearing the screen

 

cout<<“\n Enter any character: “;

cin>>a;

 

a>=90?cout<<“\n It is a lower case letter.” : cout<<“\n It is an upper case letter.”;

 

getch(); //holds the screen until any key is pressed

return 0; //makes main() finish

}

 

OUTPUT:

CASE 1:

Enter any character: r

 

It is a lower case letter.

 

CASE 2:

Enter any character: R

 

It is an upper case letter.