Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Practical No. 06: Title: Programs Using Loops and Switches

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 7

Practical no.

06
Title: Programs using loops and switches.

 Write the program that input test scores of a student and display his grade.
#include <iostream>

using namespace std;

int main()

int a;

cout<<"enter number:";

cin>> a;

if (a>=100){

cout<<"Your grade is A"<<endl;}

else if (a>=90){

cout<<"Your grade is B"<<endl;}

else if (a>=80){

cout<<"Your grade is B-"<<endl;}

else if (a>=70){

cout<<"Your grade is C "<<endl;}

lse if (a>=60){

cout<<"Your grade is D-"<<endl;}

else cout<<”Your grade is F”; }


 Write a program that inputs a letter from the user and shows weather it is a vowel
or a consonant.
#include <iostream>

using namespace std;

main()

char c;

cout<<"enter any latter: ";

cin>> c;

switch(c)

case 'a': cout<<"vowel"; break;

case 'e': cout<<"vowel"; break

case 'i': cout<<"vowel"; break;

case 'o': cout<<"vowel"; break;

case 'u': cout<<"vowel"; break;

default: cout<<"error"; }}\

start

Enter any letter

yes

Is c=a
vowel

yes

Is c=e
vowel

yes

Is c=i
vowel

yes

Is c=o vowel

yes

Is c=u vowel

no

consonent

End
Practical no. 07
Title: Write programs using different arithmetic operations and loops.

 Write a program that inputs a number for the user and displays its table using for
loop.
#include <iostream>

using namespace std;

main()

int len,tab,a;

cout<<"enter no.of table: ";

cin>> tab;

cout<<"enter length of table: ";

cin>> len;

for (a=1;a<=10;a++)

cout<<tab<<"*"<<a<<"="<<tab*a<<endl; }

 Write a program that displays a product of odd numbers from 1 to 10.


#include <iostream>

using namespace std;

main()

int c,a;
for(c=1;c<=10;c=c+2){

cout<<c<<endl;

a*=c;}

cout<<"product is: "<<a<<endl;

 Write a program that displays first five numbers and their squares using do while
loop.
#include <iostream>

using namespace std;

int main()

{ int a;

int j=1;

int c;

do

{ c=j*j;

cout<<"Value of variable j is:"<<j <<"the square is ="<<c<<endl;

j++;

}while (j<=5);

return 0; }

You might also like