0% found this document useful (0 votes)
32 views

Practical Programs

The document contains code snippets for various C programming practical exercises including: 1. A program to calculate the area of a circle using PI and radius input by the user. 2. Programs using conditional operators to find the largest of three numbers, determine if a number is even or odd, and check if a character is a vowel. 3. A program that takes student marks as input and prints the grade based on percentage ranges. 4. A program that takes a week number as input and prints the corresponding day of the week using switch case.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views

Practical Programs

The document contains code snippets for various C programming practical exercises including: 1. A program to calculate the area of a circle using PI and radius input by the user. 2. Programs using conditional operators to find the largest of three numbers, determine if a number is even or odd, and check if a character is a vowel. 3. A program that takes student marks as input and prints the grade based on percentage ranges. 4. A program that takes a week number as input and prints the corresponding day of the week using switch case.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 10

Practical No 2–

Area of Circle program in C


#include <stdio.h>

#define PI 3.14159

int main()

float radius, area;

printf("Enter the radius of the circle: ");

scanf("%f", &radius);

area = PI * radius * radius;

printf("The area of the circle is: %f", area);

return 0;

Practical No—4

1. Write a c program to find largest of three numbers using conditional


operator.

#include<stdio.h>
int main(){
int a,b,c,big;
printf("\nEnter 3 numbers:");
scanf("%d %d %d",&a,&b,&c);
big=(a>b&&a>c?a:b>c?b:c);
printf("\nThe biggest number is:%d",big);
return 0;
}

2. C program to check even or odd number using conditional operator

#include <stdio.h>

int main()

int num;

printf("Enter any number to check even or odd: ");

scanf("%d", &num);

(num%2 == 0) ? printf("The number is EVEN") : printf("The number is


ODD"); return 0;

Practical No—-5
● Write a C program to check vowel or consonant using conditional
operator

#include<stdio.h>
int main()
{
char ch;
printf("\nEnter the character:");
scanf("%c",&ch);
ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u'?printf("This character is a
vowel:%c",ch):printf("This character is not a vowel:%c",ch);
return 0;
}

● Write a C Program to display to display your batch (Batch1 or Batch2).


#include <stdio.h>

int main()
{
int rn;
printf("\nEnter roll number:");
scanf("%d",&rn);
rn>=1&&rn<=25?printf("Your batch is Batch1"):printf("Your batch is
Batch2");
return 0;
}

Practical No—-6

1.Write and Execute the C program to print the grades of students based
on percentage.

Grade: Distinction If per>=75

Grade: A If per>=60 and Per<75

Grade: B If per>=55 and Per<60

Grade: Pass If per>=40 and Per<55

Grade:Fail if per<40

#include <stdio.h>

int main()

int phy, chem, bio, math, comp;

float per;
/* Input marks of five subjects from user */

printf("Enter five subjects marks: ");

scanf("%d%d%d%d%d", &phy, &chem, &bio, &math, &comp);

/* Calculate percentage */

per = (phy + chem + bio + math + comp) / 5.0;

printf("Percentage = %.2f\n", per);

/* Find grade according to the percentage */

if(per >= 75) {

printf("Distinction");

else if(per >= 60) {

printf("Grade A");

else if(per >= 55) {

printf("Grade B");

else if(per >= 40) {

printf("Grade C");

else {

printf("Fail");

return 0;
}

2.Write a C Program to Find the Largest Number Among Three Numbers

#include <stdio.h>

int main() {

double n1, n2, n3;

printf("Enter three numbers: ");


scanf("%lf %lf %lf", &n1, &n2, &n3);

// if n1 is greater than both n2 and n3, n1 is the largest


if (n1 >= n2 && n1 >= n3)
printf("%.2lf is the largest number.", n1);

// if n2 is greater than both n1 and n3, n2 is the largest


else if (n2 >= n1 && n2 >= n3)
printf("%.2lf is the largest number.", n2);

// if both above conditions are false, n3 is the largest


else
printf("%.2lf is the largest number.", n3);

return 0;
}
Practical No—-7

Write a C program to input week number(1-7) and print day of week


name using switch case.

#include <stdio.h>

int main() {

int week;

/* Input week number from user */

printf("Enter week number (1-7): ");

scanf("%d", &week);

if(week == 1) {

printf("Monday");

else if(week == 2) {

printf("Tuesday");

else if(week == 3) {

printf("Wednesday");

else if(week == 4) {

printf("Thursday");
}

else if(week == 5) {

printf("Friday");

else if(week == 6)

{ printf("Saturday");

else if(week == 7) {

printf("Sunday");

else { printf("Invalid Input! Please enter week number between 1-7.");

return 0;

Practical No—-8

Write a C program to print English Calendar months as per given


number(eg: If input is 4 then print “April”) using Switch statement

#include<stdio.h>
void main() {
int ch;
printf("\n enter the month number : "); scanf("%d",&ch);
switch(ch) {
case 1:
printf("Month is : January");
Break;
case 2:
printf("Month is : February");
break;
case 3:
printf("Month is : March");
break;
case 4:
printf("Month is : April");
Break;
case 5:
printf("Month is : May");
Break;
case 6:
printf("Month is : June");
Break;
case 7:
printf("Month is : July");
break;
case 8:
printf("Month is : August");
Break;
case 9:
printf("Month is : September");
Break;
case 10:
printf("Month is : October");
break;
case 11:
printf("Month is : November");
break; case 12: printf("Month is : December"); break;
default :
printf("invalid number");
}}

Practical No—-9
calculate count the number of digits using for or while loop.

#include <stdio.h>

int main()
{

int n; // variable declaration

int count=0; // variable declaration

printf("Enter a number");

scanf("%d",&n);

while(n!=0)

n=n/10;

count++;

printf("\nThe number of digits in an integer is : %d",count);

return 0;

2. C Program to Print the Table of a Number

#include<stdio.h>

int main()
{
int num, i, tab;
printf("Enter the number: ");
scanf("%d", &num);
printf("\nTable of %d is:\n", num);
for(i=1; i<=10; i++)
{
tab = num*i;
printf("%d * %2d = %2d\n", num, i, tab);
}
getch();
return 0;
}

You might also like