C Language Practical /IMP Programs
Two numbers are input through the keyboard into two locations C and D. Write a program to
interchange the contents of C and D.
#include<stdio.h>
#include<conio.h>
void main()
{
int C,D,temp;
clrscr();
printf("\nEnter Two Numbers:");
scanf("%d%d",&C,&D);
printf("****Before Swapping****");
printf("\nC=%d",C);
printf("\nD=%d",D);
temp=C;
C=D;
D=temp;
printf("\n****After Swapping****");
printf("\nC=%d",C);
printf("\nD=%d",D);
getch();
}
C Programming Language by Prof. Vishal Jadhav Sir’s (VJTech Academy, contact us: +91-7743909870) 1
C Language Practical /IMP Programs
The length & breadth of a rectangle and radius of a circle are input through the keyboard. Write a
program to calculate the area & perimeter of the rectangle, and the area & circumference of the
circle.
#include<stdio.h>
#include<conio.h>
void main()
float length,breadth,radius,perimeter,circumference,area1,area2;
clrscr();
printf("\nEnter Length & Breadth of Rectangle:");
scanf("%f%f",&length,&breadth);
printf("\nEnter Radius of Circle:");
scanf("%f",&radius);
area1=(length*breadth);
perimeter=(2*(length+breadth));
printf("\nArea of Rectangle:%f",area1);
printf("\nPerimeter of Rectangle:%f",perimeter);
area2=(3.14*radius*radius);
circumference=(2*3.14*radius);
printf("\nArea of Circle:%f",area2);
printf("\nCircumference of Circle:%f",circumference);
getch();
C Programming Language by Prof. Vishal Jadhav Sir’s (VJTech Academy, contact us: +91-7743909870) 2
C Language Practical /IMP Programs
Write a program to print square of given number
#include<stdio.h>
#include<conio.h>
void main()
int no,square;
clrscr();
printf("\nEnter any number:");
scanf("%d",&no);
square=no*no;
printf("\nSquare of given number=%d",square);
getch();
C Programming Language by Prof. Vishal Jadhav Sir’s (VJTech Academy, contact us: +91-7743909870) 3
C Language Practical /IMP Programs
Write a C program to read integer, character, float, double values from the user and display it.
Mention different format specifiers used in program in comment.
#include<stdio.h>
#include<conio.h>
void main()
{
int a;
float b;
char c;
double d;
clrscr();
printf("\nEnter integer number:");
scanf("%d",&a);
printf("\nEnter float number:");
scanf("%f",&b);
printf("\nEnter character:");
scanf("%c",&c);
printf("\nEnter double number:");
scanf("%lf",&d);
printf("\nValue of a=%d",a);
printf("\nValue of b=%f",b);
printf("\nValue of c=%c",c);
printf("\nValue of d=%lf",d);
getch();
}
C Programming Language by Prof. Vishal Jadhav Sir’s (VJTech Academy, contact us: +91-7743909870) 4
C Language Practical /IMP Programs
Write a C program to print the address of variable
#include<stdio.h>
#include<conio.h>
void main()
int a;
clrscr();
printf("\nAddress of a=%u",&a);
getch();
C Programming Language by Prof. Vishal Jadhav Sir’s (VJTech Academy, contact us: +91-7743909870) 5
C Language Practical /IMP Programs
Write a program for the largest of three numbers.
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c;
clrscr();
printf("\nEnter three Numbers:");
scanf("%d%d%d",&a,&b,&c);
if(a>b)
{
if(a>c)
{
printf("\nGreatest Number=%d",a);
}
else
{
printf("\nGreatest Number=%d",c);
}
}
else
{
if(b>c)
{
printf("\nGreatest Number=%d",b);
}
else
{
printf("\nGreatest Number=%d",c);
}
}
getch();
}
C Programming Language by Prof. Vishal Jadhav Sir’s (VJTech Academy, contact us: +91-7743909870) 6
C Language Practical /IMP Programs
Write a program to demonstrate the working of relational operator.
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b;
clrscr();
printf("\nEnter two Numbers:");
scanf("%d%d",&a,&b);
if(a>b)
{
printf("\nGreatest Number=%d",a);
}
else
{
printf("\nGreatest Number=%d",b);
}
getch();
}
Write a program using conditional operator to check whether a user can vote or not based on their
age.
#include<stdio.h>
#include<conio.h>
void main()
{
int age;
clrscr();
printf("\nEnter your age:");
scanf("%d",&age);
age>=18?printf("Eligible for voting"):printf("\nNot eligible for voting");
getch();
}
C Programming Language by Prof. Vishal Jadhav Sir’s (VJTech Academy, contact us: +91-7743909870) 7
C Language Practical /IMP Programs
Write a program to find the greatest number between three by using logical operators.
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c;
clrscr();
printf("\nEnter three numbers:");
scanf("%d%d%d",&a,&b,&c);
if(a>b&&a>c)
{
printf("\nGreatest Number:%d",a);
}
else if(b>a&&b>c)
{
printf("\nGreatest Number:%d",b);
}
else
{
printf("\nGreatest Number:%d",c);
}
getch();
}
C Programming Language by Prof. Vishal Jadhav Sir’s (VJTech Academy, contact us: +91-7743909870) 8
C Language Practical /IMP Programs
Write a program that accepts marks of 5 subjects calculate the percentage and display grade
of student from percentage. (Grade Distinction, first class, second class, pass class, fail).
#include<stdio.h>
#include<conio.h>
void main()
{
int sub1,sub2,sub3,sub4,sub5,total;
float percentage;
clrscr();
printf("\nEnter five subjects marks:");
scanf("%d%d%d%d%d",&sub1,&sub2,&sub3,&sub4,&sub5);
total=(sub1+sub2+sub3+sub4+sub5);
percentage=(float)total/5;
if(percentage>=75)
{
printf("\nGrade: Distinction");
}
else if(percentage>=60)
{
printf("\nGrade: First Class");
}
else if(percentage>=50)
{
printf("Grade: Second Class");
}
else if(percentage>=40)
{
printf("\nPass Only");
}
else
{
printf("\nYou are Fail");
}
getch();
}
C Programming Language by Prof. Vishal Jadhav Sir’s (VJTech Academy, contact us: +91-7743909870) 9
C Language Practical /IMP Programs
Write a program to find whether the given number is even or odd.
#include<stdio.h>
#include<conio.h>
void main()
{
int no;
clrscr();
printf("\nEnter Any Number:");
scanf("%d",&no);
if(no%2==0)
{
printf("\nEven Number");
}
else
{
printf("\nOdd Number");
}
getch();
}
C Programming Language by Prof. Vishal Jadhav Sir’s (VJTech Academy, contact us: +91-7743909870) 10
C Language Practical /IMP Programs
Write a program to find whether the given number divisible by 5 or not.
#include<stdio.h>
#include<conio.h>
void main()
{
int no;
clrscr();
printf("\nEnter Any Number:");
scanf("%d",&no);
if(no%5==0)
{
printf("\nNumber is divisible by 5");
}
else
{
printf("\nNumber is not divisible by 5");
}
getch();
}
C Programming Language by Prof. Vishal Jadhav Sir’s (VJTech Academy, contact us: +91-7743909870) 11
C Language Practical /IMP Programs
//Find Whether given number is even or odd.
#include<stdio.h>
#include<conio.h>
void main()
{
int no;
clrscr();
printf("\nEnter any number:");
scanf("%d",&no);
if(no%2==0)
{
printf("\nNumber is EVEN");
}
else
{
printf("\nNumber is ODD");
}
getch();
}
C Programming Language by Prof. Vishal Jadhav Sir’s (VJTech Academy, contact us: +91-7743909870) 12
C Language Practical /IMP Programs
//Find Whether given number is prime number or not.
#include<stdio.h>
#include<conio.h>
void main()
{
int no,i,flag=0;
clrscr();
printf("\nEnter any number:");
scanf("%d",&no);
for(i=2;i<no;i++)
{
if(no%i==0)
{
flag=1;
break;
}
}
if(flag==0)
{
printf("\nPrime Number");
}
else
{
printf("\nNot Prime Number");
}
getch();
}
C Programming Language by Prof. Vishal Jadhav Sir’s (VJTech Academy, contact us: +91-7743909870) 13
C Language Practical /IMP Programs
//Write a C program to determine whether a given year is a leap year or not
#include<stdio.h>
#include<conio.h>
void main()
{
int year;
clrscr();
printf("\nEnter any year:");
scanf("%d",&year);
if(year%4==0)
{
printf("\nLeap Year");
}
else
{
printf("\nNot Leap Year");
}
getch();
}
C Programming Language by Prof. Vishal Jadhav Sir’s (VJTech Academy, contact us: +91-7743909870) 14
C Language Practical /IMP Programs
Write a C program to print day of the week by taking number from 1 to 7 using switch statement.
#include<stdio.h>
#include<conio.h>
void main()
{
int day;
clrscr();
printf("\nEnter any day:");
scanf("%d",&day);
switch(day)
{
case 1: printf("\nSunday");
break;
case 2: printf("\nMonday");
break;
case 3: printf("\nTuesday");
break;
case 4: printf("\nWednesday");
break;
case 5: printf("\nThursday");
break;
case 6: printf("\nFriday");
break;
case 7: printf("\nSaturday");
break;
default:printf("\nInvalid day of week");
}
getch();
}
C Programming Language by Prof. Vishal Jadhav Sir’s (VJTech Academy, contact us: +91-7743909870) 15
C Language Practical /IMP Programs
Write a C program that reads the value in the range of 1 -12 and print the name of that month and
next month.
#include<stdio.h>
#include<conio.h>
void main()
{
int month;
clrscr();
printf("\nEnter any month(1-12):");
scanf("%d",&month);
switch(month)
{
case 1: printf("\nJan & Feb");
break;
case 2: printf("\nFeb & March");
break;
case 3: printf("\nMarch & April");
break;
case 4: printf("\nApril & May");
break;
case 5: printf("\nMay & June");
break;
case 6: printf("\nJune & July");
break;
case 7: printf("\nJuly & Aug");
break;
case 8: printf("\nAug & Sept");
break;
case 9: printf("\nSept & Oct");
break;
case 10: printf("\nOct & Nov");
break;
case 11: printf("\nNov & Dec");
break;
case 12: printf("\nDec & Jan");
break;
default:printf("\nInvalid month of year");
}
getch();
}
C Programming Language by Prof. Vishal Jadhav Sir’s (VJTech Academy, contact us: +91-7743909870) 16
C Language Practical /IMP Programs
Write a program to reverse the number of given number print using while loop
#include<stdio.h>
#include<conio.h>
void main()
{
int no,rev=0,rem;
clrscr();
printf("\nEnter any number:");
scanf("%d",&no);
while(no>0)
{
rem=no%10;
rev=rev*10+rem;
no=no/10;
}
printf("\nReverse Number=%d",rev);
getch();
}
C Programming Language by Prof. Vishal Jadhav Sir’s (VJTech Academy, contact us: +91-7743909870) 17
C Language Practical /IMP Programs
Find sum of digits of a given number using do-while loop.
#include<stdio.h>
#include<conio.h>
void main()
int no,sum=0,rem;
clrscr();
printf("\nEnter any number:");
scanf("%d",&no);
while(no>0)
rem=no%10;
sum=sum+rem;
no=no/10;
printf("\nSum of digits=%d",sum);
getch();
C Programming Language by Prof. Vishal Jadhav Sir’s (VJTech Academy, contact us: +91-7743909870) 18
C Language Practical /IMP Programs
Write a program to check given number is palindrome or not using while loop.
#include<stdio.h>
#include<conio.h>
void main()
{
int no,rev=0,rem,x;
clrscr();
printf("\nEnter any number:");
scanf("%d",&no);
x=no;
while(no>0)
{
rem=no%10;
rev=rev*10+rem;
no=no/10;
}
if(x==rev)
{
printf("\nNumber is palindrome");
}
else
{
printf("\nNumber is not palindrome");
}
getch();
}
C Programming Language by Prof. Vishal Jadhav Sir’s (VJTech Academy, contact us: +91-7743909870) 19
C Language Practical /IMP Programs
Write a C Program to print odd numbers from 1 to 100
#include<stdio.h>
#include<conio.h>
void main()
{
int i;
clrscr();
printf("Odd Number between 1 to 100:");
for(i=1;i<=100;i++)
{
if(i%2!=0)
{
printf("%d\t",i);
}
}
getch();
}
C Programming Language by Prof. Vishal Jadhav Sir’s (VJTech Academy, contact us: +91-7743909870) 20
C Language Practical /IMP Programs
Write a C Program to print Even numbers from 1 to 100
#include<stdio.h>
#include<conio.h>
void main()
{
int i;
clrscr();
printf("Even Number between 1 to 100:");
for(i=1;i<=100;i++)
{
if(i%2==0)
{
printf("%d\t",i);
}
}
getch();
}
C Programming Language by Prof. Vishal Jadhav Sir’s (VJTech Academy, contact us: +91-7743909870) 21
C Language Practical /IMP Programs
Find Fibonacci series for given number
#include<stdio.h>
#include<conio.h>
void main()
{
int fno,sno,tno,N,i;
clrscr();
printf("\nEnter Value of N:");
scanf("%d",&N);
fno=0;
sno=1;
printf("\nFibonacci Series:%d\t%d",fno,sno);
for(i=2;i<N;i++)
{
tno=fno+sno;
printf("\t%d",tno);
fno=sno;
sno=tno;
}
getch();
}
C Programming Language by Prof. Vishal Jadhav Sir’s (VJTech Academy, contact us: +91-7743909870) 22
C Language Practical /IMP Programs
Write C Program to print following or similar pattern
*****
****
***
**
*
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j;
clrscr();
for(i=5;i>=1;i--)
{
for(j=1;j<=i;j++)
{
printf("*");
}
printf("\n");
}
getch();
}
C Programming Language by Prof. Vishal Jadhav Sir’s (VJTech Academy, contact us: +91-7743909870) 23
C Language Practical /IMP Programs
Write C Program to print following or similar pattern
*
**
***
****
*****
#include<stdio.h>
void main()
{
int i,j;
for(i=1;i<=5;i++)
{
for(j=1;j<=i;j++)
{
printf("*");
}
printf("\n");
}
}
C Programming Language by Prof. Vishal Jadhav Sir’s (VJTech Academy, contact us: +91-7743909870) 24
C Language Practical /IMP Programs
Write C Program to print following or similar pattern
1
12
123
1234
12345
#include<stdio.h>
void main()
{
int i,j;
for(i=1;i<=5;i++)
{
for(j=1;j<=i;j++)
{
printf("%d",j);
}
printf("\n");
}
}
C Programming Language by Prof. Vishal Jadhav Sir’s (VJTech Academy, contact us: +91-7743909870) 25
C Language Practical /IMP Programs
Write C Program to print following or similar pattern
43
432
4321
#include<stdio.h>
void main()
{
int i,j,k;
for(i=1;i<=4;i++)
{
k=4;
for(j=1;j<=i;j++)
{
printf("%d",k);
k--;
}
printf("\n");
}
}
C Programming Language by Prof. Vishal Jadhav Sir’s (VJTech Academy, contact us: +91-7743909870) 26
C Language Practical /IMP Programs
Write C program to input 5 numbers using array and display sum of it.
#include<stdio.h>
void main()
{
int a[5],sum=0,i;
printf("\nEnter 5 array elements:");
for(i=0;i<5;i++)
{
scanf("%d",&a[i]);
}
for(i=0;i<5;i++)
{
sum=sum+a[i];
}
printf("\nSum of Array Elements:%d",sum);
}
C Programming Language by Prof. Vishal Jadhav Sir’s (VJTech Academy, contact us: +91-7743909870) 27
C Language Practical /IMP Programs
Write C program to print array in ascending order.
#include<stdio.h>
void main()
{
int a[5],i,j,temp;
printf("\nEnter 5 array elements:");
for(i=0;i<5;i++)
{
scanf("%d",&a[i]);
}
//sorting logic
for(i=1;i<5;i++)
{
for(j=0;j<5-i;j++)
{
if(a[j]>a[j+1])
{
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
}
}
printf("\nSorted Array Elements:");
for(i=0;i<5;i++)
{
printf("%d\t",a[i]);
}
}
C Programming Language by Prof. Vishal Jadhav Sir’s (VJTech Academy, contact us: +91-7743909870) 28
C Language Practical /IMP Programs
Write C program to calculate addition of two 3X3 matrices
#include<stdio.h>
#include<conio.h>
void main()
{
int a[3][3],b[3][3],c[3][3],i,j;
clrscr();
printf("\nEnter First 3*3 Matrix Elements:");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
scanf("%d",&a[i][j]);
}
}
printf("\nEnter second 3*3 Matrix Elements:");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
scanf("%d",&b[i][j]);
}
}
//Addition of two matrix
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
c[i][j]=a[i][j]+b[i][j];
}
}
printf("\nAddition of 3*3 Matrix:");
for(i=0;i<3;i++)
{
printf("\n");
for(j=0;j<3;j++)
{
printf("%d\t",c[i][j]);
}
}
}
C Programming Language by Prof. Vishal Jadhav Sir’s (VJTech Academy, contact us: +91-7743909870) 29
C Language Practical /IMP Programs
Create a structure called a library to hold details of the book viz. accession number, title
of the book, author name, price of the book and flag indicating whether book is issued or
not. Fetch some sample data and display the same.
#include<stdio.h>
#include<conio.h>
struct library
{
int accession_no;
char title[10];
char author_name[10];
float price;
char flag[10];
};
void main()
{
struct library s1;
clrscr();
printf("\nEnter Book Accession No:");
scanf("%d",&s1.accession_no);
printf("\nEnter Book Title:");
scanf("%s",&[Link]);
printf("\nEnter Book Author Name:");
scanf("%s",&s1.author_name);
printf("\nEnter Book Price:");
scanf("%f",&[Link]);
printf("\nWhether book is issued or not (Y/N):");
scanf("%s",&[Link]);
printf("\n****BOOK INFORMATION****");
printf("\nAccession No: %d",s1.accession_no);
printf("\nBook Title: %s",[Link]);
printf("\nAuthor Name: %s",s1.author_name);
printf("\nBook Price: %f",[Link]);
printf("\nBook Issed Status: %s",[Link]);
getch();
}
C Programming Language by Prof. Vishal Jadhav Sir’s (VJTech Academy, contact us: +91-7743909870) 30
C Language Practical /IMP Programs
C Programming Language by Prof. Vishal Jadhav Sir’s (VJTech Academy, contact us: +91-7743909870) 31
C Language Practical /IMP Programs
Develop and execute C program to Add Two distances given in kilometer-meter using structures.
#include<stdio.h>
#include<conio.h>
struct Distance
{
int km;
};
void main()
{
struct Distance d1,d2;
int add;
clrscr();
printf("\nEnter First Distance:");
scanf("%d",&[Link]);
printf("\nEnter Second Distance:");
scanf("%d",&[Link]);
add=([Link]+[Link]);
printf("\nAddition of two distances: %d",add);
getch();
}
C Programming Language by Prof. Vishal Jadhav Sir’s (VJTech Academy, contact us: +91-7743909870) 32
C Language Practical /IMP Programs
Accept and Display 10 employees ’s information using structure.
#include<stdio.h>
#include<conio.h>
struct Employee
{
int empid;
char name[10];
int salary;
};
void main()
{
struct Employee e[10];
int i;
clrscr();
printf("\nEnter 10 employees details:");
for(i=0;i<10;i++)
{
printf("\nEnter Employee ID:");
scanf("%d",&e[i].empid);
printf("\nEnter Employee Name:");
scanf("%s",&e[i].name);
printf("\nEnter Employee Salary:");
scanf("%d",&e[i].salary);
}
printf("\n******EMPLOYEE INFORMATION******");
printf("\nEMPID\tNAME\tSALARY");
printf("\n==========================");
for(i=0;i<10;i++)
{
printf("\n%d\t%s\t%d",e[i].empid,e[i].name,e[i].salary);
}
getch();
}
C Programming Language by Prof. Vishal Jadhav Sir’s (VJTech Academy, contact us: +91-7743909870) 33
C Language Practical /IMP Programs
Accept and Display 10 books information using structure.
#include<stdio.h>
#include<conio.h>
struct Book
{
int bookid;
char name[10];
int price;
};
void main()
{
struct Book b[10];
int i;
clrscr();
printf("\nEnter 10 Book details:");
for(i=0;i<10;i++)
{
printf("\nEnter Book ID:");
scanf("%d",&b[i].bookid);
printf("\nEnter Book Name:");
scanf("%s",&b[i].name);
printf("\nEnter Book Price:");
scanf("%d",&b[i].price);
}
printf("\n******BOOK INFORMATION******");
printf("\nBOOKID\tNAME\tPRICE");
printf("\n==========================");
for(i=0;i<10;i++)
{
printf("\n%d\t%s\t%d",b[i].bookid,b[i].name,b[i].price);
}
getch();
}
C Programming Language by Prof. Vishal Jadhav Sir’s (VJTech Academy, contact us: +91-7743909870) 34
C Language Practical /IMP Programs
Find factorial of a given number using function
#include<stdio.h>
#include<conio.h>
void fact();
void main()
{
clrscr();
fact();
getch();
}
void fact()
{
int N,fact=1,i;
printf("\nEnter Value of N:");
scanf("%d",&N);
for(i=1;i<=N;i++)
{
fact=fact*i;
}
printf("\nFactorial of given number=%d",fact);
}
C Programming Language by Prof. Vishal Jadhav Sir’s (VJTech Academy, contact us: +91-7743909870) 35
C Language Practical /IMP Programs
Write C program to access and display address of variables.
#include<stdio.h>
#include<conio.h>
void main()
int a,*p;
clrscr();
a=120;
p=&a;
printf("\nValue of a=%d",a);
printf("\nValue of *p=%d",*p);
printf("\nAddress of a=%u",&a);
printf("\nAddress of p=%u",&p);
getch();
C Programming Language by Prof. Vishal Jadhav Sir’s (VJTech Academy, contact us: +91-7743909870) 36
C Language Practical /IMP Programs
Find factorial of a given number using recursion function
#include<stdio.h>
#include<conio.h>
int fact(int N);
void main()
{
int x,result;
clrscr();
printf("\nEnter Value of x:");
scanf("%d",&x);
result=fact(x);
printf("\nFactorial of given number=%d",result);
getch();
}
int fact(int N)
{
if(N==0)
{
return 1;
}
else
{
return(N*fact(N-1));
}
}
C Programming Language by Prof. Vishal Jadhav Sir’s (VJTech Academy, contact us: +91-7743909870) 37
C Language Practical /IMP Programs
Double pointer concept (pointer chain)
#include<stdio.h>
#include<conio.h>
void main()
int i=5,*p,**q,***r;
clrscr();
p=&i;
q=&p;
r=&q;
printf("\n%d %d %d",*p,**q,***r);
getch();
C Programming Language by Prof. Vishal Jadhav Sir’s (VJTech Academy, contact us: +91-7743909870) 38
C Language Practical /IMP Programs
Find output of below program
#include<stdio.h>
#include<conio.h>
void main()
int a=20;
int *b=&a;
int *c=b;
int d=*b+*c;
clrscr();
printf("\nValue of d=%d",d);
getch();
C Programming Language by Prof. Vishal Jadhav Sir’s (VJTech Academy, contact us: +91-7743909870) 39
C Language Practical /IMP Programs
Arithmetic Operations (+,-,*,/) using pointer
#include<stdio.h>
#include<conio.h>
void main()
int a=10,b=5,c,*p1,*p2;
clrscr();
p1=&a;
p2=&b;
c=*p1+*p2;
printf("\nAddition=%d",c);
c=*p1-*p2;
printf("\nSubtraction=%d",c);
c=*p1 * *p2;
printf("\nMultiplication=%d",c);
c=*p1 / *p2;
printf("\nDivision=%d",c);
getch();
C Programming Language by Prof. Vishal Jadhav Sir’s (VJTech Academy, contact us: +91-7743909870) 40
C Language Practical /IMP Programs
Calculate Length of given string without using library functions
#include<stdio.h>
#include<conio.h>
void main()
char str[10];
int len=0,i;
clrscr();
printf("\nEnter any string:");
scanf("%s",&str);
i=0;
while(str[i]!='\0')
len++;
i++;
printf("\nLength of String=%d",len);
getch();
C Programming Language by Prof. Vishal Jadhav Sir’s (VJTech Academy, contact us: +91-7743909870) 41
C Language Practical /IMP Programs
Print reverse of given string without using library functions
#include<stdio.h>
#include<conio.h>
void main()
char str1[10],str2[10];
int i,j;
clrscr();
printf("\nEnter any string:");
scanf("%s",&str1);
i=0;
while(str1[i]!='\0')
i++;
i--;
j=0;
while(i>=0)
str2[j]=str1[i];
i--;
j++;
str2[j]='\0';
printf("\nReverse String=%s",str2);
getch();
C Programming Language by Prof. Vishal Jadhav Sir’s (VJTech Academy, contact us: +91-7743909870) 42
C Language Practical /IMP Programs
Write a C program to accept integer number and display it’s Hexadecimal and octal format
#include<stdio.h>
#include<conio.h>
void main()
int a;
clrscr();
printf("\nEnter Value of a:");
scanf("%d",&a);
printf("\nHexadecimal Number:%x",a);
printf("\nOctal Number:%o",a);
getch();
C Programming Language by Prof. Vishal Jadhav Sir’s (VJTech Academy, contact us: +91-7743909870) 43
C Language Practical /IMP Programs
Write a program in ‘C’ to find whether the entered number is positive or negative.
#include<stdio.h>
#include<conio.h>
void main()
{
int no;
clrscr();
printf("\nEnter any number:");
scanf("%d",&no);
if(no!=0)
{
if(no>0)
{
printf("\nNumber is Positive");
}
else
{
printf("\nNumber is Negative");
}
}
else
{
printf("\nNumber is neither Positive or Negative");
}
getch();
}
C Programming Language by Prof. Vishal Jadhav Sir’s (VJTech Academy, contact us: +91-7743909870) 44
C Language Practical /IMP Programs
Design a program in C to read the n numbers of values in an array and display it in reverse order.
#include<stdio.h>
#include<conio.h>
void main()
{
int a[5],i;
clrscr();
printf("\nEnter five array elements:");
for(i=0;i<5;i++)
{
scanf("%d",&a[i]);
}
printf("\nArray Elements in Reverse Order:");
for(i=4;i>=0;i--)
{
printf("%d\t",a[i]);
}
getch();
}
C Programming Language by Prof. Vishal Jadhav Sir’s (VJTech Academy, contact us: +91-7743909870) 45
C Language Practical /IMP Programs
Write a ‘C’ program to calculate and display sum of five elements from array.
#include<stdio.h>
#include<conio.h>
void main()
{
int a[5],i,sum=0;
clrscr();
printf("\nEnter five array elements:");
for(i=0;i<5;i++)
{
scanf("%d",&a[i]);
}
for(i=0;i<5;i++)
{
sum=sum+a[i];
}
printf("\nSum of array elements=%d",sum);
getch();
}
C Programming Language by Prof. Vishal Jadhav Sir’s (VJTech Academy, contact us: +91-7743909870) 46
C Language Practical /IMP Programs
Declare a structure circle containing data members as radius, area, and perimeter. Accept radius
for one variable from user and find out perimeter and area.
#include<stdio.h>
#include<conio.h>
struct Circle
float radius, area, perimeter;
};
void main()
struct Circle c1;
clrscr();
printf("\nEnter radius of circle:");
scanf("%f",&[Link]);
[Link]=(3.14*[Link]*[Link]);
[Link]=(2*3.14*[Link]);
printf("\nArea of Circle=%f",[Link]);
printf("\nPerimeter of Circl3=%f",[Link]);
getch();
C Programming Language by Prof. Vishal Jadhav Sir’s (VJTech Academy, contact us: +91-7743909870) 47
C Language Practical /IMP Programs
Pointer Arithmetic (+,-,++,--)
#include<stdio.h>
#include<conio.h>
void main()
{
int a=100,*ptr;
clrscr();
ptr=&a;
printf("\nAddress stored in ptr=%u",ptr); //65524
ptr=ptr+2;
printf("\nAddress stored in ptr=%u",ptr); //65528
ptr=ptr-1;
printf("\nAddress stored in ptr=%u",ptr); //65526
ptr++;
printf("\nAddress stored in ptr=%u",ptr); //65528
ptr--;
printf("\nAddress stored in ptr=%u",ptr); //65526
getch();
}
C Programming Language by Prof. Vishal Jadhav Sir’s (VJTech Academy, contact us: +91-7743909870) 48
C Language Practical /IMP Programs
Write the program to accept 10 (ten) numbers from user using array, search and print the location
of a given number.
#include<stdio.h>
#include<conio.h>
void main()
{
int a[5],i,key,flag=0;
clrscr();
printf("\nEnter five array elements:");
for(i=0;i<5;i++)
{
scanf("%d",&a[i]);
}
printf("\nEnter element for searching:");
scanf("%d",&key);
for(i=0;i<5;i++)
{
if(key==a[i])
{
flag=1;
break;
}
}
if(flag==1)
{
printf("\nElement is Found at location %d",i);
}
else
{
printf("\nElement is not Found");
}
getch();
}
C Programming Language by Prof. Vishal Jadhav Sir’s (VJTech Academy, contact us: +91-7743909870) 49
C Language Practical /IMP Programs
Write program to read two strings and find whether they are equal or not.
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char str1[10],str2[10];
int x;
clrscr();
printf("\nEnter first string:");
scanf("%s",&str1);
printf("\nEnter second string:");
scanf("%s",&str2);
x=strcmp(str1,str2);
if(x==0)
{
printf("\nBoth strings are equal");
}
else
{
printf("\nBoth string are not equal");
}
getch();
}
C Programming Language by Prof. Vishal Jadhav Sir’s (VJTech Academy, contact us: +91-7743909870) 50
C Language Practical /IMP Programs
Write program to check whether string is palindrome or not.
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char str1[10],str2[10];
int x;
clrscr();
printf("\nEnter any string:");
scanf("%s",&str1);
strcpy(str2,str1);
strrev(str1);
x=strcmp(str1,str2);
if(x==0)
{
printf("\nPalindrome String");
}
else
{
printf("\nNot Palindrome String");
}
getch();
}
C Programming Language by Prof. Vishal Jadhav Sir’s (VJTech Academy, contact us: +91-7743909870) 51
C Language Practical /IMP Programs
Write a program to calculate sum of all even numbers between 1 to 20.
#include<stdio.h>
#include<conio.h>
void main()
{
int i,sum=0;
clrscr();
for(i=1;i<=20;i++)
{
if(i%2==0)
{
sum=sum+i;
}
}
printf("\nSum of Even Number between 1 to 20 = %d",sum);
getch();
}
C Programming Language by Prof. Vishal Jadhav Sir’s (VJTech Academy, contact us: +91-7743909870) 52
C Language Practical /IMP Programs
Armstrong Number
153 = 1^3+5^3+3^3
= 1 + 125 + 27
= 153
#include<stdio.h>
#include<conio.h>
void main()
{
int no,N,sum=0,rem;
clrscr();
printf("\nEnter any number:");
scanf("%d",&no);
N=no;
while(no>0)
{
rem=no%10;
sum=sum+(rem*rem*rem);
no=no/10;
}
if(N==sum)
{
printf("\nArmstrong Number");
}
else
{
printf("\nNot Armstrong Number");
}
getch();
}
C Programming Language by Prof. Vishal Jadhav Sir’s (VJTech Academy, contact us: +91-7743909870) 53