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

Programming in C: Dr. Pertik Garg

The document provides examples of C programs with explanations and instructions from Dr. Pertik Garg of the Department of Applied Science. It includes programs to print "Hello World", calculate the sum and swap of two numbers, calculate the area of a rectangle, use if/else conditional statements, find the largest of three numbers, and prompts the reader to write additional programs to determine if a number is odd or even and to calculate simple interest.

Uploaded by

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

Programming in C: Dr. Pertik Garg

The document provides examples of C programs with explanations and instructions from Dr. Pertik Garg of the Department of Applied Science. It includes programs to print "Hello World", calculate the sum and swap of two numbers, calculate the area of a rectangle, use if/else conditional statements, find the largest of three numbers, and prompts the reader to write additional programs to determine if a number is odd or even and to calculate simple interest.

Uploaded by

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

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

You might also like