You are on page 1of 17

$$$$$$$$$$$$#include <iostream> using namespace std ; void main () { int x ; start: cout<< " A=" <<endl; cin>>x; if ( x==0)

{ cout<< " you have entered 0\n"; goto start; } else if ( x==1) { cout<< " you have entered 1\n"; goto start; } else { cout<< " wrong input \n"; goto start; } }

Note
exit (0); // to terminate a programme .

Program check : working


cout<< " To continue prees 'Y' or to terminate press 'N'" <<endl; cin>>b; if (b=='Y' || b== 'y' ) // no space before character 'n' , not ' { goto start; } else if (b=='N' || b== 'n' ) { exit (0); } else { cout<<" wrong input "<<endl; goto start; }

n'.

assignment no. 2
#include <iostream> using namespace std ; void main () { char a ,b ; start: cout << " Enter an alphabet in cin>>a; switch(a) { case 'A' : cout<< " Lower case case 'B' : cout<< " Lower case case 'C' : cout<< " Lower case case 'D' : cout<< " Lower case case 'E' : cout<< " Lower case case 'F' : cout<< " Lower case case 'G' : cout<< " Lower case case 'H' : cout<< " Lower case case 'I' : cout<< " Lower case case 'J' : cout<< " Lower case case 'K' : cout<< " Lower case case 'L' : cout<< " Lower case case 'M' : cout<< " Lower case case 'N' : cout<< " Lower case case 'O' : cout<< " Lower case case 'P' : cout<< " Lower case case 'Q' : cout<< " Lower case case 'R' : cout<< " Lower case case 'S' : cout<< " Lower case case 'T' : cout<< " Lower case case 'U' : cout<< " Lower case case 'V' : cout<< " Lower case case 'W' : cout<< " Lower case case 'X' : cout<< " Lower case case 'Y' : cout<< " Lower case case 'Z' : cout<< " Lower case upper case = " << endl;

is is is is is is is is is is is is is is is is is is is is is is is is is is

= = = = = = = = = = = = = = = = = = = = = = = = = =

a b c d e f g h i j k l m n o p q r s t u v w x y z

"<< "<< "<< "<< "<< "<< "<< "<< "<< "<< "<< "<< "<< "<< "<< "<< "<< "<< "<< "<< "<< "<< "<< "<< "<< "<<

endl;break; endl;break; endl;break; endl;break; endl;break; endl;break; endl;break; endl;break; endl;break; endl;break; endl;break; endl;break; endl;break; endl;break; endl;break; endl;break; endl;break; endl;break; endl;break; endl;break; endl;break; endl;break; endl;break; endl;break; endl;break; endl;break;

default : cout<<"wrong input\n"; } cout<< " To continue prees 'Y' or to terminate press 'N'" <<endl; cin>>b; if (b=='Y' || b== 'y' ) { goto start; } else if (b=='N' || b== 'n' ) { exit (0);

} else { cout<<" wrong input "<<endl; goto start; } }

Assignment no. 1

#include <iostream> using namespace std ; void main () { double y = 1.0 ; unsigned int x, i; char b; start: cout<< " Enter an positive integer \n"; cin>>x;

if ( x==0) { cout<<" Factorial of "<< x<< " is = 1 \n"; goto check ; } else { // factorial part . for( i =1 ; i<=x; i++) y = i*y; cout<< " Factorial of "<<x<< " is = " <<y<<endl; i=1; y=1.0; goto check ;

} check: cout<< " To continue prees 'Y' or to terminate press 'N'" <<endl; cin>>b; if (b=='Y' || b== 'y' ) {

goto start; } else if (b=='N' || b== 'n' ) { exit (0); } else { cout<<" wrong input "<<endl; goto start; }

Assignment no. 3

#include <iostream> using namespace std ; void main () { float x, y, z, l; char b; start : cout<<"Input two variable X and Y . "<<endl; cin>>x>>y; z=x; l=y; cout << "X is "<<l<<"and"<< " Y is "<<z<<endl; cout<< " To continue prees 'Y' or to terminate press 'N'" <<endl; cin>>b; if (b=='Y' || b== 'y' ) // no space before character 'n' , not ' n'. { goto start; } else if (b=='N' || b== 'n' ) { exit (0); } else { cout<<" wrong input "<<endl; goto start; }

assignment no. 4

#include <iostream> using namespace std ; void main () { float x, y; char b; start : cout<<"Input two variable X and Y . "<<endl; cin>>x>>y; cout << "X is "<<y<<"and"<< " Y is "<<x<<endl; cout<< " To continue prees 'Y' or to terminate press 'N'" <<endl; cin>>b; if (b=='Y' || b== 'y' ) // no space before character 'n' , not ' n'. { goto start; } else if (b=='N' || b== 'n' ) { exit (0); } else { cout<<" wrong input "<<endl; goto start; }

Assignment no. 5
#include<iostream> using namespace std; void main() { float x, y, z, l; char b; start: cout<< " Enter Four integer "<<endl; cin>>x>>y>>z>>l; if (x>y && x>z && x>l) cout<<" Maximum is "<<x<<endl; else if (y>z && y>x && y>l) cout<<" Maximum is "<<y<<endl; else if (z>y && z>l && z>x) cout<<" Maximum is "<<z<<endl; else cout<<" Maximum is "<<l<<endl; cout<< " To continue prees 'Y' or to terminate press 'N'" <<endl; cin>>b; if (b=='Y' || b== 'y' ) // no space before character 'n' , not ' n'. { goto start; } else if (b=='N' || b== 'n' ) { exit (0); } else { cout<<" wrong input "<<endl; goto start; }

Assignmeny no. : 14
#include <iostream> using namespace std; void main() { int x,y,i; start: i=1; y=2000; cout<<""<<endl; // to look better . cout<<" Enter the number of leap year :"; cin>>x; cout<<"The next "<<x<<" leap years from 2001 is :"; while(i<=x) { y=y+4; cout<<" "<<y; i++;

} goto start;

Assignment no. : 11 (prime number)


#include <iostream> using namespace std; void main() { int x,y =0; start: cout<<" Enter a positive integer :"; cin>>x; for(int a=1; a<=x; a++ ) { if (x%a==0) { y++; } } if(y==2) { cout<< x <<" is prime number"<<endl; } else { cout<< x <<" is not } goto start; prime number"<<endl;

Assignment no. 13
#include <iostream> using namespace std;

void main() { int x ,l,k ; start: cout<<"Enter a number:"<<" "; cin>>x; cout<<"The first "<<x<<" perfect number is :"; for( l=0,k=1;l<x;k++) { int i=1 , sum = 0 ; while(i<k) { if(k%i==0) sum=sum+i; i++; } if(sum==k) { cout<<sum<<" "; l++; } } cout<<""<<endl; cout<<""<<endl; cout<<""<<endl; cout<<""<<endl; k=1; l=0; goto start;

Assignment no. 12
// Fibonacci Series....... for nth term. #include<iostream> using namespace std; void main() { long x, y,z,l; y=0; z=1; cout<<"enter an integer:"; cin>>x; cout<<"Fibonacci numbers "<<x<<" ="<<"0 while(true) { l=y+z; if(l>x)break; { cout<<" "<<l; } y=z; z=l; } cout<<" cout<<" cout<<" cout<<" } "<<endl; "<<endl; "<<endl; "<<endl;

1";

Assignment no. : 15
// Binary to decimal . #include<iostream> using namespace std; void main() { int x,y,decimal=0,i=1; char b; start: cout<<"Enter a binary number:"; cin>>x; while(x!=0) {y=x%10; decimal=decimal+y*i; x=x/10; i=i*2; } cout<<"Deecimal= "<<decimal<<endl; cout<<" "<<endl; cout<<" "<<endl; cout<<" "<<endl; cout<<" "<<endl; cout<< " To continue prees 'Y' or to terminate press 'N'" <<endl; cin>>b; if (b=='Y' || b== 'y' ) // no space before character 'n' , not ' { decimal= 0; i=1; goto start; } else if (b=='N' || b== 'n' ) { exit (0); } else { cout<<" wrong input "<<endl; decimal= 0; i=1; goto start; } }

n'.

Assignment no. 16
// decimal to octal #include<iostream> using namespace std; int main() { int x,z=1,sum=0,remainder; char b; start:

cout<<" Enter a decimal number : "; cin>>x;

while(x!=0) { remainder=x%8; sum=sum+remainder*z; z=z*10; x=x/8; } cout<< "Octal number is : cout<<" cout<<" cout<<" cout<<" "<<endl; "<<endl; "<<endl; "<<endl;

" << sum;

cout<< " To continue prees 'Y' or to terminate press 'N'" <<endl; cin>>b; if (b=='Y' || b== 'y' ) // no space before character 'n' , not ' { z=1; sum=0; goto start; } else if (b=='N' || b== 'n' ) { exit (0); } else { cout<<" wrong input "<<endl; z=1; sum=0; goto start; } }

n'.

Assignment no. 17
// Show an integer wheather prime or not and wheaher #include<iostream> using namespace std; void main() { int x,y = 0,l, count = 0 ; char b; start: cout<<"Enter a positive integer : "; cin>>x; cout<<"\n"; switch(x%2) { case 0: cout<<"\t"<< x<<" is an even number. "<<endl;break; default:cout<<"\t"<< x<<" is an odd number. "<<endl; y=1; break; } switch(y) { case 1: for (int i= 1; i<=x; i++ ) { l=x%i; switch(l) { case 0:count++;break; } } } switch(count) { case 2: cout<<"\t"<<x<<" is a prime number. " <<endl;break; default : switch (x) { case 2 : cout<<"\t"<<x<<" is a prime number. " <<endl;break; case 1 : cout<<"\t"<<x<<" is a prime number. " <<endl;break;

default : cout<<"\t"<<x<<" is'nt a prime number. " <<endl;break; } } cout<<"\n"; //line gap for beautification. cout<<"\n"; cout<<"\n"; cout<<"\n"; cout<< " To continue prees 'Y' or to terminate press 'N'" <<endl; cin>>b; if (b=='Y' || b== 'y' ) // no space before character 'n' , not ' { count=0; y=0; goto start; } else if (b=='N' || b== 'n' ) { exit (0); } else { cout<<" wrong input "<<endl; count=0; y=0; goto start; }

n'.

You might also like