C Language
C Language
LANGUAGE
C language:-
C is a procedural programming language
initially developed by Dennis Ritchie in
the year 1972 at Bell Laboratories of
AT&T Labs. It was mainly developed as a
system programming language to write
the UNIX operating system
Stdio.h:- stdio.h header file allows us to
perform input and output operations in C.
The functions like printf() and scanf() are
used to display output and take input
from a user.
Printf():-in C language, print f function is
used to print output on the screen. This
function is a part of the C standard library
“stdio.h” and it can allow formatting the
output in numerous ways.
Scanf():-In C programming language,
scanf is a function that stands for Scan
Formatted String. It is used to read data
from stdin (standard input stream i.e.
usually keyboard) and then writes the
result int o the given arguments.
It accepts character, string, and
numeric data from the user using
standard input.
scanf also uses format specifiers like
printf.
ADDITION OF 2 NUMBERS:
#include <stdio.h>
#include<conio.h>
Int main()
{
int number1, number2, sum;
printf("Enter two integers: ");
scanf("%d %d", &number1, &number2);
sum = number1 + number2;
printf("%d + %d = %d", number1,
number2, sum);
}
SUBTRACTION OF 2 NUMBER’S:
include <stdio.h>
Int main()
{
int number1, number2, subtract;
printf("Enter two int egers: ");
scanf("%d %d", &number1, &number2);
subtract = number1 - number2;
printf("%d - %d = %d", number1,
number2, subtract);
}
Program to Multiplication of two
numbers
#include<stdio.h>
#include<conio.h>
int main()
{
int num1,num2,product;
printf("Enter two numbers:");
scanf("%d %d",&num1,&num2);
product=num1*num2;
printf("Product of two numbers:
%d",product);
}
#include<stdio.h>
#include<conio.h>
Int main()
{
int num1,num2,quotient;
printf("Enter two numbers:");
scanf("%d %d",&num1,&num2);
quotient=num1/num2;
printf("Quotient: %d",quotient);
}
AREA OF SQUARE:
#include<stdio.h>
#include<conio.h>
Int main()
{
int side,area;
printf("Enter a side of square:");
scanf("%d",&side);
area=side * side;
printf("\nArea of Square: %d",area);
}
C Program to find area of
Rectangle
#include<stdio.h>
#include<conio.h>
Int main()
{
int length,breadth, area;
printf("Enter length and breadth of
rectangle:");
scanf("%d %d",&length,&breadth);
area=length * breadth;
print f("\nArea of Rectangle: %d",area);
}
#include<stdio.h>
#include<conio.h>
Int main()
{
float p,r,t,si;
printf(“enter the p and t and r=”);
scanf("%f %f %f",&p,&t,&r);
si=(p*t*r)/100;
print f("%f",si);
}
C Program to convert
FAHRENHIET TO CELSIUS
#include<stdio.h>
#include<conio.h>
Int main()
{
float f,c;
print f("Enter celsius:");
scanf("%f",&c);
f=c*1.8+32;
print f("Fahrenhiet:%f",f);
}
AREA OF TRIANGLE:
#include <stdio.h>
#include<conio.h>
int main()
{
float base, height, area;
IF CONDITION
Even or odd:
#include <stdio.h>
#include<conio.h>
Int main()
{
int num;
print f("Enter an int eger: ");
scanf("%d", &num);
// true if num is perfectly divisible by 2
if(num % 2 = = 0)
print f("%d is even.", num);
else
print f("%d is odd.", num);
}
#include<stdio.h>
#include<conio.h>
Int main()
{
int num;
scanf("%d",&num);
#include <stdio.h>
#include<conio.h>
Void main
{
int m;
float km;
print f("Enter Meters:");
scanf("%d",&m);
km=m/1000.00;
print f("Kilometers: %f",km);
}
#include <stdio.h>
#include<conio.h>
Int main()
{
float basic, gross, da, hra;
print f(“Enter basic salary of an
employee: “);
scanf(“%f”, &basic);
if(basic <= 10000)
{
da = basic * 0.8;
hra = basic * 0.2;
}
else if(basic <= 20000)
{
da = basic * 0.9;
hra = basic * 0.25;
}
else
{
da = basic * 0.95;
hra = basic * 0.3;
}
/* Calculate gross salary */
gross = basic + hra + da;
print f(“GROSS SALARY OF EMPLOYEE =
%f”, gross);
}
AMSTRONG NUMBER:
#include <math.h>
#include <stdio.h>
#include<conio.h>
int main()
{
int num, originalNum, remainder, n = 0;
float result = 0.0;
print f(“Enter an int eger: “);
scanf(“%d”, &num);
originalNum = num;
// store the number of digits of num in n
for (originalNum = num; originalNum !=
0; ++n) {
originalNum /= 10;
}
for (originalNum = num; originalNum !=
0; originalNum /= 10) {
remainder = originalNum % 10;
// store the sum of the power of individual
digits in result
result += pow(remainder, n);
}
// if num is equal to result, the number is
an Armstrong number
if ((int )result == num)
print f(“%d is an Armstrong number.”,
num);
else
print f(“%d is not an Armstrong
number.”, num);
}
Palindrome number:
#include<stdio.h>
#include<conio.h>
Int main()
{
int n,r,sum=0,temp;
print f(“enter the number=”);
scanf(“%d”,&n);
temp=n;
while(n>0)
{
r=n%10;
sum=(sum*10)+r;
n=n/10;
}
if(temp==sum)
print f(“palindrome number “);
else
print f(“not palindrome”);
}
Reverse number:
#include<stdio.h>
#include<conio.h>
int main()
{
int num, rev = 0, rem;
print f(“Enter the number to reverse: “);
scanf(“%d”, &num);
while (num != 0){
rem = num % 10;
rev = rev * 10 + rem;
num = num/10;
}
print f(“The reversed number is: %d”,
rev);
}
#include <stdio.h>
#include<conio.h>
Int main()
{
int i, n, sum=0;
print f("Enter upper limit: ");
scanf("%d", &n);
/* Find the sum of all odd number */
for(i=1; i<=n; i+=2)
{
sum += i;
}
print f("Sum of odd numbers = %d",
sum);
}
LOOP IN C
PROGRAMME
Loops in programming are used to
repeat a block of code until the
specified condition is met. A loop
statement allows programmers to
execute a statement or group of
statements multiple times without
repetition of code.
while first Initializes, then condition checks, and then executes the
Loop Type Description
do-while do-while first executes the body and then the condition check is
loop done.
for Loop
While Loop
While loop does not depend upon the number of
iterations. In for loop the number of iterations was
previously known to us but in the While loop, the
execution is terminated on the basis of the test
condition. If the test condition will become false then it
will break from the while loop else body will be executed.
do-while Loop