Using C Practice using loops as you have been learning in cl
Using C, \"Practice using loops, as you have been learning in class. Also, ensure that you use functions and boolean-logic operators.\"
This is a pretty easy homework assignment but it just needs to be a program with defined funfuctions that includes boolean-logic operators as well as loops it can output anything there are no guidelines.
Solution
#include <stdio.h>
/*fun function declaration*/
void fun();
/*Main function start*/
int main() {
/*calling fun function*/
fun();
return 0;
}
/*main function end*/
/*fun function definitation*/
void fun(){
/*variable declaration*/
int x = 10;
int y = 20;
int i;
/*Both must be true for && operator*/
if ( x && y ) {
printf(\"Line 1 - Condition is true\ \" );
}
/*Any one of is true*/
if ( x || y ) {
printf(\"Line 2 - Condition is true\ \" );
}
if ( !x ) {
printf(\"Line 4 - Condition is true\ \" );
}else{
printf(\"Line 5 - Condition is true\ \" );
}
/*for loop for printing number 5 times*/
printf(\"------------------for loop output start ----------------\ \");
for(i=0;i<5;i++){
printf(\"%d \",(i+1));
}
printf(\"\ \");
printf(\"------------------for loop output end ----------------\ \");
/*while loop*/
printf(\"------------------While loop output start ----------------\ \");
while(i>=0){
printf(\"%d \",(i+1));
i--;
}
printf(\"\ \");
printf(\"------------------While loop output End ----------------\ \");
}
/**********************************output**************************/
Line 1 - Condition is true
Line 2 - Condition is true
Line 5 - Condition is true
------------------for loop output start ----------------
1 2 3 4 5
------------------for loop output end ----------------
------------------While loop output start ----------------
6 5 4 3 2 1
------------------While loop output End ----------------
Thanks a lot

