0% found this document useful (0 votes)
43 views4 pages

Lab Assignment

The document contains 4 programming questions and their solutions in C language. Question 1 prompts the user for a number and checks if it is prime. Question 2 takes a number from 1-7 as input and prints the corresponding day of the week. Question 3 takes two numbers as input, asks the user for an operation, and performs the calculation. Question 4 takes 5 numbers as input and finds the largest and smallest among them.

Uploaded by

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

Lab Assignment

The document contains 4 programming questions and their solutions in C language. Question 1 prompts the user for a number and checks if it is prime. Question 2 takes a number from 1-7 as input and prints the corresponding day of the week. Question 3 takes two numbers as input, asks the user for an operation, and performs the calculation. Question 4 takes 5 numbers as input and finds the largest and smallest among them.

Uploaded by

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

Assignment

Question1

Write a C program which prompt a number from user and analyze entered number is prime or not?
Program:
#include<stdio.h>
int main()
{
int num,i,fact;
printf("Enter the Number:");
scanf("%d",&num);
for(i=2; i<num; i++)
if (num%i==0)
{
fact=0;
break;
}
else
fact=1;
if(fact)
printf("%d is prime\n",num);
else
printf("%d is NOT prime\n",num);
return 0;
}
Output:
Question 2
Using single if statement, write a C program which take input as number (starting from 1 to 7) and print day as per
number, considering 1 for Monday and 7 for Sunday

Program:
#include<stdio.h>
int main()
{
int day;
printf("Enter the Number:");
scanf("%d",&day);
if(day == 1) {
printf("Monday\n");
} else if(day == 2) {
printf("Tuesday\n");
} else if (day == 3) {
printf("Wednesday\n");
} else if(day == 4) {
printf("Thursday\n");
} else if(day == 5) {
printf("Friday\n");
} else if(day == 6) {
printf("Saturday\n");
} else {
printf("Sunday\n");
}

return 0;
}
Output:
Question3
Write a C program which take two numbers as input, then ask user for choice, 1 will be for addition, 2 Subtraction, 3
Multiplication, 4 Division

Program:
#include <stdio.h>
#include <conio.h>

int main()
{
int i;
int firstNumber, secondNumber;
int sum, difference, product;
float division;
printf("Enter First Number: ");
scanf("%d", &firstNumber);
printf("Enter Second Number: ");
scanf("%d", &secondNumber);
printf("Enter Operation: ");
scanf("%d", &i);
if(i==1){
sum=firstNumber+secondNumber;
printf("\nSum = %d", sum);}
else if(i==2)
{
difference=firstNumber-secondNumber;
printf("\ndifference = %d", difference);
}
else if(i==3)
{
product=firstNumber*secondNumber;
printf("\nproduct = %d", product);
}
else if(i==4)
{
division=firstNumber/secondNumber;
printf("\nDivision = %.3f", division);
}
return 0;

}
Output:
Question4
Write a C program which take 5 number as input and find smallest and largest among entries

Program:
#include<stdio.h>
int main()
{
int a[5],big,small,i;
printf("Enter the FIVE integers:\n");
for(i=0;i<5;i++)
scanf("%d",&a[i]);
big = a[0];
for(i=0;i<5;i++)
{
if(big<a[i])
big=a[i];
}
printf("The Largest Number is : %d",big);
small = a[0];
for(i=0;i<5;i++)
{
if(small>a[i])
small=a[i];
}
printf("\nThe Smallest Number is : %d",small);
return 0;

}
Output:

You might also like