diff --git a/lab1_q2 b/lab1_q2 new file mode 100644 index 0000000..d1bcb95 --- /dev/null +++ b/lab1_q2 @@ -0,0 +1,27 @@ +/*Write a program which reads n integers from the standard input (i.e., keyboard), and prints the smallest number. Prompt the user first to input the value of n, which has to be positive. Check if the COMPENG 2SH4Principlesof ProgrammingLAB 1(Sept. 16–27)Instructor: Mohamed HassanFall 2019 +input is valid and in case it is not,keep asking the user for a correct input. Then prompt the user to input each number*/ + + +#include +#include +int main() +{ /* program is made so that it outputs the smallest integer from a list of n integers */ + int i,x,integer1,integer2; + printf("program will output smallest integer from a list of n integers. Now enter n, this MUST be positive\n"); + scanf("%d",&x); + while(x<=0){ //if input is not a positive inetger, this loop will continously run, to help make sure a postive n value is given + printf("Program will output smallest integer from a list of n integers. YOU MUST ENTER A positive integer n\n"); + scanf("%d",&x);} + + printf("Enter an integer\n"); // prompts user to enter an integer, this will be integer1 + scanf("%d",&integer1); + + for(i=0;i<(x-1);i++){ //for loop that goes from 0 to one less n because the user was already asked for an integer once. + printf("Enter an integer\n"); + scanf("%d",&integer2); + if(integer2<=integer1) { // if integer 2 less than integer 1 set inetger 1 equivaelent to integer 2 + integer1 = integer2;} + } +printf("%d",integer1); +return 0; +}