Home Basic Loop Array string Function Pointer Contact STUDY

AHF    C    PROGRAM    SOLVING

Programming tips

Working with switch case



Comment



Header file



Test expression



Specifer




Function_ general instruction for cleaning room by robot




// AHF C PROGRAM SOLVING

//The problem are solving here using FUNCTION

#include<stdio.h> #include<math.h> #define pf printf //function declaration char R(char ch, char a, char b); int main() { char ch,a,b,robot; pf("\nEnter the room status\t(c for clear and d for dirty)\n\n\t\t and\n enter the room number (A or B): "); scanf("%c %c %c",&a,&b,&ch); //function call robot=R(ch,a,b); if(ch=='A') //selecting room number { //checking clean(a) condition for room A if(a=='c') //if clean go to room B { pf("\nMove room B."); } if(a=='d') //if dirty clean room A and go to room B { pf("\nClear the room A."); pf("\nMove to room B."); } //checking dirty (b) condition for room B if(b=='d') //if dirty clean room B { pf("\nClear room B."); pf("\nWait for dirty."); } if(b=='c') //if room B is clean robot will stop { pf("\nWait for dirty."); } } else if(ch=='B') //selecting room number { //checking dirty (b) condition for room B if(b=='c') //if room B is clean go to room A { pf("\nMove to room A."); } if(b=='d') //if room B is dirty, clean and go to room A { pf("\nClear room B."); pf("\nMove to room A."); } ////checking clean (a) condition for room A if(a=='c') //if room A is clean robot will stop { pf("\nWait for dirty."); } if(a=='d') //if room A is dirty, clean and stop { pf("\nClear room A."); pf("\nWait for dirty."); } } } //function definition char R(char x, char y, char z) //function header //function body { char m,n,o; if(m=='A') { if(n=='c') { return y; } if(n=='d') { return z; } if(o=='c') { return y; } if(o=='d') { return z; } } else if(m=='B') { if(o=='c') { return z; } if(o=='d') { return y; } if(n=='c') { return y; } if(n=='d') { return z; } } }
OUTPUT:


© 2018 - All rights reserved