-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlab1_q2
More file actions
27 lines (23 loc) · 1.45 KB
/
lab1_q2
File metadata and controls
27 lines (23 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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;
}