0% found this document useful (0 votes)
46 views7 pages

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

The document contains code snippets for 3 programs using loops: 1) A program that takes a number as input and displays its multiplication table using a for loop. 2) A program that displays the product of all odd numbers from 1 to 10 using a for loop. 3) A program that displays the first five numbers and their squares using a do-while loop.

Uploaded by

Saliha Satti
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
46 views7 pages

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

The document contains code snippets for 3 programs using loops: 1) A program that takes a number as input and displays its multiplication table using a for loop. 2) A program that displays the product of all odd numbers from 1 to 10 using a for loop. 3) A program that displays the first five numbers and their squares using a do-while loop.

Uploaded by

Saliha Satti
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 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