C++ Control Flow Statements 3

Question:1
C++ program to take input for the name and age of a person, check and print whether the person can vote or not?
Sol:

#include<iostream>
using namespace std;
int main()
{
	char name[20];
	int age;
	cout<<"Enter name ";
	cin>>name;
	cout<<"Enter age ";
	cin>>age;
	if(age>=18)
	cout<<"You can vote";
	else
	cout<<"you cannot vote";
	return(0);
}
/* Output */
Enter name amit
Enter age 12
you cannot vote
/* Output */
Enter name Amit
Enter age 21
You can vote

Question:2
C++ program to take input for a number if number<=10 calculate and print its square?
Sol:

#include<iostream>
using namespace std;
int main()
{
	int a,b;
	cout<<"Enter any no ";
	cin>>a;
	if(a<=10)
	{
		b=a*a;
		cout<<"Square = "<<b<<endl;
	}
	
	return(0);
}
/* Output */
Enter any no 5
Square = 25

Question:3
C++ program to take input for a number if number<=10 calculate and print its cube otherwise print its square?
Sol:

#include<iostream>
using namespace std;
int main()
{
	int a,b;
	cout<<"Enter any no ";
	cin>>a;
	if(a<=10)
	{
		b=a*a*a;
		cout<<"Cube = "<<b<<endl;
	}
	else
	{
		b=a*a;
		cout<<"Square = "<<b<<endl;
	}
	
	return(0);
}
/* Output */
Enter any no 5
Cube = 125
/* Output */
Enter any no 12
Square = 144

Question:4
C++ program to take a number check and print whether the number is +ve , -ve or zero?
Sol:

#include<iostream>
using namespace std;
int main()
{
	int a;
	cout<<"Enter any no ";
	cin>>a;
	if(a==0)
	cout<<"Number is zero";
	else
	  if(a>0)
	  cout<<"Number is +ve";
	  else
	  cout<<"Number is -ve";
	return(0);
}
/* Output */

Enter any no 25
Number is +ve

Enter any no -10
Number is -ve

Enter any no 0
Number is zero