-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
27 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |