[go: up one dir, main page]

0% found this document useful (0 votes)
8 views28 pages

C Assignment

The document is a laboratory assignment for C programming for MCA first-year students at Shri G.S. Institute of Technology & Science. It includes a list of 21 programming tasks, each requiring the student to write a C program to solve various problems such as finding maximum numbers, checking for leap years, and calculating grades. The assignment is structured with an index and provides sample programs and outputs for several tasks.

Uploaded by

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

C Assignment

The document is a laboratory assignment for C programming for MCA first-year students at Shri G.S. Institute of Technology & Science. It includes a list of 21 programming tasks, each requiring the student to write a C program to solve various problems such as finding maximum numbers, checking for leap years, and calculating grades. The assignment is structured with an index and provides sample programs and outputs for several tasks.

Uploaded by

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

Shri G.S.

Institute of Technology & Science


(An Autonomous Institute, Established in 1952)

LABORATORY ASSIGNMENT
CT10452: C PROGRAMMING

2024-2026
MCA I YEAR
Semester – I

Department of Information Technology

SUBMITTED TO: SUBMITTED BY:


Mr. Deepesh Agrawal Shruti Gupta
Ms. Megha Rathore
C PROGRAMMING ASSIGNMENT 1

INDEX
S. No Questions Page No. Remarks

1. Write a C program to find maximum between two numbers. 3

2. Write a C program to find maximum between three numbers. 4

3. Write a C program to check whether a number is negative, positive or 5


zero.
4. Write a C program to check whether a number is divisible by 5 and 11 6
or not.

5. Write a C program to check whether a number is even or odd. 7

6. Write a C program to check whether a year is leap year or not. 8

7. Write a C program to check whether a character is alphabet or not. 9

8. Write a C program to input any alphabet and check whether it is vowel 10


or consonant.
9. Write a C program to input any character and check whether it is 11
alphabet, digit or special character.

10. Write a C program to check whether a character is uppercase or 12


lowercase alphabet.
11. Write a C program to input week number and print week day. 13

12. Write a C program to input month number and print number of days 14
in that month.

13. Write a C program to count total number of notes in given amount. 15

14. Write a C program to input angles of a triangle and check whether 17


triangle is valid or not.
15. Write a C program to input all sides of a triangle and check whether 18
triangle is valid or not.

16. Write a C program to check whether the triangle is equilateral, 19


isosceles or scalene triangle.
17. Write a C program to find all roots of a quadratic equation. 20

18. Write a C program to calculate profit or loss. 21

1
C PROGRAMMING ASSIGNMENT 1

19. Write a C program to input marks of five subjects Physics, Chemistry, 22


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
20. Write a C program to input basic salary of an employee and calculate 24
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%
21. Write a C program to input electricity unit charges and calculate total 25
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

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");

printf("Enter any character : ");

scanf("%c",&chr);

if((chr>='a'&&chr<='z')||(chr>='A'&&chr<='Z')){

printf("%c is a alphabet",chr);

}else{

printf("%c is not a alphabet",chr);

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");

printf("Enter three coefficients : ");

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{

printf("Roots are not possible for this equation");

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() {

float phy, chem, bio, math, comp, total, per;

char grade;

clrscr();

printf("Shruti Gupta\n");

printf("Enter marks for Physics: ");

scanf("%f", &phy);

printf("Enter marks for Chemistry: ");

scanf("%f", &chem);

printf("Enter marks for Biology: ");

scanf("%f", &bio);

printf("Enter marks for Mathematics: ");

scanf("%f", &math);

printf("Enter marks for Computer: ");

scanf("%f", &comp);

total = phy + chem+ bio + math + comp;


22
C PROGRAMMING ASSIGNMENT 1

per = (total / 500) * 100;

if (per >= 90) {

grade = 'A';

} else if (per >= 80) {

grade = 'B';

} else if (per >= 70) {

grade = 'C';

} else if (per >= 60) {

grade = 'D';

} else if (per >= 40) {

grade = 'E';

} else {

grade = 'F';

printf("Total Marks: %f", total);

printf("Percentage: %f\n", per);

printf("Grade: %c\n", grade);

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(){

float units, bill, extra;

clrscr();

printf("Shruti Gupta\n");

printf("Enter electricity units consumed: ");

scanf("%f", &units);

if (units <= 50) {

bill = units * 0.50;

} else if (units <= 150) {

bill = (50 * 0.50) + ((units - 50) * 0.75);

} else if (units <= 250) {

bill = (50 * 0.50) + (100 * 0.75) + ((units - 150) * 1.20);

25
C PROGRAMMING ASSIGNMENT 1

} else {

bill = (50 * 0.50) + (100 * 0.75) + (100 * 1.20) + ((units - 250) * 1.50);

extra = 0.20 * bill;

bill = bill+extra;

printf("Total electricity bill = %f\n", bill);

getch();

return 0;

Output:

26
C PROGRAMMING ASSIGNMENT 1

27

You might also like