SlideShare uma empresa Scribd logo
1 de 28
INDEX
S.No. Program Page Date Sign
1. Program in C, to calculate area and circumference of the circle.
2. Program in C, to find the real roots of a quadratic equation.
3. Program in C, to find whether a number is odd or even.
4.
Program in C, to find largest, second largest and smallest among
the given three numbers.
5.
Program in C, to calculate grade of a student having three
subjects .The calculation of grade be according to the condition
as following:
If percentage >=80 then grade A
If percentage>=60 but <80% then grade B
If percentage>=40 but <60% then grade C
Otherwise fail
6. Program in C, to find the reverse of a given integer number.
7. Program in C, to find the factorial of a given number.
8. Program in C, to print prime numbers between 1 to 100.
9.
Program in C, to print the following Series.
a). 1 b). *
2 1 * *
3 2 1 * * *
4 3 2 1 * * * *
10.
Program in C, to perform arithmetic calculations on integers
using switch case statement
11.
Program in C, to find maximum and minimum element in a given
array
12. Program in C, to perform addition of two matrices
13. Program in C, to perform multiplication of two matrices
14. Program in C, to find X to power Y using user defined function
15. Program in C, to swap two numbers using call by reference
16.
Program in C, to generate first 25 Fibonacci numbers using
recursion
S.No. Program Page Date Sign
17.
Program in C, to process the student data –name, class, roll
number using structures
18 Program in C, to compare two strings using strcmp () function
19.
Program in C, to find whether a string is palindrome or not
without using string functions
20. Program in C, to sort given elements of array using bubble sort
21. Program in C, to sort given elements of array using selection sort
22. Program in C, to search an element using linear search
23. Program in C, to search an element using binary search
24. Program in C, to copy contents of one file to another
25.
Program in C, to count number of characters, vowels, constant
and words in a given file.
1. Program in C, to calculate area and circumference of the circle.
#include <stdio.h>
main()
{
float radius , area , circumference;
printf("nEnter Radius : ");
scanf(" %f" , &radius);
do
{
area = 3.14159 * radius * radius;
circumference = 2 * 3.14159 * radius;
printf("nArea = %0.2f" , area);
printf("nCircumference = %0.2f" , circumference);
printf("nEnter new Radius (0 to quit): ");
scanf(" %f" , &radius);
}
while(radius != 0);
}
2. Program in C, to find the real roots of a quadratic equation.
#include <stdio.h>
#include <math.h>
main()
{
float a , b , c , det , x1 , x2 , x;
printf("nEnter the values:");
printf("na = ");
scanf("%f" , &a);
printf("nb = ");
scanf("%f" , &b);
printf("nc = ");
scanf("%f" , &c);
if(a == 0)
{
x = -c/b;
printf("nRoots are Linear:tx = %f" , x);
}
else
{
det = b*b - 4*a*c;
if(det == 0)
{
x = -b / (2*a);
printf("nRoots are Identical:tx1 = x2 = %f" , x);
}
else if(det < 0)
{
printf("nRoots are Complex.");
}
else
{
x1 = (-b + sqrt(det)) / (2*a);
x2 = (-b - sqrt(det)) / (2*a);
printf("nRoots are Real:");
printf("nx1 = %f" , x1);
printf("nx2 = %f" , x2);
}
}
}
3. Program in C, to find whether a number is odd or even.
#include <stdio.h>
void main()
{
int n;
printf("nEnter a Number: ");
scanf("%d" , &n);
if(n%2 == 0)
printf("n%d is EVEN" , n);
else
printf("n%d is ODD" , n);
}
4. Program in C, to find largest, second largest and smallest among the given three numbers.
#include <stdio.h>
main()
{
float n1 , n2 , n3;
printf("nEnter 1st Number: ");
scanf("%f" , &n1);
printf("nEnter 2nd Number: ");
scanf("%f" , &n2);
printf("nEnter 3rd Number: ");
scanf("%f" , &n3);
printf("nSmallest < Second Largest < Largest");
if(n1 < n2 && n2 < n3)
{
printf("n%f < %f < %f" , n1 , n2 , n3);
}
else if(n1 < n3 && n3 < n2)
{
printf("n%f < %f < %f" , n1 , n3 , n2);
}
else if(n2 < n1 && n1 < n3)
{
printf("n%f < %f < %f" , n2 , n1 , n3);
}
else if(n2 < n3 && n2 < n1)
{
printf("n%f < %f < %f" , n2 , n3 , n1);
}
else if(n3 < n1 && n1 < n2)
{
printf("n%f < %f < %f" , n3 , n1 , n2);
}
else if(n3 < n2 && n2 < n1)
{
printf("n%f < %f < %f" , n3 , n2 , n1);
}
}
5.
Program in C, to calculate grade of a student having three subjects .The calculation of
grade be according to the condition as following:
If percentage >=80 then grade A
If percentage>=60 but <80% then grade B
If percentage>=40 but <60% then grade C
Otherwise fail
#include <stdio.h>
main()
{
float p;
printf("nPercentage of Student ? : ");
scanf("%f" , &p);
if(p >= 80)
printf("nGrade = A");
else if(p >= 60 && p < 80)
printf("nGrade = B");
else if(p >= 40 && p < 60)
printf("nGrade = C");
else
printf("nFail");
}
6. Program in C, to find the reverse of a given integer number.
#include <stdio.h>
main()
{
long unsigned n, rev , rem ;
char c;
do
{
rev=0;
printf("nnEnter number: ");
scanf(" %lu" , &n);
while(n > 0)
{
rem = n%10;
rev = rev * 10 + rem;
n = n/10;
}
printf("nReverse of the number is: %lu" , rev);
printf("nnRepeat again? ");
scanf(" %c" , &c);
}
while((c == 'y')||(c == 'Y'));
printf("n<<Good Bye!>>");
}
7. Program in C, to find the factorial of a given number.
#include <stdio.h>
main()
{
int n ;
long unsigned fact = 1 ;
printf("nEnter Number : ");
scanf("%d" , &n);
if(n==1)
printf("%d ! (factorial) = %d" , n , fact);
else
{
for (int i = 1 ; i <= n ; i++)
{
fact = fact * i;
}
printf("%d ! (factorial) = %lu" , n , fact);
}
}
8. Program in C, to print prime numbers between 1 to 100.
#include <stdio.h>
main()
{
int u , l , prime , num , div;
printf("nEnter lower limit: ");
scanf("%d" , &l);
printf("nEnter upper limit: ");
scanf("%d" , &u);
if(l < 2)
{
l = 2;
}
printf("nPrime Number between %d and %d are:n" , l , u);
if(l == 2)
{
printf("%dt" , l);
l++;
}
for(num=l ; num <= u ; num++)
{
for(div=2 ; div <= num-1 ; div++)
{
if(num%div != 0)
{
prime=num;
continue;
}
else
{
prime=0;
break;
}
}
if(prime==0)
continue;
else
printf("%dt" , prime);
}
}
9.
Program in C, to print the following Series.
a). 1 b). *
2 1 * *
3 2 1 * * *
4 3 2 1 * * * *
#include <stdio.h>
main()
{
int rows , n , i;
printf("nHow many rows ? ");
scanf("%d" , &rows);
for ( n = 1 ; n <= rows ; n++ )
{
i=1;
while(i <= n)
{
printf("%dt" , n);
i++;
}
printf("n");
}
}
…………………………………………………………………………………………………………………………………………………………………………………………………….
#include <stdio.h>
main()
{
int rows , i , n;
printf("nHow many rows ? ");
scanf("%d" , &rows);
for(i = 1 ; i <= rows ; i++)
{
for(n = rows-i ; n >= 1 ; n--)
{
printf(" ");
}
n=1;
while(n <= i)
{
printf("* ");
n++;
}
printf("n");
}
}
10. Program in C, to perform arithmetic calculations on integers using switch case statement
#include <stdio.h>
main()
{
float n1 , n2;
char option;
printf("nEnter a number: ");
scanf(" %f",&n1);
printf("nEnter another number: ");
scanf(" %f",&n2);
printf("nSelect an operation:n+ to addn- to subtractn* to
multiplyn/ to dividen");
scanf(" %c",&option);
switch(option)
{
case '+': printf("%ft+t%ft=t%f",n1,n2,n1+n2);
break;
case '-': printf("%ft-t%ft=t%f",n1,n2,n1-n2);
break;
case '*': printf("%ft*t%ft=t%f",n1,n2,n1*n2);
break;
case '/': printf("%ft/t%ft=t%f",n1,n2,n1/n2);
break;
default: printf("nInvalid Option selected");
main();
}
printf("nRepeat Program ? (Y/N) ");
scanf(" %c",&option);
if((option == 'Y') || (option == 'y'))
{
main();
}
else
{
printf("nGood Bye !");
}
}
11. Program in C, to find maximum and minimum element in a given array
#include <stdio.h>
#define size 10
main()
{
float a[size] , min , max;
int i;
printf("nEnter Array Elements:n");
for(i = 0 ; i < size ; i++)
{
printf("nA[%d] = ",i+1);
scanf("%f",&a[i]);
}
max = a[0];
min = a[0];
for(i = 1 ; i < size ; i++)
{
if(a[i] > max)
{
max = a[i];
}
if(a[i] < min)
{
min = a[i];
}
}
printf("nMaximum value = %0.2f" , max);
printf("nMinimum value = %0.2f" , min);
}
12. Program in C, to perform addition of two matrices
#include <stdio.h>
#define rows 3
#define cols 3
main()
{
int a[rows][cols] , b[rows][cols] , i , j;
printf("nEnter Elements for Matrix - An");
for(i = 0 ; i < rows ; i++)
{
for(j = 0 ; j < cols ; j++)
{
printf("A[%d][%d] = ", i,j);
scanf("%d" , &a[i][j]);
}
}
printf("nEnter Elements for Matrix - Bn");
for(i = 0 ; i < rows ; i++)
{
for(j = 0 ; j < cols ; j++)
{
printf("B[%d][%d] = ", i,j);
scanf("%d" , &b[i][j]);
a[i][j] += b[i][j];
}
}
printf("nA + Ba");
for(i = 0 ; i < rows ; i++)
{
printf("n");
for(j = 0 ; j < cols ; j++)
{
printf("%dt", a[i][j]);
}
}
}
13. Program in C, to perform multiplication of two matrices
#include <stdio.h>
main()
{
int a[3][3] , b[3][3] , c[3][3] , i , j , k;
printf("nEnter Elements for Matrix - Ana");
for(i = 0 ; i < 3 ; i++)
{
for(j = 0 ; j < 3 ; j++)
{
printf("A[%d][%d] = ", i,j);
scanf("%d" , &a[i][j]);
}
}
printf("nEnter Elements for Matrix - Bna");
for(i = 0 ; i < 3 ; i++)
{
for(j = 0 ; j < 3 ; j++)
{
printf("B[%d][%d] = ", i,j);
scanf("%d" , &b[i][j]);
}
}
for(i = 0 ; i < 3 ; i++)
{
for(j = 0 ; j < 3 ; j++)
{
c[i][j] = 0;
for(k = 0 ; k < 3 ; k++)
{
c[i][j]=c[i][j]+(a[i][k]*b[k][j]);
}
}
}
printf("nA x B:na");
for(i = 0 ; i < 3 ; i++)
{
printf("n");
for(j = 0 ; j < 3 ; j++)
{
printf("%dt", c[i][j]);
}
}
}
14. Program in C, to find X to power Y using user defined function
#include<stdio.h>
int power_function(int , int);
main()
{
int number , power , i , result;
printf("Enter Number: ");
scanf("%d",&number);
printf("Enter power: ");
scanf("%d",&power);
printf("%d raised to the power %d is %d",number , power,
power_function(number , power));
}
int power_function(int num , int pow)
{
int i , res = num;
for(i = 1 ; i < pow ; i++)
{
res = res * num;
}
return res;
}
15. Program in C, to swap two numbers using call by reference
#include<stdio.h>
#include<conio.h>
void swap (int *a , int *b);
main()
{
int a,b,*aa,*bb;
clrscr();
a=1234;
b=5678;
aa=&a;
bb=&b;
printf("nnValue of a = %d & Value of b = %d before swapping",a,b);
swap(aa,bb);
printf("nnValue of a = %d & Value of b = %d after swapping",a,b);
getch();
}
void swap(int *x,int *y)
{
int temp;
temp=*x;
*x=*y;
*y=temp;
}
16. Program in C, to generate first 25 Fibonacci numbers using recursion
#include<stdio.h>
void fibonacci (long unsigned prev_num, long unsigned next_num);
main()
{
static double prev_num=0, next_num=1;
printf ("nFollowing are the first 25 Numbers of the Fibonacci
Series:n");
printf("n%u",prev_num + next_num);
fibonacci (prev_num , next_num);
}
void fibonacci (long unsigned prev_num, long unsigned next_num)
{
static int i=1;
long unsigned fibo;
fibo = prev_num + next_num;
if (i == 25)
{
printf ("naDone..!");
}
else
{
printf ("n%lu", fibo);
prev_num = next_num;
next_num = fibo;
i++;
fibonacci (prev_num , next_num);//recursion
}
}
17. Program in C, to process the student data – name, class, roll number using structures
#include<stdio.h>
main()
{
struct student
{
char s_name[30];
char s_class[10];
int s_num;
};
student s1;
printf("nEnter data for Student:n");
printf("nName: ");
gets(s1.s_name);
printf("nClass: ");
gets(s1.s_class);
printf("nRoll Number: ");
scanf("%d", &s1.s_num);
printf("n-------------------------nData Entered by you is:n");
printf("nName: ");
puts(s1.s_name);
printf("nClass: ");
puts(s1.s_class);
printf("nRoll Number: %d", s1.s_num);
}
18 Program in C, to compare two strings using strcmp () function
#include<stdio.h>
#include<string.h>
main()
{
char str_1[20] , str_2[20];
printf("String_1: "); gets(str_1);
printf("String_2: "); gets(str_2);
int i = strcmp (str_1 , str_2);
if (i == 0)
puts("nComparison Result: Strings are Equal");
if(i < 0)
puts("nComparison Result: Strings NOT Equal, String_1 is smaller");
if(i > 0)
puts("nComparison Result: Strings NOT Equal, String_2 is smaller");
}
19. Program in C, to find whether a string is palindrome or not without using string functions
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char s1[20] , s2[20];
clrscr();
printf("nEnter a string: ");
scanf("%s",s1);
strcpy(s2 , s1);
strrev(s2);
if(strcmp(s1,s2)==0)
printf(""%s" is a PALINDROME",s1);
else
printf(""%s" is NOT a PALINDROME",s1);
getch();
}
20. Program in C, to sort given elements of array using bubble sort
#include <stdio.h>
#define size 50
main()
{
int a[size] , i , j , temp , value , n = 0 , index = -1;
printf("nEnter Array Elements:n[Enter 0 (zero) to Stop]n");
for( i = 0 ; i < size ; i++)
{
printf("nA[%d] = ",i);
scanf("%d", &value);
if(value == 0)
{
break;
}
else
{
a[i] = value;
n++;
}
}
puts("nnThe Array you have Entered is:n");
for (i = 0 ; i < n ; i++)
{
printf("nA[%d] = %d", i , a[i]);
}
for (i = 0 ; i < n ; i++)
{
for (j = i+1 ; j < n ; j++)
{
if(a[i] > a[j])
{
temp = a[i];
a[i] = a[j];
a[j] = temp;
}
}
}
puts("nnAfter Bubble Sort:n");
for (i = 0 ; i < n ; i++)
{
printf("nA[%d] = %d", i , a[i]);
}
}
21. Program in C, to sort given elements of array using selection sort
22. Program in C, to search an element using linear search
#include <stdio.h>
#define size 50
main()
{
int a[size] , i , value , n = 0 , index = -1;
printf("nEnter Array Elements:n[Enter 0 (zero) to Stop]n");
for( i = 0 ; i < size ; i++)
{
printf("nA[%d] = ",i);
scanf("%d", &value);
if(value == 0)
{
break;
}
else
{
a[i] = value;
n++;
}
}
for (i = 0 ; i < n ; i++)
{
printf("nA[%d] = %d", i , a[i]);
}
printf("nnEnter Item to Search: ");
scanf("%d",&value);
for (i = 0 ; i <= n ; i++)
{
if(a[i] == value)
{
index = i;
break;
}
}
if(index == -1)
{
printf("nItem not found");
}
else
{
printf("nItem found at Index: %d", index);
}
}
23. Program in C, to search an element using binary search
#include <stdio.h>
#define size 50
main()
{
int a[size] , i , j , temp , value , n = 0 , index , beg , end , mid;
printf("nEnter Array Elements:n[Enter 0 (zero) to Stop]n");
for( i = 0 ; i < size ; i++)
{
printf("nA[%d] = ",i);
scanf("%d", &value);
if(value == 0)
{
break;
}
else
{
a[i] = value;
n++;
}
}
for (i = 0 ; i < n-1 ; i++)
{
for (j = i+1 ; j < n ; j++)
{
if(a[i] > a[j])
{
temp = a[i];
a[i] = a[j];
a[j] = temp;
}
}
}
printf("nnArray after Bubble Sort:");
for (i = 0 ; i < n ; i++)
{
printf("nA[%d] = %d", i , a[i]);
}
printf("nnEnter Item to search: ");
scanf("%d" , &value);
index = -1;
beg = 0;
end = n-1;
mid = (beg + end) / 2;
while(end >= beg)
{
mid = (beg + end) / 2;
if(value == a[mid])
{
index = mid;
break;
}
else if(value < a[mid])
{
end = mid-1;
continue;
}
else if(value > a[mid])
{
beg = mid+1;
continue;
}
}
if(index < 0)
{
printf("nItem not Found");
}
else
{
printf("Item Found at Index: %d" , index);
}
}
24. Program in C, to copy contents of one file to another
25. Program in C, to count number of characters, vowels, constant and words in a given file.

Mais conteúdo relacionado

Mais procurados

Practical write a c program to reverse a given number
Practical write a c program to reverse a given numberPractical write a c program to reverse a given number
Practical write a c program to reverse a given numberMainak Sasmal
 
Practical File of C Language
Practical File of C LanguagePractical File of C Language
Practical File of C LanguageRAJWANT KAUR
 
C programs
C programsC programs
C programsMinu S
 
C program to check leap year
C program to check leap year C program to check leap year
C program to check leap year mohdshanu
 
Chapter 8 c solution
Chapter 8 c solutionChapter 8 c solution
Chapter 8 c solutionAzhar Javed
 
Computer programming subject notes. Quick easy notes for C Programming.Cheat ...
Computer programming subject notes. Quick easy notes for C Programming.Cheat ...Computer programming subject notes. Quick easy notes for C Programming.Cheat ...
Computer programming subject notes. Quick easy notes for C Programming.Cheat ...DR B.Surendiran .
 
Simple C programs
Simple C programsSimple C programs
Simple C programsab11cs001
 
The solution manual of c by robin
The solution manual of c by robinThe solution manual of c by robin
The solution manual of c by robinAbdullah Al Naser
 
Core programming in c
Core programming in cCore programming in c
Core programming in cRahul Pandit
 
Basic c programs updated on 31.8.2020
Basic c programs updated on 31.8.2020Basic c programs updated on 31.8.2020
Basic c programs updated on 31.8.2020vrgokila
 
Data Structure using C
Data Structure using CData Structure using C
Data Structure using CBilal Mirza
 
LET US C (5th EDITION) CHAPTER 1 ANSWERS
LET US C (5th EDITION) CHAPTER 1 ANSWERSLET US C (5th EDITION) CHAPTER 1 ANSWERS
LET US C (5th EDITION) CHAPTER 1 ANSWERSKavyaSharma65
 
B.Com 1year Lab programs
B.Com 1year Lab programsB.Com 1year Lab programs
B.Com 1year Lab programsPrasadu Peddi
 
Programming in C Lab
Programming in C LabProgramming in C Lab
Programming in C LabNeil Mathew
 
Practical write a c program to reverse a given number
Practical write a c program to reverse a given numberPractical write a c program to reverse a given number
Practical write a c program to reverse a given numberMainak Sasmal
 
C- Programming Assignment 4 solution
C- Programming Assignment 4 solutionC- Programming Assignment 4 solution
C- Programming Assignment 4 solutionAnimesh Chaturvedi
 

Mais procurados (20)

Practical write a c program to reverse a given number
Practical write a c program to reverse a given numberPractical write a c program to reverse a given number
Practical write a c program to reverse a given number
 
Practical File of C Language
Practical File of C LanguagePractical File of C Language
Practical File of C Language
 
C programs
C programsC programs
C programs
 
C program to check leap year
C program to check leap year C program to check leap year
C program to check leap year
 
SaraPIC
SaraPICSaraPIC
SaraPIC
 
Chapter 8 c solution
Chapter 8 c solutionChapter 8 c solution
Chapter 8 c solution
 
Computer programming subject notes. Quick easy notes for C Programming.Cheat ...
Computer programming subject notes. Quick easy notes for C Programming.Cheat ...Computer programming subject notes. Quick easy notes for C Programming.Cheat ...
Computer programming subject notes. Quick easy notes for C Programming.Cheat ...
 
Simple C programs
Simple C programsSimple C programs
Simple C programs
 
The solution manual of c by robin
The solution manual of c by robinThe solution manual of c by robin
The solution manual of c by robin
 
Core programming in c
Core programming in cCore programming in c
Core programming in c
 
Basic c programs updated on 31.8.2020
Basic c programs updated on 31.8.2020Basic c programs updated on 31.8.2020
Basic c programs updated on 31.8.2020
 
Data Structure using C
Data Structure using CData Structure using C
Data Structure using C
 
LET US C (5th EDITION) CHAPTER 1 ANSWERS
LET US C (5th EDITION) CHAPTER 1 ANSWERSLET US C (5th EDITION) CHAPTER 1 ANSWERS
LET US C (5th EDITION) CHAPTER 1 ANSWERS
 
C Programming
C ProgrammingC Programming
C Programming
 
C lab manaual
C lab manaualC lab manaual
C lab manaual
 
B.Com 1year Lab programs
B.Com 1year Lab programsB.Com 1year Lab programs
B.Com 1year Lab programs
 
Programming in C Lab
Programming in C LabProgramming in C Lab
Programming in C Lab
 
Practical write a c program to reverse a given number
Practical write a c program to reverse a given numberPractical write a c program to reverse a given number
Practical write a c program to reverse a given number
 
88 c-programs
88 c-programs88 c-programs
88 c-programs
 
C- Programming Assignment 4 solution
C- Programming Assignment 4 solutionC- Programming Assignment 4 solution
C- Programming Assignment 4 solution
 

Semelhante a C-programs (20)

C file
C fileC file
C file
 
C Programming Example
C Programming ExampleC Programming Example
C Programming Example
 
Progr3
Progr3Progr3
Progr3
 
Numerical analysis
Numerical analysisNumerical analysis
Numerical analysis
 
C lab
C labC lab
C lab
 
C Programming Exam problems & Solution by sazzad hossain
C Programming Exam problems & Solution by sazzad hossainC Programming Exam problems & Solution by sazzad hossain
C Programming Exam problems & Solution by sazzad hossain
 
C programs
C programsC programs
C programs
 
c programs.pptx
c programs.pptxc programs.pptx
c programs.pptx
 
'C' language notes (a.p)
'C' language notes (a.p)'C' language notes (a.p)
'C' language notes (a.p)
 
C programming codes for the class assignment
C programming codes for the class assignmentC programming codes for the class assignment
C programming codes for the class assignment
 
Basic C Programming Lab Practice
Basic C Programming Lab PracticeBasic C Programming Lab Practice
Basic C Programming Lab Practice
 
DSC program.pdf
DSC program.pdfDSC program.pdf
DSC program.pdf
 
C programms
C programmsC programms
C programms
 
C lab programs
C lab programsC lab programs
C lab programs
 
C lab programs
C lab programsC lab programs
C lab programs
 
week-3x
week-3xweek-3x
week-3x
 
C faq pdf
C faq pdfC faq pdf
C faq pdf
 
C basics
C basicsC basics
C basics
 
ADA FILE
ADA FILEADA FILE
ADA FILE
 
Write a program to check a given number is prime or not
Write a program to check a given number is prime or notWrite a program to check a given number is prime or not
Write a program to check a given number is prime or not
 

Mais de SSGMCE SHEGAON

Unit-1 intro to communication networks
Unit-1 intro to communication networksUnit-1 intro to communication networks
Unit-1 intro to communication networksSSGMCE SHEGAON
 
Insulating materials- electrial
Insulating materials- electrialInsulating materials- electrial
Insulating materials- electrialSSGMCE SHEGAON
 
Digital communication (DSSS)
Digital communication  (DSSS)Digital communication  (DSSS)
Digital communication (DSSS)SSGMCE SHEGAON
 
Microcontrollers and RT programming 3
Microcontrollers and RT programming 3Microcontrollers and RT programming 3
Microcontrollers and RT programming 3SSGMCE SHEGAON
 
Lect 2 loudspeakers (instrumentation)
Lect 2 loudspeakers (instrumentation)Lect 2 loudspeakers (instrumentation)
Lect 2 loudspeakers (instrumentation)SSGMCE SHEGAON
 
Microcontrollers and intro to real time programming 1
Microcontrollers and intro to real time programming 1Microcontrollers and intro to real time programming 1
Microcontrollers and intro to real time programming 1SSGMCE SHEGAON
 
Android automation tools
Android automation toolsAndroid automation tools
Android automation toolsSSGMCE SHEGAON
 
Android mobile cotrolled robot (wi fi)
Android mobile cotrolled robot (wi fi)Android mobile cotrolled robot (wi fi)
Android mobile cotrolled robot (wi fi)SSGMCE SHEGAON
 
Khushwant singh's joke book 5
Khushwant singh's joke book 5Khushwant singh's joke book 5
Khushwant singh's joke book 5SSGMCE SHEGAON
 

Mais de SSGMCE SHEGAON (10)

Unit-1 intro to communication networks
Unit-1 intro to communication networksUnit-1 intro to communication networks
Unit-1 intro to communication networks
 
Insulating materials- electrial
Insulating materials- electrialInsulating materials- electrial
Insulating materials- electrial
 
Digital communication (DSSS)
Digital communication  (DSSS)Digital communication  (DSSS)
Digital communication (DSSS)
 
Microcontrollers and RT programming 3
Microcontrollers and RT programming 3Microcontrollers and RT programming 3
Microcontrollers and RT programming 3
 
Lect 2 loudspeakers (instrumentation)
Lect 2 loudspeakers (instrumentation)Lect 2 loudspeakers (instrumentation)
Lect 2 loudspeakers (instrumentation)
 
Microcontrollers and intro to real time programming 1
Microcontrollers and intro to real time programming 1Microcontrollers and intro to real time programming 1
Microcontrollers and intro to real time programming 1
 
Android automation tools
Android automation toolsAndroid automation tools
Android automation tools
 
Android mobile cotrolled robot (wi fi)
Android mobile cotrolled robot (wi fi)Android mobile cotrolled robot (wi fi)
Android mobile cotrolled robot (wi fi)
 
Khushwant singh's joke book 5
Khushwant singh's joke book 5Khushwant singh's joke book 5
Khushwant singh's joke book 5
 
7th sem syllabus
7th sem syllabus 7th sem syllabus
7th sem syllabus
 

Último

An Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdfAn Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdfSanaAli374401
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin ClassesCeline George
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxVishalSingh1417
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingTeacherCyreneCayanan
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxnegromaestrong
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxVishalSingh1417
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxAreebaZafar22
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 

Último (20)

Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
An Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdfAn Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdf
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writing
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 

C-programs

  • 1. INDEX S.No. Program Page Date Sign 1. Program in C, to calculate area and circumference of the circle. 2. Program in C, to find the real roots of a quadratic equation. 3. Program in C, to find whether a number is odd or even. 4. Program in C, to find largest, second largest and smallest among the given three numbers. 5. Program in C, to calculate grade of a student having three subjects .The calculation of grade be according to the condition as following: If percentage >=80 then grade A If percentage>=60 but <80% then grade B If percentage>=40 but <60% then grade C Otherwise fail 6. Program in C, to find the reverse of a given integer number. 7. Program in C, to find the factorial of a given number. 8. Program in C, to print prime numbers between 1 to 100. 9. Program in C, to print the following Series. a). 1 b). * 2 1 * * 3 2 1 * * * 4 3 2 1 * * * * 10. Program in C, to perform arithmetic calculations on integers using switch case statement 11. Program in C, to find maximum and minimum element in a given array 12. Program in C, to perform addition of two matrices 13. Program in C, to perform multiplication of two matrices 14. Program in C, to find X to power Y using user defined function 15. Program in C, to swap two numbers using call by reference 16. Program in C, to generate first 25 Fibonacci numbers using recursion
  • 2. S.No. Program Page Date Sign 17. Program in C, to process the student data –name, class, roll number using structures 18 Program in C, to compare two strings using strcmp () function 19. Program in C, to find whether a string is palindrome or not without using string functions 20. Program in C, to sort given elements of array using bubble sort 21. Program in C, to sort given elements of array using selection sort 22. Program in C, to search an element using linear search 23. Program in C, to search an element using binary search 24. Program in C, to copy contents of one file to another 25. Program in C, to count number of characters, vowels, constant and words in a given file.
  • 3. 1. Program in C, to calculate area and circumference of the circle. #include <stdio.h> main() { float radius , area , circumference; printf("nEnter Radius : "); scanf(" %f" , &radius); do { area = 3.14159 * radius * radius; circumference = 2 * 3.14159 * radius; printf("nArea = %0.2f" , area); printf("nCircumference = %0.2f" , circumference); printf("nEnter new Radius (0 to quit): "); scanf(" %f" , &radius); } while(radius != 0); }
  • 4. 2. Program in C, to find the real roots of a quadratic equation. #include <stdio.h> #include <math.h> main() { float a , b , c , det , x1 , x2 , x; printf("nEnter the values:"); printf("na = "); scanf("%f" , &a); printf("nb = "); scanf("%f" , &b); printf("nc = "); scanf("%f" , &c); if(a == 0) { x = -c/b; printf("nRoots are Linear:tx = %f" , x); } else { det = b*b - 4*a*c; if(det == 0) { x = -b / (2*a); printf("nRoots are Identical:tx1 = x2 = %f" , x); } else if(det < 0) { printf("nRoots are Complex."); } else { x1 = (-b + sqrt(det)) / (2*a); x2 = (-b - sqrt(det)) / (2*a); printf("nRoots are Real:"); printf("nx1 = %f" , x1); printf("nx2 = %f" , x2); } } }
  • 5. 3. Program in C, to find whether a number is odd or even. #include <stdio.h> void main() { int n; printf("nEnter a Number: "); scanf("%d" , &n); if(n%2 == 0) printf("n%d is EVEN" , n); else printf("n%d is ODD" , n); }
  • 6. 4. Program in C, to find largest, second largest and smallest among the given three numbers. #include <stdio.h> main() { float n1 , n2 , n3; printf("nEnter 1st Number: "); scanf("%f" , &n1); printf("nEnter 2nd Number: "); scanf("%f" , &n2); printf("nEnter 3rd Number: "); scanf("%f" , &n3); printf("nSmallest < Second Largest < Largest"); if(n1 < n2 && n2 < n3) { printf("n%f < %f < %f" , n1 , n2 , n3); } else if(n1 < n3 && n3 < n2) { printf("n%f < %f < %f" , n1 , n3 , n2); } else if(n2 < n1 && n1 < n3) { printf("n%f < %f < %f" , n2 , n1 , n3); } else if(n2 < n3 && n2 < n1) { printf("n%f < %f < %f" , n2 , n3 , n1); } else if(n3 < n1 && n1 < n2) { printf("n%f < %f < %f" , n3 , n1 , n2); } else if(n3 < n2 && n2 < n1) { printf("n%f < %f < %f" , n3 , n2 , n1); } }
  • 7. 5. Program in C, to calculate grade of a student having three subjects .The calculation of grade be according to the condition as following: If percentage >=80 then grade A If percentage>=60 but <80% then grade B If percentage>=40 but <60% then grade C Otherwise fail #include <stdio.h> main() { float p; printf("nPercentage of Student ? : "); scanf("%f" , &p); if(p >= 80) printf("nGrade = A"); else if(p >= 60 && p < 80) printf("nGrade = B"); else if(p >= 40 && p < 60) printf("nGrade = C"); else printf("nFail"); }
  • 8. 6. Program in C, to find the reverse of a given integer number. #include <stdio.h> main() { long unsigned n, rev , rem ; char c; do { rev=0; printf("nnEnter number: "); scanf(" %lu" , &n); while(n > 0) { rem = n%10; rev = rev * 10 + rem; n = n/10; } printf("nReverse of the number is: %lu" , rev); printf("nnRepeat again? "); scanf(" %c" , &c); } while((c == 'y')||(c == 'Y')); printf("n<<Good Bye!>>"); }
  • 9. 7. Program in C, to find the factorial of a given number. #include <stdio.h> main() { int n ; long unsigned fact = 1 ; printf("nEnter Number : "); scanf("%d" , &n); if(n==1) printf("%d ! (factorial) = %d" , n , fact); else { for (int i = 1 ; i <= n ; i++) { fact = fact * i; } printf("%d ! (factorial) = %lu" , n , fact); } }
  • 10. 8. Program in C, to print prime numbers between 1 to 100. #include <stdio.h> main() { int u , l , prime , num , div; printf("nEnter lower limit: "); scanf("%d" , &l); printf("nEnter upper limit: "); scanf("%d" , &u); if(l < 2) { l = 2; } printf("nPrime Number between %d and %d are:n" , l , u); if(l == 2) { printf("%dt" , l); l++; } for(num=l ; num <= u ; num++) { for(div=2 ; div <= num-1 ; div++) { if(num%div != 0) { prime=num; continue; } else { prime=0; break; } } if(prime==0) continue; else printf("%dt" , prime); } }
  • 11. 9. Program in C, to print the following Series. a). 1 b). * 2 1 * * 3 2 1 * * * 4 3 2 1 * * * * #include <stdio.h> main() { int rows , n , i; printf("nHow many rows ? "); scanf("%d" , &rows); for ( n = 1 ; n <= rows ; n++ ) { i=1; while(i <= n) { printf("%dt" , n); i++; } printf("n"); } } ……………………………………………………………………………………………………………………………………………………………………………………………………. #include <stdio.h> main() { int rows , i , n; printf("nHow many rows ? "); scanf("%d" , &rows); for(i = 1 ; i <= rows ; i++) { for(n = rows-i ; n >= 1 ; n--) { printf(" "); } n=1; while(n <= i) { printf("* "); n++; } printf("n"); } }
  • 12. 10. Program in C, to perform arithmetic calculations on integers using switch case statement #include <stdio.h> main() { float n1 , n2; char option; printf("nEnter a number: "); scanf(" %f",&n1); printf("nEnter another number: "); scanf(" %f",&n2); printf("nSelect an operation:n+ to addn- to subtractn* to multiplyn/ to dividen"); scanf(" %c",&option); switch(option) { case '+': printf("%ft+t%ft=t%f",n1,n2,n1+n2); break; case '-': printf("%ft-t%ft=t%f",n1,n2,n1-n2); break; case '*': printf("%ft*t%ft=t%f",n1,n2,n1*n2); break; case '/': printf("%ft/t%ft=t%f",n1,n2,n1/n2); break; default: printf("nInvalid Option selected"); main(); } printf("nRepeat Program ? (Y/N) "); scanf(" %c",&option); if((option == 'Y') || (option == 'y')) { main(); } else { printf("nGood Bye !"); } }
  • 13. 11. Program in C, to find maximum and minimum element in a given array #include <stdio.h> #define size 10 main() { float a[size] , min , max; int i; printf("nEnter Array Elements:n"); for(i = 0 ; i < size ; i++) { printf("nA[%d] = ",i+1); scanf("%f",&a[i]); } max = a[0]; min = a[0]; for(i = 1 ; i < size ; i++) { if(a[i] > max) { max = a[i]; } if(a[i] < min) { min = a[i]; } } printf("nMaximum value = %0.2f" , max); printf("nMinimum value = %0.2f" , min); }
  • 14. 12. Program in C, to perform addition of two matrices #include <stdio.h> #define rows 3 #define cols 3 main() { int a[rows][cols] , b[rows][cols] , i , j; printf("nEnter Elements for Matrix - An"); for(i = 0 ; i < rows ; i++) { for(j = 0 ; j < cols ; j++) { printf("A[%d][%d] = ", i,j); scanf("%d" , &a[i][j]); } } printf("nEnter Elements for Matrix - Bn"); for(i = 0 ; i < rows ; i++) { for(j = 0 ; j < cols ; j++) { printf("B[%d][%d] = ", i,j); scanf("%d" , &b[i][j]); a[i][j] += b[i][j]; } } printf("nA + Ba"); for(i = 0 ; i < rows ; i++) { printf("n"); for(j = 0 ; j < cols ; j++) { printf("%dt", a[i][j]); } } }
  • 15. 13. Program in C, to perform multiplication of two matrices #include <stdio.h> main() { int a[3][3] , b[3][3] , c[3][3] , i , j , k; printf("nEnter Elements for Matrix - Ana"); for(i = 0 ; i < 3 ; i++) { for(j = 0 ; j < 3 ; j++) { printf("A[%d][%d] = ", i,j); scanf("%d" , &a[i][j]); } } printf("nEnter Elements for Matrix - Bna"); for(i = 0 ; i < 3 ; i++) { for(j = 0 ; j < 3 ; j++) { printf("B[%d][%d] = ", i,j); scanf("%d" , &b[i][j]); } } for(i = 0 ; i < 3 ; i++) { for(j = 0 ; j < 3 ; j++) { c[i][j] = 0; for(k = 0 ; k < 3 ; k++) { c[i][j]=c[i][j]+(a[i][k]*b[k][j]); } } } printf("nA x B:na"); for(i = 0 ; i < 3 ; i++) { printf("n"); for(j = 0 ; j < 3 ; j++) { printf("%dt", c[i][j]); } } }
  • 16. 14. Program in C, to find X to power Y using user defined function #include<stdio.h> int power_function(int , int); main() { int number , power , i , result; printf("Enter Number: "); scanf("%d",&number); printf("Enter power: "); scanf("%d",&power); printf("%d raised to the power %d is %d",number , power, power_function(number , power)); } int power_function(int num , int pow) { int i , res = num; for(i = 1 ; i < pow ; i++) { res = res * num; } return res; }
  • 17. 15. Program in C, to swap two numbers using call by reference #include<stdio.h> #include<conio.h> void swap (int *a , int *b); main() { int a,b,*aa,*bb; clrscr(); a=1234; b=5678; aa=&a; bb=&b; printf("nnValue of a = %d & Value of b = %d before swapping",a,b); swap(aa,bb); printf("nnValue of a = %d & Value of b = %d after swapping",a,b); getch(); } void swap(int *x,int *y) { int temp; temp=*x; *x=*y; *y=temp; }
  • 18. 16. Program in C, to generate first 25 Fibonacci numbers using recursion #include<stdio.h> void fibonacci (long unsigned prev_num, long unsigned next_num); main() { static double prev_num=0, next_num=1; printf ("nFollowing are the first 25 Numbers of the Fibonacci Series:n"); printf("n%u",prev_num + next_num); fibonacci (prev_num , next_num); } void fibonacci (long unsigned prev_num, long unsigned next_num) { static int i=1; long unsigned fibo; fibo = prev_num + next_num; if (i == 25) { printf ("naDone..!"); } else { printf ("n%lu", fibo); prev_num = next_num; next_num = fibo; i++; fibonacci (prev_num , next_num);//recursion } }
  • 19. 17. Program in C, to process the student data – name, class, roll number using structures #include<stdio.h> main() { struct student { char s_name[30]; char s_class[10]; int s_num; }; student s1; printf("nEnter data for Student:n"); printf("nName: "); gets(s1.s_name); printf("nClass: "); gets(s1.s_class); printf("nRoll Number: "); scanf("%d", &s1.s_num); printf("n-------------------------nData Entered by you is:n"); printf("nName: "); puts(s1.s_name); printf("nClass: "); puts(s1.s_class); printf("nRoll Number: %d", s1.s_num); }
  • 20. 18 Program in C, to compare two strings using strcmp () function #include<stdio.h> #include<string.h> main() { char str_1[20] , str_2[20]; printf("String_1: "); gets(str_1); printf("String_2: "); gets(str_2); int i = strcmp (str_1 , str_2); if (i == 0) puts("nComparison Result: Strings are Equal"); if(i < 0) puts("nComparison Result: Strings NOT Equal, String_1 is smaller"); if(i > 0) puts("nComparison Result: Strings NOT Equal, String_2 is smaller"); }
  • 21. 19. Program in C, to find whether a string is palindrome or not without using string functions #include<stdio.h> #include<conio.h> #include<string.h> void main() { char s1[20] , s2[20]; clrscr(); printf("nEnter a string: "); scanf("%s",s1); strcpy(s2 , s1); strrev(s2); if(strcmp(s1,s2)==0) printf(""%s" is a PALINDROME",s1); else printf(""%s" is NOT a PALINDROME",s1); getch(); }
  • 22. 20. Program in C, to sort given elements of array using bubble sort #include <stdio.h> #define size 50 main() { int a[size] , i , j , temp , value , n = 0 , index = -1; printf("nEnter Array Elements:n[Enter 0 (zero) to Stop]n"); for( i = 0 ; i < size ; i++) { printf("nA[%d] = ",i); scanf("%d", &value); if(value == 0) { break; } else { a[i] = value; n++; } } puts("nnThe Array you have Entered is:n"); for (i = 0 ; i < n ; i++) { printf("nA[%d] = %d", i , a[i]); } for (i = 0 ; i < n ; i++) { for (j = i+1 ; j < n ; j++) { if(a[i] > a[j]) { temp = a[i]; a[i] = a[j]; a[j] = temp; } } } puts("nnAfter Bubble Sort:n"); for (i = 0 ; i < n ; i++) { printf("nA[%d] = %d", i , a[i]); } }
  • 23. 21. Program in C, to sort given elements of array using selection sort
  • 24. 22. Program in C, to search an element using linear search #include <stdio.h> #define size 50 main() { int a[size] , i , value , n = 0 , index = -1; printf("nEnter Array Elements:n[Enter 0 (zero) to Stop]n"); for( i = 0 ; i < size ; i++) { printf("nA[%d] = ",i); scanf("%d", &value); if(value == 0) { break; } else { a[i] = value; n++; } } for (i = 0 ; i < n ; i++) { printf("nA[%d] = %d", i , a[i]); } printf("nnEnter Item to Search: "); scanf("%d",&value); for (i = 0 ; i <= n ; i++) { if(a[i] == value) { index = i; break; } } if(index == -1) { printf("nItem not found"); } else { printf("nItem found at Index: %d", index); } }
  • 25. 23. Program in C, to search an element using binary search #include <stdio.h> #define size 50 main() { int a[size] , i , j , temp , value , n = 0 , index , beg , end , mid; printf("nEnter Array Elements:n[Enter 0 (zero) to Stop]n"); for( i = 0 ; i < size ; i++) { printf("nA[%d] = ",i); scanf("%d", &value); if(value == 0) { break; } else { a[i] = value; n++; } } for (i = 0 ; i < n-1 ; i++) { for (j = i+1 ; j < n ; j++) { if(a[i] > a[j]) { temp = a[i]; a[i] = a[j]; a[j] = temp; } } } printf("nnArray after Bubble Sort:"); for (i = 0 ; i < n ; i++) { printf("nA[%d] = %d", i , a[i]); } printf("nnEnter Item to search: "); scanf("%d" , &value); index = -1; beg = 0; end = n-1; mid = (beg + end) / 2; while(end >= beg) { mid = (beg + end) / 2;
  • 26. if(value == a[mid]) { index = mid; break; } else if(value < a[mid]) { end = mid-1; continue; } else if(value > a[mid]) { beg = mid+1; continue; } } if(index < 0) { printf("nItem not Found"); } else { printf("Item Found at Index: %d" , index); } }
  • 27. 24. Program in C, to copy contents of one file to another
  • 28. 25. Program in C, to count number of characters, vowels, constant and words in a given file.