Está en la página 1de 37

//Sum and Average of two numbers

#include<iostream.h> #include<conio.h> void main() { clrscr(); int num1,num2; float sum,avg; cout<<"Enter number1:"; cin>>num1; cout<<"Enter number2:"; cin>>num2; sum=num1+num2; avg=sum/2; cout<<"Sum:"<<sum; cout<<"\nAverage:"<<avg; getch(); }

//Program to implement break statement


#include<iostream.h> #include<conio.h> void main() { clrscr(); int t; for(t=1;t<=100;t++) { cout<<t<<"\n"; if(t==24) break; } getch(); }

//Program to create calculator using switch case statement


#include<iostream.h> #include<conio.h> void main() { clrscr(); int ch,num1,num2,s; cout<<"Calculator"; cout<<"\nEnter the number1:"; cin>>num1; cout<<"Enter the number2:"; cin>>num2; cout<<"!!!Enter your choice for the operation!!!"; cout<<"\n1.Addition"; cout<<"\n2.Subtraction"; cout<<"\n3.Multiplication"; cout<<"\n4.Division"; cout<<"\nEnter your choice(1-4):"; cin>>ch; switch(ch) { case 1 : s=num1+num2; cout<<"Addition of two numbers:"<<s; break;

case 2 : s=num1-num2; cout<<"Subtraction of two numbers:"<<s; break; case 3 : s=num1*num2; cout<<"Multiplication of two numbers:"<<s; break; case 4 : s=num1/num2; cout<<"Division of two numbers:"<<s; break; default : cout<<"!!!!!Wrong Choice!!!!!"; break; } getch(); }

//Program to implement continue statement


#include<iostream.h> #include<conio.h> void main() { clrscr(); int i; for(i=1;i<=10;i++) { if(i%4==0) continue; cout<<i<<"\n"; } getch(); }

//Program to print the Fibonacci series


#include<iostream.h> #include<conio.h> void main() { clrscr(); int a,b,c,n; a=0; b=1; cout<<"Enter the Length of Fibonacci series:"; cin>>n; cout<<a<<" "<<b; for(int i=2;i<n;i++) { c=a+b; a=b; b=c; cout<<" "<<c; } getch(); }

10

//Program to implement goto statement


#include<iostream.h> #include<conio.h> void main() { clrscr(); int t; t=1; loop1: cout<<t<<"\n"; t++; if(t<=24) goto loop1; getch(); }

11

12

//Largest number among three number


#include<iostream.h> #include<conio.h> void main() { clrscr(); int a,b,c; cout<<"Enter the Number 1:"; cin>>a; cout<<"Enter the Number 2:"; cin>>b; cout<<"Enter the Number 3:"; cin>>c; if(a>b && a>c) cout<<"Largest Number :"<<a; else if (b>c) cout<<"Largest Number :"<<b; else cout<<"Largest Number :"<<c; getch(); }

13

14

//Program to find the prime number


#include<iostream.h> #include<conio.h> void main() { clrscr(); int i,num; cout<<"Enter a Number:"; cin>>num; for(i=2;i<=num-1;i++) { if(num%i==0) { cout<<num<<" is not prime"; break; } } if(i==num) cout<<num<<" is prime"; getch(); }

15

16

//Program to print the reverse of a number


#include<iostream.h> #include<conio.h> void main() { clrscr(); int num,a; cout<<"Enter the Number:"; cin>>num; cout<<"Reverse of the number "<<num<<" is "; do { a=num%10; num=num/10; cout<<a; }while(num!=0); getch(); }

17

18

//Program to find the sum of digit of a number


#include<iostream.h> #include<conio.h> void main() { clrscr(); int num,sum=0,a; cout<<"Enter the Number:"; cin>>num; do { a=num%10; sum+=a; num=num/10; }while(num!=0); cout<<"Sum of the numbers:"<<sum; getch(); }

19

20

//Program to print the table of a number


#include<iostream.h> #include<conio.h> void main() { clrscr(); int n,i; cout<<"Enter the number of the table to be created:"; cin>>n; for(i=1;i<=10;i++) { cout<<n<<"*"<<i<<"="<<n*i<<"\n"; } getch(); }

21

22

//Program to calculate area of circle using while loop


#include<iostream.h> #include<conio.h> void main() { clrscr(); int r; float area; cout<<"Enter the Radius of the Circle:"; cin>>r; while(r!=0) { area=3.14*r*r; cout<<"Area of the circle:"<<area; cout<<"\nEnter radius of the Circle:"; cin>>r; } getch(); }

23

24

//Program to implement Single Dimensional Array


#include<iostream.h> #include<conio.h> void main() { clrscr(); int num[5],i; cout<<"Enter five Numbers:"; for(i=0;i<5;i++) cin>>num[i]; getch(); }

25

26

//Program to implement a Two Dimensional Array


#include<iostream.h> #include<conio.h> void main() { clrscr(); int a[3][3],i,j; for(i=1;i<=3;i++) { for(j=1;j<=3;j++) { cout<<"Enter Element["<<i<<"]["<<j<<"]:"; cin>>a[i][j]; } } for(i=1;i<=3;i++) { for(j=1;j<=3;j++) { cout<<a[i][j]<<" "; } cout<<"\n"; } getch();

27

28

//Program to implement Nested Function


#include<iostream.h> #include<conio.h> void func1(); void func2(); void func3(); void main() { clrscr(); cout<<"Hello Friends"; func1(); getch(); } void func1() { cout<<"\nGod Helps"; func2(); } void func2() { cout<<" those who"; func3(); } void func3()

29

{ cout<<" help themselves"; }

30

//Program to get and print the number of Character in String


#include<iostream.h> #include<conio.h> void main() { clrscr(); char book_name[]="Mastering in C++"; int i=0; while(book_name[i]!='\0') { cout<<book_name[i]; i++; } cout<<"\nNumber of Characters in the String:"<<i; getch(); }

31

32

//Program to implement Recursive Function


#include<iostream.h> #include<conio.h> void main() { int n; long int factorial(int); clrscr(); cout<<"Enter the number for finding a Factorial:"; cin>>n; if(n<0) cout<<"Factorial is not Possible"; else cout<<factorial(n); getch(); } long int factorial(int n) { if(n==0) return 1; else return(n*factorial(n-1)); }

33

34

//Program to implement class concept


#include<iostream.h> #include<conio.h> class item { int number; float cost; public: void getdata(int a,float b); void pushdata() { cout<<"Number:"<<number<<"\n"; cout<<"Cost:"<<cost<<"\n"; } }; void item :: getdata(int a,float b) { number=a; cost=b; } int main() { clrscr(); item x;

35

x.getdata(100,299.95); x.pushdata(); getch(); return 0; }

36

37

También podría gustarte