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

Project Co

Uploaded by

K.S. gaming
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)
28 views28 pages

Project Co

Uploaded by

K.S. gaming
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

EXPERIMENT-1 (Basic Programs)

1. Implement C program which demonstrates working of increment


(++) and decrement(--) operators. Increment operator adds 1 to
its operand and Decrement operator subtracts 1 from its
operand.

#include <stdio.h>
int main()
{
// increment operator ++i
int i, j, increment, decrement;
printf("enter a number: ");
scanf("%d", &i);
increment = ++i;
printf("increment = %d\n", increment);
// decrement operator --j
printf("enter a number: ");
scanf("%d", &j);
decrement = --j;
printf("decrement = %d", decrement);
return 0;
}
OUTPUT:
2. Implement C program to calculate area of a circle, given
the radius.

#include <stdio.h>
int main()
{
// area of circle = 3.14*radius*radius
float radius;
printf("enter radius: ");
scanf("%f", &radius);
printf("area of the circle is: %f", 3.14 * radius * radius);
return 0;
}

OUTPUT:
3. Implement C program to calculate the surface area,
volume of a Sphere.

#include <stdio.h>
int main()
{
// surface area of sphere = 4*3.14*radius*radius
float radius;
printf("enter the value of radius: ");
scanf("%f", &radius);
printf("surface area of sphere: %f\n\n", 4.0 * 3.14 * radius * radius);
// volume of sphere = (4/3)*3.14*r*r*r
float r;
printf("enter the value of r: ");
scanf("%f", &r);
printf("volume of sphere: %f\n\n", (4.0 / 3.0) * 3.14 * r * r * r);
return 0;
}

OUTPUT:
4. Implement C program to find subtraction of two integer
numbers.

#include <stdio.h>
int main()
{
// subtraction of two integers
int i, j;
printf("enter value of i: ");
scanf("%d", &i);
printf("enter value of j: ");
scanf("%d", &j);
printf("The difference is: %d", i - j);
return 0;
}
OUTPUT:
5. Implement C program to find area of a rectangle.

#include <stdio.h>
int main()
{
// area of rectangle = length*breadth
float length, breadth;
printf("enter value of length: ");
scanf("%f", &length);
printf("enter value of breadth: ");
scanf("%f", &breadth);
printf("area of rectangle: %f", length * breadth);
return 0;
}
OUTPUT:
6. Implement C program to find quotient and remainder.

#include <stdio.h>
int main()
{
// program to compute quotient and remainder
int dividend, divisor;
printf("enter the dividend: ");
scanf("%d", &dividend);
printf("enter the divisor: ");
scanf("%d", &divisor);
printf("the quotient is: %d\n", dividend / divisor);
printf("the remainder is: %d", dividend % divisor);
return 0;
}

OUTPUT:
EXPERIMENT-2 (Using if-else)
1. Implement C program to check whether number is EVEN or
ODD.
#include <stdio.h>
int main()
{
int n;
printf("enter a number: ");
scanf("%d", &n);
if (n % 2 == 0)
{
printf("%d is an even number", n);
}
else
{
printf("%d is an odd number", n);
}
return 0;
}
OUTPUT:
2. Implement C program to find largest number among three
numbers.
#include <stdio.h>
int main()
{
int num1, num2, num3;
printf("enter first number: ");
scanf("%d", &num1);
printf("enter second number: ");
scanf("%d", &num2);
printf("enter third number: ");
scanf("%d", &num3);
if (num1 > num2 && num1 > num3)
{
printf("%d is the largest", num1);
}
else if (num2 > num1 && num2 > num3)
{
printf("%d is the largest", num2);
}
else
{
printf("%d is the largest", num3);
}
return 0;
}
OUTPUT:
3. Implement C program to check whether a person is eligible
to vote or not?
#include <stdio.h>
int main()
{
int age;
printf("enter age: ");
scanf("%d", &age);
if (age >= 18)
{
printf("The person is eligible to vote");
}
else
{
printf("The person is not eligible to vote");
}
return 0;
}
OUTPUT:
4. Implement C program to read marks and print percentage
and division.
#include <stdio.h>
int main()
{
int total = 100, obtained;
printf("Enter your marks: ");
scanf("%d", &obtained);
if (obtained < 0 || obtained > 100)
{
printf("Enter valid marks");
return 1;
}
int percentage = obtained * 100 / total;
printf("Your percentage is: %d\n", percentage);
if (obtained == 100)
{
printf("Your division is: A++\n");
printf("You scored FULL MARKS!");
}
else if (obtained >= 90 && obtained < 100)
{
printf("Your division is: A+");
}
else if (obtained >= 80 && obtained < 90)
{
printf("Your division is: A");
}
else if (obtained >= 70 && obtained < 80)
{
printf("Your division is: B");
}
else if (obtained >= 60 && obtained < 70)
{
printf("Your division is: C");
}
else if (obtained >= 50 && obtained < 60)
{
printf("Your division is: D");
}
else if (obtained >= 40 && obtained < 50)
{
printf("Your division is: E");
}
else
{
printf("Your division is: F\n");
printf("You FAILED!");
}
return 0;
}
OUTPUT:
5. Implement C program to convert temperature form
Fahrenheit to Celsius and vice versa.
#include <stdio.h>
int main()
{
int choice;
float temperature, convertedTemperature;
printf("Temperature Conversion Menu:\n");
printf("1. Fahrenheit to Celsius\n");
printf("2. Celsius to Fahrenheit\n");
printf("Enter your choice (1 or 2): ");
scanf("%d", &choice);
if (choice == 1)
{
printf("Enter temperature in Fahrenheit: ");
scanf("%f", &temperature);
convertedTemperature = (temperature - 32) * 5 / 9;
printf("%.2f Fahrenheit is %.2f Celsius\n", temperature, convertedTemperature);
}
else if (choice == 2)
{
printf("Enter temperature in Celsius: ");
scanf("%f", &temperature);
convertedTemperature = (temperature * 9 / 5) + 32;
printf("%.2f Celsius is %.2f Fahrenheit\n", temperature, convertedTemperature);
}
else
{
printf("Invalid choice. Please enter 1 or 2.\n");
return 1;
}
return 0;
}
OUTPUT:
EXPERIMENT-3 (Using Switch Case)
1. Implement C program to read the grade of student print
equivalent description.
#include <stdio.h>
int main()
{
// program to read the grade of a student and print equivalent description
(using switch
case)
char grade;
printf("Enter your grade: ");
scanf("%c", &grade);
switch (grade)
{
case 'O':
printf("Your grade is %c\n", grade);
break;
case 'A':
printf("Your grade is %c\n", grade);
break;
case 'B':
printf("Your grade is %c\n", grade);
break;
case 'C':
printf("Your grade is %c\n", grade);
break;
case 'D':
printf("Your grade is %c\n", grade);
break;
case 'E':
printf("Your grade is %c\n", grade);
break;
case 'F':
printf("Your grade is %c\n", grade);
printf("You failed\n");
break;
default:
printf("Enter a valid grade");
break;
}
return 0;
}
OUTPUT:
2. Implement C program to read weekday number and print weekday
name.
#include <stdio.h>
int main()
{// program to read weekday number and print weekday name
char num;
printf("Enter a number from 1 to 7: ");
scanf("%c", &num);
switch (num)
{case '1':
printf("Today is Monday!\n");
break;
case '2':
printf("Today is Tuesday!\n");
break;
case '3':
printf("Today is Wednesday!\n");
break;
case '4':
printf("Today is Thursday!\n");
break;
case '5':
printf("Today is Friday!\n");
break;
case '6':
printf("Today is Saturday!\n");
break;
case '7':
printf("Today is Sunday!\n");
break;
default:
printf("There are only 7 days in a week!\n");
break;
}return 0;}
OUTPUT:
3. Implement C program to check whether a character is
VOWEL or CONSONANT.
#include <stdio.h>
int main()
{
char ch;
printf("Enter an english alphabet: ");
scanf("%c", &ch);
switch (ch)
{
case 'a':
printf("VOWEL");
break;
case 'e':
printf("VOWEL");
break;
case 'i':
printf("VOWEL");
break;
case 'o':
printf("VOWEL");
break;
case 'u':
printf("VOWEL");
break;
case 'A':
printf("VOWEL");
break;
case 'E':
printf("VOWEL");
break;
case 'I':
printf("VOWEL");
break;
case 'O':
printf("VOWEL");
break;
case 'U':
printf("VOWEL");
break;
default:
printf("CONSONANT");
break;
}
return 0;
}

P.T.O
OUTPUT :
4. Implement C program calculator with basic operations.
#include <stdio.h>
int main()
{
int num1, num2;
printf("Enter 1st number: ");
scanf("%d", &num1);
printf("Enter 2nd number: ");
scanf("%d", &num2);
char ch;
printf("Enter the initial of the operation (in capital) you want to perform: ");
scanf(" %c", &ch);
int multiplication = num1 * num2, division = num1 / num2, addition = num1 +
num2,
subtraction = num1 - num2;
switch (ch)
{
case 'A':
printf("The sum of the numbers is: %d", addition);
break;
case 'S':
printf("The difference of the numbers is: %d", subtraction);
break;
case 'M':
printf("The product of the numbers is: %d", multiplication);
break;
case 'D':
printf("The quotient is: %d", division);
break;
default:
printf("Enter a valid initial");
break;
}
return 0;
}
OUTPUT:
5. Implement C program to find number of days in a month.
#include <stdio.h>
int main()
{
// program to find number of days in a month
int num;
printf("Enter a number from 1 to 12: ");
scanf("%d", &num);
switch (num)
{
case 1:
printf("There are 31 days in January");
break;
case 2:
printf("There are 28 days in February and 29 if its a leap year");
break;
case 3:
printf("There are 31 days in March");
break;
case 4:
printf("There are 30 days in April");
break;
case 5:
printf("There are 31 days in May");
break;
case 6:
printf("There are 30 days in June");
break;
case 7:
printf("There are 31 days in July");
break;
case 8:
printf("There are 31 days in August");
break;
case 9:
printf("There are 30 days in September");
break;
case 10:
printf("There are 31 days in October");
break;
case 11:
printf("There are 30 days in November");
break;
case 12:
printf("There are 31 days in December");
break;
default:
printf("There are only 12 months in a year, enter a valid number");
break;
}
return 0;
}
OUTPUT:
THE END

You might also like