DEPARTMENT OF APPLIED SCIENCE
Programming in C
Dr. Pertik Garg
DEPARTMENT OF APPLIED SCIENCE
Compilation of c program online
• Link to compile program online
https://www.programiz.com/c-programming/on
line-compiler/
PPS Dr. Pertik Garg
DEPARTMENT OF APPLIED SCIENCE
First Program
#include <stdio.h>
int main()
{
// Write C code here
printf("Hello world");
return 0;
PPS
} Dr. Pertik Garg
DEPARTMENT OF APPLIED SCIENCE
First Program
PPS Dr. Pertik Garg
DEPARTMENT OF APPLIED SCIENCE
Sum of two Numbers
#include <stdio.h>
int main()
{ // Write C code here
int a,b,c;
printf("Enter First Number");
scanf("%d",&a);
printf("Enter Second Number");
scanf("%d",&b);
c=a+b;
printf("Result is%d",c);
return 0;
}
PPS Dr. Pertik Garg
DEPARTMENT OF APPLIED SCIENCE
Sum of two Numbers
PPS
DEPARTMENT OF APPLIED SCIENCE
Swapping of two numbers
#include <stdio.h>
int main()
{ // Write C code here
int a,b,c;
printf("Enter Value of A");
scanf("%d",&a);
printf("Enter Value of B");
scanf("%d",&b);
c=a;
a=b;
b=c;
printf("Result after Swapping A %d",a);
printf("Result after Swapping B %d",b);
return 0;
}
PPS Dr. Pertik Garg
DEPARTMENT OF APPLIED SCIENCE
Swapping of two numbers
PPS Dr. Pertik Garg
DEPARTMENT OF APPLIED SCIENCE
Swapping of two numbers without using third variable
#include <stdio.h>
int main()
{ // Write C code here
int a,b,c;
printf("Enter Value of A");
scanf("%d",&a);
printf("Enter Value of B");
scanf("%d",&b);
a=a+b ;
a=a-b;
b=a-b;
printf("Result after Swapping A %d",a);
printf("Result after Swapping B %d",b);
return 0;
}
PPS Dr. Pertik Garg
DEPARTMENT OF APPLIED SCIENCE
Swapping of two numbers without using third variable
PPS Dr. Pertik Garg
DEPARTMENT OF APPLIED SCIENCE
Program to Calculate area
#include <stdio.h>
int main()
{ // Write C code here
int len,breadth,area;
printf("Enter length");
scanf("%d",&len);
printf("Enter breadth");
scanf("%d",&breadth);
area=len*breadth;
printf("Area = %d",area);
return 0;
}
PPS Dr. Pertik Garg
DEPARTMENT OF APPLIED SCIENCE
Program to Calculate area
PPS Dr. Pertik Garg
DEPARTMENT OF APPLIED SCIENCE
If-else condition
#include <stdio.h>
int main()
{
int number;
printf("Enter an integer: ");
scanf("%d", &number);
// true if number is less than 0
if (number < 0)
{
printf("Your entered number is negative");
}
else
{
printf("Your entered number is Positive.");
}
}
return 0;
}
PPS Dr. Pertik Garg
DEPARTMENT OF APPLIED SCIENCE
If-else condition
PPS Dr. Pertik Garg
DEPARTMENT OF APPLIED SCIENCE
Find the largest #include
number <stdio.h>
among 3 numbers
int main() {
int a,b,c;
printf("Enter value of A: ");
scanf("%d", &a);
printf("Enter value of B: ");
scanf("%d", &b);
printf("Enter value of C: ");
scanf("%d", &c);
// true if number is less than 0
if (a>b && a>c)
{
printf("largest no. is A");
}
else
if (b>a && b>c)
{
printf("largest no. is B");
}
else
{
printf("largest no. is C");
}
}
PPS Dr. Pertik Garg
DEPARTMENT OF APPLIED SCIENCE
Find the largest number among 3 numbers
PPS Dr. Pertik Garg
DEPARTMENT OF APPLIED SCIENCE
Try yourself
• WAP to find no. is odd or even
• WAP to calculate simple interest by input
principal, rate and time.
PPS Dr. Pertik Garg