0% found this document useful (0 votes)
12 views

Lab Task C Programs

Uploaded by

hadirehman488
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views

Lab Task C Programs

Uploaded by

hadirehman488
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

NAME HAIDER REHMAN

REG NO Fa22-bse-064

ict lab task

Exercise for Lab:

1. Prompt the user to input 5 values and display the minimum number amongst them.

program:

#include<stdio.h>

int main()

int n1, n2, n3, n4, n5;

printf("enter 5 numbers to find minimum between them\n");

printf("enter 1st number\n");

scanf("%d", &n1);

printf("enter second number\n");

scanf("%d", &n2);

printf("enter 3rd number\n");

scanf("%d", &n3);

printf("enter 4th number\n");

scanf("%d", &n4);

printf("enter 5th number\n");

scanf("%d", &n5);

if(n1< n2 && n1< n3 && n1<n4 && n1<n5){

printf("%d is the smallest\n",n1);

}
else if(n2< n1 && n2< n3 && n2<n4 && n2<n5){

printf("%d is the smallest\n",n2);

else if(n3< n1 && n3< n2 && n3<n4 && n4<n5){

printf("%d is the smallest\n",n3);

else if(n4< n1 && n4< n2 && n4<n3 && n4<n5){

printf("%d is the smallest\n",n4);

else if(n5< n1 && n5< n2 && n5<n3 && n5<n4){

printf("%d is the smallest\n",n5);

return 0;

2. Input 5 values from the user and display the number of positives, the number of negatives and the
number of zeros amongst the 5 values

program:

#include<stdio.h>

int main()

int n1, n2, n3, n4, n5;

printf("enter 5 numbers to find positive and negative and zeros\n");

printf("enter 1st number\n");

scanf("%d", &n1);

printf("enter second number\n");


scanf("%d", &n2);

printf("enter 3rd number\n");

scanf("%d", &n3);

printf("enter 4th number\n");

scanf("%d", &n4);

printf("enter 5th number\n");

scanf("%d", &n5);

int positiveCount = (n1 > 0) + (n2 > 0) + (n3 > 0) + (n4 > 0) + (n5 > 0);

int negativeCount = (n1 < 0) + (n2 < 0) + (n3 < 0) + (n4 < 0) + (n5 < 0);

int zeroCount = (n1 == 0) + (n2 == 0) + (n3 == 0) + (n4 == 0) + (n5 == 0);

printf("Number of positives: %d\n", positiveCount);

printf("Number of negatives: %d\n", negativeCount);

printf("Number of zeros: %d\n", zeroCount);

return 0;

3. Prompt the user to input a character and display whether it is a vowel or consonant using switch
statement.

program:

#include<stdio.h>

int main()

char ch;

printf("enter a character\n");

scanf("%c", &ch);

switch(ch){
case 'a':

case 'A':

case 'e':

case 'E':

case 'i':

case 'I':

case 'o':

case 'O':

case 'u':

case 'U':

printf("the given character is a wovel\n");

break;

default :

printf("the given character is a consonent\n");

return 0;

Home Task

1. Ask the user to enter marks obtained in a course and the total marks of the course. Then display a
menu Press 1 to calculate percentage. Press 2 to display grade. If the user presses 1 then percentage
should be displayed and if the user presses 2 the grade against the marks should be displayed. (Hint: use
switch statement for menu selection and else if to display the grade)

program:

#include<stdio.h>

int main()
{

int a;

float obtmark;

float totmark;

float per;

printf("enter marks obtained in a course\n");

scanf("%f", &obtmark);

printf("%f\n", obtmark);

printf("enter total marks in a course\n");

scanf("%f", &totmark);

printf("%f\n", totmark);

printf("enter 1 for calculate percentage\n");

printf("enter 2 for display grade\n");

scanf("%d", &a);

switch(a){

case 1:

per = obtmark/totmark*100.0;

printf("percentage is %.2f",per);

break;

case 2:

per = obtmark/totmark*100.0;

if(per>= 80){

printf("grade is A\n");

else if(per>= 70 && per<= 80){


printf("grade is B\n");

else if(per>= 60 && per<= 70){

printf("grade is C\n");

else if(per>= 50 && per<= 60){

printf("grade is D\n");

else {

printf("F\n");

break;

default:

printf("you entered invalid choice");

return 0;

2. Prompt the user to enter 3 values. For any equal values, the program should display the numbers
that are equal. (For example user input 34,6,34 the program should display the message that the 1st and
3rd values are equal)

program:

#include <stdio.h>

int main() {

// Input 3 values from the user

int value1, value2, value3;


printf("Enter the first value: ");

scanf("%d", &value1);

printf("Enter the second value: ");

scanf("%d", &value2);

printf("Enter the third value: ");

scanf("%d", &value3);

// Check for equality and display the message

if (value1 == value2 && value2 == value3) {

printf("All three values are equal: %d\n", value1);

} else if (value1 == value2) {

printf("The first and second values are equal: %d\n", value1);

} else if (value1 == value3) {

printf("The first and third values are equal: %d\n", value1);

} else if (value2 == value3) {

printf("The second and third values are equal: %d\n", value2);

} else {

printf("No two values are equal.\n");

return 0;

You might also like