

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Various coding exercises focused on conditional statements and programming examples using c/c++. It includes converting statements to conditional statements, writing and executing code, and creating a program that lets users enter an integer value and validates the input. Also, there is a simple menu program and a program for player selection in federal colleges.
Typology: Exercises
1 / 3
This page cannot be seen from the preview
Don't miss anything!


Given that A,B,C,D are all integers having some initial value (which is not know) Example Statement Conditional Statement A,B,C and D are all positive numbers A>0 && B>0 && C>0 && D>
Convert the following into conditional statements for A,B,C and D
A, B, C, and D all are negative numbers
A and B are positive numbers or C and D are negative numbers
A is even B is odd C is positive and D is negative
Any of A,B,C or D is divisible by 5
A or B is even and C is odd
A and B are greater than 20 or C and D are less than 100
Write the following code, execute it and compare the output
Program-01 (character input) #include <stdio.h> #include <conio.h> #include <iostream.h> main() {
char ans;
cout<<”Is today your birthday? (Y/N) : “; cin>>ans;
if(ans==’y’ || ans == ‘Y’) cout<<” Happy Birthday To You “<<endl ; else cout<<”Have a nice day”<<endl; getch(); }
Program-02 (Simple while loop) #include <stdio.h> #include <conio.h> #include <iostream.h> main() {
int a=10; while(a<1){ cout<<”Value of a = “<<a; a--; }
getch(); }
Program-03 (Conditional while loop) #include <stdio.h> #include <conio.h> #include <iostream.h> main() { int a=10; while(a%2!=0){
cout<<”Enter Value of a = “; cin>>a; cout<<endl; } getch(); }
Program-
Write a program that lets user enter an integer value between 1 and 10, the program validates the input , if the value entered is between 1 and 10 the program prints the value entered otherwise the program takes the input again , the program ends on legal values otherwise keep taking input.
Program-05 (Simple Menu program)
#include <stdio.h> #include <conio.h> #include <iostream.h> main() {
char choice,finish;
do{ cout<<”What do you want to know “<<endl; cout<<”1-My Name”<<endl; cout<<”2-My Roll no”<<endl; choice=getch(); if(choice==’1’) cout<<”My name is ---“<<endl;
if(choice == ‘2’) cout<<”My roll number is ---“<<endl;