C Assignment
C Assignment
LABORATORY ASSIGNMENT
CT10452: C PROGRAMMING
2024-2026
MCA I YEAR
Semester – I
INDEX
S. No Questions Page No. Remarks
12. Write a C program to input month number and print number of days 14
in that month.
1
C PROGRAMMING ASSIGNMENT 1
2
C PROGRAMMING ASSIGNMENT 1
Question No.1
Write a C program to find maximum between two numbers.
Program:
#include<stdio.h>
int main(){
int num1,num2;
printf(" Shruti Gupta\n");
printf("enter the first number");
scanf("%d",&num1);
printf("enter the second number");
scanf("%d",&num2);
if(num1>num2){
printf("the maximum of two number is %d",num1);
}
else if(num1==num2){
printf("both are equal");
}
else{
printf("the maximum of two number is %d",num2);
}
}
Output:
3
C PROGRAMMING ASSIGNMENT 1
Question No. 2
Write a C program to find maximum between three numbers.
Program:
#include<stdio.h>
#include<conio.h>
int main() {
clrscr();
int num1,num2,num3;
printf(" Shruti Gupta \n");
printf("enter the 1st ,2nd and 3rd number respectively");
scanf("%d%d%d",&num1,&num2,&num3);
if(num1>num2) {
if(num1>num3){
printf("the maximum of three number is %d",num1);
}else{
printf("the maximum of three number is %d",num3);
}}
else {
if(num2>num3){
printf("the maximum of three number is %d",num2);
}else{
printf("the maximum of three number is %d",num3);
}}
getch();
}
Output:
4
C PROGRAMMING ASSIGNMENT 1
Question No.3
Write a C program to check whether a number is negative, positive or zero.
Program:
#include<stdio.h>
#include<conio.h>
int main(){
int num;
clrscr();
printf("Shruti Gupta\n");
printf("Enter any number : ");
scanf("%d",&num);
if(num>0){
printf("Number is positive");
}
else if(num<0){
printf("Number is negative");
}
else{
printf("Number is zero");
}
getch();
return 0;
}
Output:
5
C PROGRAMMING ASSIGNMENT 1
Question No. 4
Write a C program to check whether a number is divisible by 5 and 11 or not.
Program:
#include<stdio.h>
#include<conio.h>
int main(){
int no;
clrscr();
printf("Shruti Gupta \n");
printf("Enter any number : ");
scanf("%d",&no);
if(no%5==0&&no%11==0){
printf("Number is divisible by 5 and 11");
}else if(no%5==0){
printf("Number is divisible by 5");
}else if(no%11==0){
printf("Number is divisible by 11");
}else{
printf("Number is not divisible by 5 and 11");
}
getch();
return 0;
}
Output:
6
C PROGRAMMING ASSIGNMENT 1
Question No. 5
Write a C program to check whether a number is even or odd.
Program:
#include<stdio.h>
#include<conio.h>
int main(){
int num;
clrscr();
printf("Shruti Gupta \n");
printf("Enter any number : ");
scanf("%d",&num);
if(num%2==0){
printf("Number is even");
}
else{
printf("Number is odd");
}
getch();
return 0;
}
Output:
7
C PROGRAMMING ASSIGNMENT 1
Question No. 6
Write a C program to check whether a year is leap year or not.
Program:
#include<stdio.h>
#include<conio.h>
int main(){
int year;
clrscr();
printf("Shruti Gupta\n");
printf("Enter any year : ");
scanf("%d",&year);
if((year%4==0&&year%100!=0)||(year%400==0)){
printf("%d is a leap year",year);
}else{
printf("%d is not a leap year",year);
}getch();
return 0;
}
Output:
8
C PROGRAMMING ASSIGNMENT 1
Question No. 7
Write a C program to check whether a character is alphabet or not.
Program:
#include<stdio.h>
#include<conio.h>
int main(){
char chr;
clrscr();
printf("Shruti Gupta\n");
scanf("%c",&chr);
if((chr>='a'&&chr<='z')||(chr>='A'&&chr<='Z')){
printf("%c is a alphabet",chr);
}else{
getch();
return 0;
Output:
9
C PROGRAMMING ASSIGNMENT 1
Question No. 8
Write a C program to input any alphabet and check whether it is vowel or consonant.
Program:
#include<stdio.h>
#include<conio.h>
int main(){
char chr;
clrscr();
printf("Shruti Gupta \n");
printf("Enter any character : ");
scanf("%c",&chr);
if(chr=='a','e','i','o','u','A','E','I','O','U'){
printf("Character is vowel");
}else{
printf("Character is consonent");
}
getch();
return 0;
}
Output:
10
C PROGRAMMING ASSIGNMENT 1
Question No. 9
Write a C program to input any character and check whether it is alphabet, digit or special
character.
Program:
#include<stdio.h>
#include<conio.h>
int main(){
char ch;
clrscr();
printf("NAMAN BHAWSAR\n\n");
printf("Enter any character : ");
scanf("%c",&ch);
if((ch>='a'&&ch<='z')||(ch>='A'&&ch<='Z')){
printf("Character is alphabet");
}else if(ch>='0'&&ch<='9'){
printf("Character is digit");
}else{
printf("Character is a special symbol");
}
getch();
return 0;
}
Output:
11
C PROGRAMMING ASSIGNMENT 1
Question No. 10
Write a C program to check whether a character is uppercase or lowercase alphabet.
Program:
#include<stdio.h>
#include<conio.h>
int main(){
char chr;
clrscr();
printf("Shruti Gupta\n");
printf("Enter any character : ");
scanf("%c",&chr);
if(chr>='a'&&chr<='z'){
printf("Character is lower case");
}else if(chr>='A'&&chr<='Z'){
printf("Character is upper case");
}else{
printf("Invalid Character");
}
getch();
return 0;
}
Output:
12
C PROGRAMMING ASSIGNMENT 1
Question No. 11
Write a C program to input week number and print week day.
Program:
#include<stdio.h>
#include<conio.h>
int main(){
char week;
clrscr();
printf("Shruti Gupta\n");
printf("enter week day number from 1 to 7");
scanf("%d",&week);
switch(week){
case 1:
printf("Monday");
break;
case 2:
printf("Tuesday");
break;
case 3:
printf("Wednesday");
break;
case 4:
printf("Thursday");
break;
case 5:
printf("Friday");
break;
case 6:
printf("Saturday");
break;
13
C PROGRAMMING ASSIGNMENT 1
case 7:
printf("Sunday");
break;
default :
printf("invalid input");
break;
}
}
Output:
Question No. 12
Write a C program to input month number and print number of days in that month.
Program:
#include<stdio.h>
#include<conio.h>
int main(){
char month;
clrscr();
printf("Shruti Gupta\n");
printf("enter month's number (1 to 12)");
scanf("%d",&month);
switch(month){
case 1: case 3: case 5: case 7: case 8: case 10: case 12:
printf("number of days in month is 31");
break;
case 4: case 6: case 9: case 11:
printf("number of days in month is 30");
14
C PROGRAMMING ASSIGNMENT 1
break;
case 2:
printf("number of days in month is 29");
break;
default:
printf("invalid input");
}
}
Output:
Question No. 13
Write a C program to count total number of notes in given amount.
Program:
#include<stdio.h>
#include<conio.h>
int main(){
int amt;
clrscr();
printf("Shruti Gupta\n");
printf("Enter the amount : ");
scanf("%d",&amt);
int n500,n200,n100,n50,n20,n10;
n500 = amt/500;
amt = amt%500;
n200 = amt/200;
amt = amt%200;
n100 = amt/100;
15
C PROGRAMMING ASSIGNMENT 1
amt = amt%100;
n50 = amt/50;
amt = amt%50;
n20 = amt/20;
amt = amt%20;
n10 = amt/10;
amt = amt%10;
printf("Rs. 500 Notes : %d\n",n500);
printf("Rs. 200 Notes : %d\n",n200);
printf("Rs. 100 Notes : %d\n",n100);
printf("Rs. 50 Notes : %d\n",n50);
printf("Rs. 20 Notes : %d\n",n20);
printf("Rs. 10 Notes : %d\n",n10);
printf("and Rs. 1 coins of %d",amt);
getch();
return 0;
Output:
16
C PROGRAMMING ASSIGNMENT 1
Question No. 14
Write a C program to input angles of a triangle and check whether triangle is valid or not.
Program:
#include<stdio.h>
#include<conio.h>
int main(){
int ang1,ang2,ang3,sum_Ang;
clrscr();
printf("Shruti Gupta\n");
printf("Enter three angles of triangle : ");
scanf("%d%d%d",&ang1,&ang2,&ang3);
sum_Ang = ang1+ang2+ang3;
if(sum_Ang==180&&ang1>0&&ang2>0&&ang3>0){
printf("It is a valid triangle ");
}else{
printf("Triiangle angles are not valid.Pease enter valid angles of triangle ");
}
getch();
return 0;
Output:
17
C PROGRAMMING ASSIGNMENT 1
Question No. 15
Write a C program to input all sides of a triangle and check whether triangle is valid or
not.
Program:
#include<stdio.h>
#include<conio.h>
int main(){
int side1,side2,side3;
clrscr();
printf("Shruti Gupta \n");
printf("Enter three sides of triangle : ");
scanf("%d%d%d",&side1,&side2,&side3);
if((side1+side2>side3)&&(side1+side3>side2)&&(side2+side3>side1)){
printf("It is a valid Triangle :)");
}else{
printf("It is not a valid triangle please enter valid se sides");
}
getch();
return 0;
Output:
18
C PROGRAMMING ASSIGNMENT 1
Question No. 16
Write a C program to check whether the triangle is equilateral, isosceles or scalene
triangle.
Program:
#include<stdio.h>
#include<conio.h>
int main(){
int side1,side2,side3;
clrscr();
printf("Shruti Gupta \n");
printf("Enter three sides of triangle : ");
scanf("%d%d%d",&side1,&side2,&side3);
if(side1==side2&&side2==side3){
printf("Triangle is equilateral triangle");
}else if(side1==side2|| side1==side3||side2==side3){
printf("Triangle is isosceles triangle");
}else{
printf("Triangle is scalene triangle");
}
getch();
return 0;
}
Output:
19
C PROGRAMMING ASSIGNMENT 1
Question No. 17
Write a C program to find all roots of a quadratic equation.
Program:
#include<stdio.h>
#include<conio.h>
int main(){
int a,b,c,root1,root2,D;
clrscr();
printf("Shruti Gupta\n");
scanf("%d%d%d",&a,&b,&c);
D=(b*b)-(4*a*c);
if(D>=0){
root1 = (-b+(D*D))/2*a;
root2 = (-b-(D*D))/2*a;
printf("root1 : %d\n",root1);
printf("root2 : %d",root2);
}else{
getch();
return 0;
Output:
20
C PROGRAMMING ASSIGNMENT 1
Question No. 18
Write a C program to calculate profit or loss.
Program:
#include<stdio.h>
#include<conio.h>
int main(){
int cp,sp,profit,loss;
clrscr();
printf("Shruti Gupta\n");
printf("Enter cost price : ");
scanf("%d",&cp);
printf("Enter selling price: ");
scanf("%d",&sp);
if(sp>cp){
profit = sp-cp;
printf("profit is %d",profit);
}
else if(cp>sp){
loss = cp-sp;
printf("loss is %d ",loss);
}
else{
printf("neither loss nor profit happen");
}
}
Output:
21
C PROGRAMMING ASSIGNMENT 1
Question No. 19
Write a C program to input marks of five subjects Physics, Chemistry, Biology, Mathematics and
Computer. Calculate percentage and grade according to following:
Percentage >= 90%: Grade A
Percentage >= 80%: Grade B
Percentage >= 70%: Grade C
Percentage >= 60%: Grade D
Percentage >= 40%: Grade E
Percentage < 40%: Grade F
Program:
#include<stdio.h>
#include<conio.h>
int main() {
char grade;
clrscr();
printf("Shruti Gupta\n");
scanf("%f", &phy);
scanf("%f", &chem);
scanf("%f", &bio);
scanf("%f", &math);
scanf("%f", &comp);
grade = 'A';
grade = 'B';
grade = 'C';
grade = 'D';
grade = 'E';
} else {
grade = 'F';
getch();
return 0;
Output:
23
C PROGRAMMING ASSIGNMENT 1
Question No. 20
Write a C program to input basic salary of an employee and calculate its Gross salary according to
following:
Basic Salary <= 10000: HRA = 20%, DA = 80%
Basic Salary <= 20000: HRA = 25%, DA = 90%
Basic Salary > 20000: HRA = 30%, DA = 95%
Program:
#include<stdio.h>
#include<conio.h>
int main() {
float bs, hra, da, gs;
clrscr();
printf("Shruti Gupta\n");
printf("Enter basic salary: ");
scanf("%f", &bs);
if (bs <= 10000) {
hra = 0.20 * bs;
da = 0.80 * bs;
} else if (bs <= 20000) {
hra = 0.25 * bs;
da = 0.90 * bs;
} else {
hra = 0.30 * bs;
da = 0.95 * bs;
}
gs = bs + hra + da;
printf("Gross salary = %f\n", gs);
getch();
return 0;
}
24
C PROGRAMMING ASSIGNMENT 1
Output:
Question No. 21
Write a C program to input electricity unit charges and calculate total electricity bill according to
the given condition:
For first 50 units Rs. 0.50/unit
For next 100 units Rs. 0.75/unit
For next 100 units Rs. 1.20/unit
For unit above 250 Rs. 1.50/unit
An additional surcharge of 20% is added to the bill
Program:
#include<stdio.h>
#include<conio.h>
int main(){
clrscr();
printf("Shruti Gupta\n");
scanf("%f", &units);
25
C PROGRAMMING ASSIGNMENT 1
} else {
bill = (50 * 0.50) + (100 * 0.75) + (100 * 1.20) + ((units - 250) * 1.50);
bill = bill+extra;
getch();
return 0;
Output:
26
C PROGRAMMING ASSIGNMENT 1
27