Posts

Showing posts from April, 2020

PROGRAM TO PERFORM IF ,TO CKECK THE NUMBER IS POSITIVE

Program to perform if: Code: #include<iostream.h> #include<conio.h> void main() { clrscr(); int a; cin>>a; if (a>0) cout<<"number is positive"; } Output: 3 number is positive

PROGRAM TO PERFORM FUNCTION OVERLOADING

Program to perform function overloading: Code: #include<iostream.h> #include<conio.h> void multiply(int x) { cout <<"the value is"<<"\t"<<x*3<<"\n"; } void multiply(int x,int y) { cout<<"the value is"<<"\t"<<x*y<<"\n"; } void main() { clrscr(); multiply(3); multiply(3,5); getch(); } Output: the value is 9 the value is 15

PROGRAM TO PERFORM INLINE FUNCTION

Program to perform inline function: Code: #include<iostream.h> #include<conio.h> inline float convert_feet(int x) { return x*4; } void main() { clrscr(); int inches; cin>>inches; cout<<"the value is"<<"\t"<<convert_feet(inches); getch(); } Output: 5 the value is 20

PROGRAM TO PERFORM RRETURN BY REFERENCE

Program to perform return by reference: Code: #include<iostream.h> #include<conio.h> void main() { clrscr(); int &max(int &,int &); int a,b; cin>>a>>b; max(a,b)=-1; cout<<a<<"\t"<<b; } int &max(int &x,int &y) { if(x>y) return x; else return y; } Output: 3 4 3     -1

PROGRAM TO PERFORM CALL BY REFERENCE

Pr ogram to perform call by reference: Code: #include<iostream.h> #include<conio.h> void exchange(int &a,int &b) { int c; c=a; a=b; b=c; } void main() { clrscr(); int a,b; cin>>a>>b; cout<<"\t"<<"\nbefore function call\t"; cout<<a<<"\t"<<b; exchange(a,b); cout<<"\t"<<"\nafter function call\t"; cout<<a<<"\t"<<b; getch(); } Output: 3 5 before function call 3 5 after function call 5 3

PROGRAM TO PERFORM CALL BY VALUE

Program to perform call by value : Code: #include<iostream.h> #include<conio.h> void exchange(int a,int b) { int c; c=a; a=b; b=c; } void main() { clrscr(); int a,b; cin>>a>>b; cout<<"\t"<<"\nbefore function call\t"; cout<<a<<"\t"<<b; exchange(a,b); cout<<"\t"<<"\nafter function call\t"; cout<<a<<"\t"<<b; getch(); } Output:  3 5 before function call 3 5 after function call 5 3

PRINT IF PREVIOUS IS SMALLER

Image

BOTH ADJACENT ELEMENTS - ODD OR EVEN

Image

SUM PRODUCT DIFFERENCE DIVISION AND MODULO

SUM PRODUCT DIFFERENCE DIVISION AND MODULO: In this program we are going to get  Two input from the user and print their sum , difference, product , division and the modulo. CODE: #include<stdio.h> #include <stdlib.h> int main() { int num1,num2,num,difference,division,modulo; scanf("%d %d",&num1,&num2); if(num1>num2) {     difference=num1-num2;     division=(int)num1/num2;     modulo=(int)num1%num2; } else {     difference=num2-num1;     division=(int)num2/num1;      modulo=(int)num2%num1; } printf("SUM : %d\n",num1+num2); // "\n" is usedthe move to next line and %d to print the integer printf("DIFFERENCE : %d\n",difference); printf("PRODUCT : %d\n",num1*num2); printf("DIVISION : %d\n",division); printf("MODULO : %d\n",modulo); return 0; } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 ...

PRINT HELLO WORLD

PRINT HELLO WORLD: In this program ,we use print statement to print "HELLO WORLD!" . The output statement can be printed in the following method. CODE: #include<stdio.h> #include <stdlib.h> int main() {   printf("HELLO WORLD!");// type the statement you want to print inside the " ". } Your Program Output: HELLO WORLD!