0% found this document useful (0 votes)
3 views7 pages

C Programs for Basic Calculations

Basic knowledge of c programming

Uploaded by

aryannikam11807
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)
3 views7 pages

C Programs for Basic Calculations

Basic knowledge of c programming

Uploaded by

aryannikam11807
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

Name: - Aryan Anil Nikam Roll No: - 133

Q.1] Program to check weather the number is even or odd.

Source Code:
#include<stdio.h>
#include<conio.h>
void main()
{
int a;
clrscr();
printf("Enter value for a=");
scanf("%d",& a);
if(a%2==0)
{
printf("\n Number is even");
}
else
{
printf("\n Number is odd");
}
getch();
}
Output:

Page No.
Name: - Aryan Anil Nikam Roll No: - 133

Q.2] Program to print grade of student based on their marks.

Source Code:
#include<stdio.h>
#include<conio.h>
void main()
{
int m;
clrscr();
printf("enter the marks=");
scanf("%d",& m);
if(m>=50)
{
if(m>=90)
{
printf("Grade A");
}
else if(m>=75)
{
printf("Grade B");
}
else
{

printf("Grade C");
}
}
else
{
printf("Grade D");
}
getch();
}

Page No.
Name: - Aryan Anil Nikam Roll No: - 133

Output:
Name: - Aryan Anil Nikam Roll No: - 133

Q.3] Program to print larger and the smaller number among the
given three numbers

1) Larger number

Source Code:

#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c;
clrscr();
printf("enter value for a=");
scanf("%d",& a);
printf("enter value for b=");
scanf("%d",& b);
printf("enter value for c=");
scanf("%d",& c);
if(a>b && a>c)
{
printf("a is greater");
}
else if(a<b && b>c)
{
printf("b is greater");
}
else
{
printf("c is greater");
}
getch()
Output:

Page No.
Name: - Aryan Anil Nikam Roll No: - 133

2) smaller number :-

Source Code:

#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c;
clrscr();
printf("enter value for a=");
scanf("%d",& a);
printf("enter value for b=");
scanf("%d",& b);
printf("enter value for c=");
scanf("%d",& c);
if(a<b && a<c)
{
printf("a is smaller");
}
else if(a>b && b<c)
{
printf("b is smaller");
}
else
{
printf("c is smaller");
}
getch();
}

Output:

Page No.
Name: - Aryan Anil Nikam Roll No: - 133

Q.4] Program to print a simple calculator using switch case

Source Code:

Output:

#include<stdio.h>
#include<conio.h>
void main()
{
int sum,sub,mult,option;
float a,b,div;
clrscr();
printf("enter value for num1=");
scanf("%f",& a);
printf("enter value for num2=");
scanf("%f",& b);
printf("Enter case for operation=");
scanf("%d",& option);
switch(option)
{
case 1:
sum=a+b;
printf("sum=%d",sum);
break;
case 2:
sub=a-b;
printf("subs=%d",sub);
break;
case 3:
mult=a*b;
printf("mult=%d",mult);
break;
case 4:
div=a/b;
printf("div=%0.3f",div);
break;
case 5:
default:
printf("invalid statement");
break;
}
getch();
}
Page No.
Name: - Aryan Anil Nikam Roll No: - 133

1. Addition:-

2. Subtraction:-

3. Multiplication:-

4. Division:-

Page No.

You might also like