Skip to content

Commit

Permalink
Create lab1_q2
Browse files Browse the repository at this point in the history
  • Loading branch information
ZanButt authored Jan 9, 2021
1 parent be83073 commit 2aafe9d
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions lab1_q2
Original file line number Diff line number Diff line change
@@ -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 <stdio.h>
#include <stdlib.h>
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;
}

0 comments on commit 2aafe9d

Please sign in to comment.