CP lab-week 3
CP lab-week 3
h>
#include <stdio.h>
int main()
scanf("%d", &number);
squareRoot = sqrt(number);
return 0;
void main()
{
// Variable declaration
int a,b,larg;
printf("Enter two number\n");
scanf("%d %d", &a,&b);
}
3. C Program to take 5 subject marks in integer and find the total, average and
percentage in float?
#include <stdio.h>
int main()
{
int eng, phy, chem, math, comp;
float total, average;
/* Input marks of all five subjects */
printf("Enter marks of five subjects: \n");
scanf("%d%d%d%d%d",&eng,&phy,&chem,&math,&comp);
/* Calculate total, average and percentage */
total = eng + phy + chem + math + comp;
average = total / 5.0;
/* Print all results */
printf("Total marks=%f\n", total);
printf("Average marks=%f\n", average);
return 0;
}
}
else if(num2>num3&&num2>num4)
{
printf("number 2 is greatest:%d",num2);
else if(num3>num4)
{
printf("number 3 is greatest:%d",num3);
}
else
{
printf("number 4 is greatest:%d",num4);
}
}
6. C program to find the largest number among three numbers?
#include <stdio.h>
int main()
{
int a,b,c;
printf("enter three numbers");
scanf("%d%d%d",&a,&b,&c);
if(a>b && a>c)
{
printf("a is largest:%d",a);
}
else if(b>a && b>c)
{
printf(" b is largest:%d",b);
}
else
{
printf(" c is largest:%d",c);
}
}
7. C program to find the smallest number among three numbers?
#include <stdio.h>
int main()
{
int a,b,c;
printf("enter three numbers");
scanf("%d%d%d",&a,&b,&c);
if(a<b && a<c)
{
printf("a is smallest:%d",a);
}
else if(b<a && b<c)
{
printf(" b is smallest:%d",b);
}
else
{
printf(" c smallest:%d",c);
}
}
8. C Program to find the smallest number among four numbers?
#include <stdio.h>
int main()
{
int a,b,c,d;
printf("enter three numbers");
scanf("%d%d%d%d",&a,&b,&c,&d);
if(a<b && a<c && a<d)
{
printf("a is smallest:%d",a);
}
else if(b<c && b<d)
{
printf("b is smallest:%d",b);
}
else if(c<d)
{
printf("c smallest:%d",c);
}
else
{
printf("d is smallest:%d",d);
}
}
9.
#include<stdio.h>
int main()
{
int a, b;
char choice;
printf("Enter your choice\n");
printf("a. Addition\nb. Subtraction\nc. Multiplication\nd. Division\n");
scanf("%c", &choice);
printf("Enter 2 integer numbers\n");
scanf("%d %d", &a, &b);
switch(choice)
{
case 'a': printf("addition=%d",(a+b));
break;
return 0;
}
#include <stdio.h>
int main()
{
int day;
printf("enter the day\n");
scanf("%d",&day);
switch(day)
{
case 1:
printf("Monday");
break;
case 2:
printf("Tuesday");
break;
case 3:
printf("Wednesday");
break;
case 4:
printf("Thursday");
break;
case 5:
printf("Thursday");
break;
case 6:
printf("Thursday");
break;
case 7:
printf("Thursday");
break;
default:
printf("Invalid Input");
break;
}
}