0% found this document useful (0 votes)
11 views3 pages

Lap 3

The document contains six exercises in C programming. Exercise 1 checks if a character is a number, uppercase letter, or lowercase letter; Exercise 2 prints numbers from 99 to 1; Exercise 3 prints numbers from 1 to 100, skipping 50; Exercise 4 prints numbers from 1 to 100 that are multiples of 3, excluding 30, 60, and 90; Exercise 5 finds the maximum and minimum of five user-input numbers; and Exercise 6 sums user-input numbers until zero is entered.

Uploaded by

phanhacambodia22
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views3 pages

Lap 3

The document contains six exercises in C programming. Exercise 1 checks if a character is a number, uppercase letter, or lowercase letter; Exercise 2 prints numbers from 99 to 1; Exercise 3 prints numbers from 1 to 100, skipping 50; Exercise 4 prints numbers from 1 to 100 that are multiples of 3, excluding 30, 60, and 90; Exercise 5 finds the maximum and minimum of five user-input numbers; and Exercise 6 sums user-input numbers until zero is entered.

Uploaded by

phanhacambodia22
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

Lap3:

Exercise1:

#include <stdio.h>

int main() {
char inputchar;
printf("Enter a character: ");
scanf(" %c", &inputchar);

if (inputchar >= '0' && inputchar <= '9') {


printf("You entered a number.\n");
} else if (inputchar >= 'A' && inputchar <= 'Z') {
printf("You entered an uppercase letter.\n");
} else if (inputchar >= 'a' && inputchar <= 'z') {
printf("You entered a lowercase letter.\n"); // Corrected line!
} else {
printf("This is not a number or letter.\n");
}

return 0;
}

Exercise2:

#include <stdio.h>

int main() {
int num = 99;
while( num >= 1) {
printf("%d\n", num);
num--;
}
printf("\n");
return 0;
}

Exercise3:

#include <stdio.h>

int main() {
int num = 1;
while(num >= 1 && num <= 100) {
if (num == 50) {
printf("");
} else {
printf("%d\n", num);
}
num++;
}
return 0;
}

Exercise3:

#include <stdio.h>
int main() {
int num = 8;
while(num <= 1000) {
if (num % 2 != 0 && num != 11&& num !=17 && num != 21) {
printf("%d\n", num);
}
num++;
}
return 0;
}

Exercise4:

#include <stdio.h>

int main() {
int num = 1;
while(num <= 100) {
if (num % 3 == 0 && num != 30&& num !=60 && num != 90) {
printf("%d\n", num);
}
num++;
}
return 0;
}

Exercise5:

#include <stdio.h>
int main() {
int numbers[5];
printf("Enter 5 numbers:\n");
for (int i = 0; i < 5; i++) {
scanf("%d", &numbers[i]);
}
int max = numbers[0];
for (int i = 1; i < 5; i++) {
if (numbers[i] > max) {
max = numbers[i];
}
}
printf("The maximum number is: %d\n", max);
int min = numbers[0];
for (int i = 1; i < 5; i++) {
if (numbers[i] < min) {
min = numbers[i];
}
}
printf("The minimum number is: %d\n", min);
return 0;
}

Exercise6:

#include <stdio.h>
int main() {
int number;
int total = 0; // Start with zero

printf("Type numbers, 0 to stop:\n");

scanf("%d", &number); // Get the first number

while (number != 0) { // Keep going until we see a zero


total = total + number; // Add to the total
scanf("%d", &number); // Get the next number
}

printf("The total is: %d\n", total); // Show the total

return 0;
}

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy