0% found this document useful (0 votes)
27 views

A. //program For Biggest Number Using Else-If Aldder

This document contains 4 C++ programs that demonstrate different programming concepts: 1) A program that uses else-if statements to determine the largest of two numbers. 2) A program that uses a for loop to check if a number is prime. 3) A program that uses a while loop to reverse a number. 4) A program that uses a switch statement to display the day of the week corresponding to a number.

Uploaded by

Hajiram Beevi
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views

A. //program For Biggest Number Using Else-If Aldder

This document contains 4 C++ programs that demonstrate different programming concepts: 1) A program that uses else-if statements to determine the largest of two numbers. 2) A program that uses a for loop to check if a number is prime. 3) A program that uses a while loop to reverse a number. 4) A program that uses a switch statement to display the day of the week corresponding to a number.

Uploaded by

Hajiram Beevi
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 4

1. a. //program for biggest number using else-if aldder #include <iostream.h> #include <conio.

h> void main() { int x; int y; clrscr(); cout << "\nEnter X : ; cin >> x; cout << "\nEnter Y : ; cin >> y; if ( x > y ) { cout << "\nX is Greater Than Y"; } else if ( y > x) { cout << "\nY is Greater Than X"; } else { cout << "\nBoth Are Same"; } getch(); }

1.b. //program for checking whether the given number is prime or not using for loop #include<iostream.h> #include<conio.h> void main() { int num, count=0; clrscr(); cout<<"Enter a number :"; cin>>num; for(int i=2; i<num/2; i++) { if(num%i==0) { count++; break; } } if(count==0) cout<<"Prime number"; else cout<<"Not a Prime number"; getch(); }

1.c. //display the given number in reverse order using while loop #include<iostream.h> #include<conio.h> void main() { long no,rev,temp1,temp2; clrscr(); cout<<"\n Enter any Digit number"; cin>>no; rev=0; temp1=no; while(temp1>0) { temp2=temp1%10; rev=rev*10+temp2; temp1=temp1/10; } cout<<"Reverse"<<rev; getch(); } 1.d.//Display day of a week for given number by using switch statement #include<iostream.h> #include<conio.h> void main() { int m; clrscr(); cout<< "Enter the number of the day to be displayed: ";

cin>> m; switch( m) { case 0: cout<<"Sunday\n"; break; case 1: cout<<"Monday\n"; break; case 2: cout << "Tuesday\n"; break; case 3: cout<<"Wednesday\n"; break; case 4: cout<<"Thursday\n"; break; case 5: cout << "Friday\n"; break; case 6: cout<<"Saturday\n"; break; default: break; } getch(); } cout << "Fail\n";

You might also like