You are on page 1of 17

Program to find Armstrong Numbers within a limit

#include<stdio.h>
#include<conio.h>
void main()
{
int l,u,k,rem,sum,temp;
clrscr();
printf("================================\n\n");
printf("Finding Armstrong Numbers within limit\n\n");
printf("================================\n\n");
printf("Enter Lower limit & Upper Limit\n");
scanf("%d%d",&l,&u);
for(k=l;k<=u;k++)
{
sum=0;
temp=k;
while(temp>0)
{
rem = temp%10;
sum = sum+(rem*rem*rem);
temp = temp/10;
}
if(sum==k)
printf("\n%d",k);
}
getch();
}
OUTPUT
================================
Finding Armstrong Numbers within limit
================================
Enter Lower limit & Upper Limit
10
500
153
370
371
407
Program to access array of integer using pointer
#include<stdio.h>
#include<conio.h>
void main()
{
int a[10],i,n;
int *p;
printf("================================\n\n");
printf("Accessing array using Pointer\n\n");
printf("================================\n\n");
printf("Enter no of elements in Array\n");
scanf("%d",&n);
printf("Enter elements of array\n");
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
p=a;
printf("Elements in array Accessed by pointer\n");
printf("=====================================\n\n");
for(i=0;i<n;i++)
printf("%d\n",*(p+i));

getch();
}
OUTPUT
================================
Accessing array using Pointer
================================
Enter no of elements in Array
5
Enter elements of array
6
8
5
1
6
Elements in array Accessed by pointer
=====================================
6
8
5
1
6
Arithmetic Operations
#include<stdio.h>
#include<conio.h>
void main()
{
float a,b;
char op;
clrscr();
printf("=======================\n\n");
printf("Arithmetic Operations\n\n");
printf("=======================\n\n");
printf("enter two numbers\n");
scanf("%f%f",&a,&b);
flushall();
printf("enter the operator +,-,*,/\n");
scanf("%c",&op);
switch(op)
{
case '+':printf("a+b=%f",a+b);break;
case '-':printf("a-b=%f",a-b);break;
case '*':printf("a*b=%f",a*b);break;
case '/':printf("a/b=%f",a/b);break;
default:printf("invalid operator");break;
}
getch();
}
OUTPUT
=======================
Arithmetic Operations
=======================
enter two numbers
50
65

enter the operator +,-,*,/


*
a*b=3250.000000
Employee Structure
#include<stdio.h>
#include<conio.h>
struct employee
{
char name[25];
int age,salary;
char desig[50];
};
void main()
{
struct employee emp1;
clrscr();
printf("================================\n\n");
printf("Employee Structure\n\n");
printf("================================\n\n");
printf("Enter Name of Employee\n");
scanf("%s",&emp1.name);
printf("Enter age of employee\n");
scanf("%d",&emp1.age);
printf("Enter Salary\n");
scanf("%d",&emp1.salary);
printf("Enter Designation\n");
scanf("%s",&emp1.desig);
printf(" Name = %s,\n Age=%d \n designation = %s \n salary = %d",
emp1.name, emp1.age, emp1.desig,emp1.salary);
getch();
}
OUTPUT
================================
Employee Structure
================================
Enter Name of Employee
Rajeev
Enter age of employee
35
Enter Salary
28000
Enter Designation
Manager
Name = Rajeev,
Age=35
designation = Manager
salary = 28000
Factorial Using Recursion
#include<stdio.h>
#include<conio.h>
void main()
{
long fact(int);
int n;
long s;
clrscr();

printf("================================\n\n");
printf("Factorial Using Recursion\n\n");
printf("================================\n\n");
printf("enter number");
scanf("%d",&n);
s=fact(n);
printf("factorial=%d",s);
getch();
}
long fact(int a)
{
if(a<=1)
return 1;
else
return a*fact(a-1);
}
OUTPUT
================================
Factorial Using Recursion
================================
enter number5
factorial=120
Fahrenheit to Celsius conversion
#include<stdio.h>
#include<conio.h>
void main()
{
float f,c;
clrscr();
printf("================================\n\n");
printf("fahrenheit to Celsius Conversion\n\n");
printf("================================\n\n");
printf("Enter the Temparature in fahrenheit\n");
scanf("%f",&f);
c = (f-32)*5/9;
printf("Temparature in Celsius = %f",c);
getch();
}
OUTPUT
================================
fahrenheit to Celsius Conversion
================================
Enter the Temparature in fahrenheit
96.5
Temparature in Celsius = 35.833332
Checking if an Identity Matrix
#include<stdio.h>
#include<conio.h>
void main()
{
int m[10][10],r,c,i,j,flag=0;
clrscr();

printf("================================\n\n");
printf("Finding If a Matrix is Identity\n\n");
printf("================================\n\n");
printf("Enter Rows and Number of Coloumns\n");
scanf("%d%d",&r,&c);
if(r==c)
{
printf("Enter The matrix");
for(i=0;i<c;i++)
for(j=0;j<c;j++)
scanf("%d",&m[i][j]);
//reading finished
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
if((m[i][i]!=1)||(i!=j && m[i][j]!=0))
{
flag=1;
break;
}
}
if(flag==0)
printf("Identity Matrix");
else
printf("Not Identity Matrix");
}
else
printf("Not a Squre matrix");
getch();
}
OUTPUT
================================
Finding If a Matrix is Identity
================================
Enter Rows and Number of Coloumns
3
3
Enter The matrix1
0
0
0
1
0
0
0
1
Identity Matrix
Finding Largest and second largest among 3 nos
#include<stdio.h>
#include<conio.h>
void main()
{
int large, slarge, a,b,c;
clrscr();
printf("================================\n\n");
printf("Finding Largest and Second largest Among 3 Nos\n\n");
printf("================================\n\n");
printf("Enter 3 Numbers");

scanf("%d%d%d",&a,&b,&c);
if((a>b)&&(a>c))
{
large=a;
if(b>c)
slarge=b;
else
slarge=c;
}
else if((b>c)&&(b>a))
{
large=b;
if(a>c)
slarge=a;
else
slarge=c;
}
else
{
large=c;
if(b>c)
slarge=b;
else
slarge=c;
}
printf("Large = %d, Second Large =%d", large,slarge);
getch();
}
OUTPUT
================================
Finding Largest and Second largest Among 3 Nos
================================
Enter 3 Numbers5
25
3
Large = 25, Second Large =5
Matrix Multiplication
#include<conio.h>
#include<stdio.h>
void main()
{
int a[10][20],b[10][10],p[10][10],i,j,k,r1,r2,c1,c2;
clrscr();
printf("================================\n\n");
printf("Matrix Multiplication\n\n");
printf("================================\n\n");
printf("enter the order of the first matrix\n");
scanf("%d%d",&r1,&c1);
printf("enter the order of the second matrix\n");
scanf("%d%d",&r2,&c2);
if(r1==r2&&c1==c2)
{
printf("Enter The elements of first matrix\n");
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
scanf("%d",&a[i][j]);
}

printf("Enter The elements of second matrix\n");


for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
scanf("%d",&b[i][j]);
}
//multiplication
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
{
p[i][j]=0;
for(k=0;k<c2;k++)
p[i][j]=p[i][j]+(a[i][k]*b[k][j]);
}
}
//printing resultant matrix
printf("\nThe Resultant matrix\n");
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
{printf("%d\t",p[i][j]);}
printf("\n");
}
}
else
{
printf("Not a square matrix");
}
getch();
}
OUTPUT
================================
Matrix Multiplication
================================
enter the order of the first matrix
2
2
enter the order of the second matrix
2
2
Enter The elements of first matrix
56
45
78
23
Enter The elements of second matrix
45
56
45
34
The Resultant matrix
4545 4666
4545 5150
Vowel Counting
#include<stdio.h>

#include<conio.h>
void main()
{
int i,count=0;
char str[100];
clrscr();
printf("========================\n\n");
printf("No of Vowels in a String\n\n");
printf("========================\n\n");
printf("Enter the string\n");
gets(str);
for(i=0;str[i]!='\0';i++)
{
switch(str[i])
{
case 'a':
case 'e':
case 'i':
case 'o':
case 'u':
case 'A':
case 'E':
case 'I':
case 'O':
case 'U':count++;break;
}
}
printf("No of Vowels in the string=%d",count);
getch();
}
OUTPUT
========================
No of Vowels in a String
========================
Enter the string
Good Morning
No of Vowels in the string=4
ODD OR EVEN USING BITWISE OPERATOR
#include<stdio.h>
#include<conio.h>
void main()
{
int n;
clrscr();
printf("================================\n\n");
printf("ODD or EVEN Using Bitwise Operator\n\n");
printf("================================\n\n");
printf("Enter an integer\n");
scanf("%d", &n);
if(n&1)
printf("Odd\n");
else
printf("Even\n");
getch();
}
OUTPUT
================================
ODD or EVEN Using Bitwise Operator

================================
Enter an integer
8
Even
Checking if a number is prime or not
#include<stdio.h>
#include<conio.h>
void main()
{
int n,i,flag=0;
printf("================================\n\n");
printf("Finding if a Number is Prime or Not\n\n");
printf("================================\n\n");
printf("Enter a Number\n");
scanf("%d",&n);
for(i=2;i<=n/2;i++)
{
if(n%i==0)
{
flag=1;
break;
}
}
if(flag==1)
printf("Number is not prime");
else
printf("Number is prime");
getch();
}
OUTPUT
================================
Finding if a Number is Prime or Not
================================
Enter a Number
7
Number is prime
OUTPUT
================================
Finding if a Number is Prime or Not
================================
Enter a Number
12
Number is not prime
PRIME NUMBER BETWEEN LIMITS
#include<stdio.h>
#include<conio.h>
void main()
{
int k,l,u,i;
clrscr();
printf("================================\n\n");

printf("Finding Prime Number between limit\n\n");


printf("================================\n\n");
printf("enter the limits");
scanf("%d%d",&l,&u);
printf("prime number between limits are \n");
for(k=l;k<=u;k++)
{
for(i=2;i<=k/2;i++)
{
if(k%i==0)
break;
}
if(i>k/2)
printf("%d\n",k);
}
getch();
}
OUTPUT
================================
Finding Prime Number between limit
================================
enter the limits2
20
prime number between limits are
2
3
5
7
11
13
17
19
ROOTS OF A QUADRATIC EQUATION
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
int a,b,c,d,r1,r2;
clrscr();
printf("=====================================\n\n");
printf("Finding Roots of a quadratic Equation\n\n");
printf("=====================================\n\n");
printf("enter the constants\n");
scanf("%d%d%d",&a,&b,&c);
d=b*b-4*a*c;
if(d>0)
{
r1=(-b+sqrt(d))/2*a;
r2=(-b-sqrt(d))/2*a;
printf("two distinct roots are %d and %d",r1,r2);
}
else if(d==0)
{
r1=r2=-b/2*a;
printf("equal roots=%d",r1);
}
else
{
r1=-b/2*a;

r2=sqrt(-d)/2*a;
printf("imaginary roots=%d+i%d and %d-i%d",r1,r2,r1,r2);
}
getch();
}

OUTPUT
=====================================
Finding Roots of a quadratic Equation
=====================================
enter the constants
1
2
3
imaginary roots=-1+i1 and -1-i1
SIZE AND RANGE OF OPERATORS
#include<conio.h>
#include<stdio.h>
#include<limits.h>
void main()
{
clrscr();
printf("\n Size of character %d\n\n Range : %d to %d",sizeof(char),CHAR_MIN,CHAR_MAX);
printf("\n Size of Unsigned character : %d\n\n Range : %d to
%d",sizeof(char),0,UCHAR_MAX);
printf("\n Size of short integer: %d\n\n Range : %d to
%d",sizeof(short),SHRT_MIN,SHRT_MAX);
printf("\n Size of integer : %d\n\n Range : %d to %d",sizeof(int),INT_MIN,INT_MAX);
printf("\n Size of unsigned integer : %d\n\n Range : %d to %ld",sizeof(int),0,UINT_MAX);
printf("\n Size of LONG integer : %d\n\n Range : %ld to
%ld",sizeof(long),LONG_MIN,LONG_MAX);
printf("\n Size of UNSIGNED LONG integer : %d\n\n Range : %d to
%lu",sizeof(long),0,ULONG_MAX);
printf("\n Size of float : %d\n\n",sizeof(float));
printf("\n Size of double : %d",sizeof(double));
getch();
}
OUTPUT
Size of character 1
Range : -128 to 127
Size of Unsigned character : 1
Range : 0 to 255
Size of short integer: 2
Range : -32768 to 32767
Size of integer : 4
Range : -2147483648 to 2147483647
Size of unsigned integer : 4
Range : 0 to -1
Size of LONG integer : 4

Range : -2147483648 to 2147483647


Size of UNSIGNED LONG integer : 4
Range : 0 to 4294967295
Size of float : 4
Size of double : 8
STRING PALINDROME
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char s[20];
int l,i,j;
clrscr();
printf("================================\n\n");
printf("Finding if a String Is Palindrome\n\n");
printf("================================\n\n");
printf("enter the string\n");
gets(s);
l=strlen(s);
for(i=0,j=l-1;i<l/2;i++,j--)
{
if (s[i]!=s[j])
break;
}
if(i==l/2)
printf("\nPalindrome");
else
printf("\nNot palindrome");
getch();
}
OUTPUT
================================
Finding if a String Is Palindrome
================================
enter the string
malayalam
Palindrome
OUTPUT
================================
Finding if a String Is Palindrome
================================
enter the string
morning
Not palindrome
Swapping Using Pointer
#include<stdio.h>

#include<conio.h>
void swap(int *a, int *b) \
{
int temp;
temp = *a;
*a = *b;
*b = temp;
}
void main()
{
int a, b;
clrscr();
printf("================================\n\n");
printf("Swapping variables using pointer\n\n");
printf("================================\n\n");
printf("\nEnter the first number : ");
scanf("%d", &a);
printf("\nEnter the Second number : ");
scanf("%d", &b);
printf("\nBefore Swapping ");
printf("\nFirst number : %d", a);
printf("\nSecond number : %d", b);
swap(&a, &b);
printf("\nAfter Swapping");
printf("\nFirst number : %d", a);
printf("\nSecond number : %d", b);
getch();
}
OUTPUT
================================
Swapping variables using pointer
================================
Enter the first number : 10
Enter the Second number : 20
Before Swapping
First number : 10
Second number : 20
After Swapping
First number : 20
Second number : 10
Search Delete and modify
#include<stdio.h>
#include<conio.h>
void main()
{
int a[10],p,i,n,d,j;
clrscr();
printf("===================================\n\n");
printf("Search | Delete | Modify Operations\n\n");
printf("===================================\n\n");
printf("Enter No of elements\n");
scanf("%d",&n);
printf("\nEnter elements\n");
for(i=0;i<n;i++)
scanf("%d",&a[i]);
printf("\nYou have Entered\n");

for (i = 0; i<n; i++)


printf("%d\t",a[i]);
printf("\nEnter item to be Searched\n");
scanf("%d",&p);
for (i=0;i<n; i++)
{
if (a[i]==p)
{
printf("\n%d is present",p);
break;
}
}
if (i==n)
printf("\n Item is not present");
printf("\nEnter item to be modified\n");
scanf("%d",&p);
for (i=0;i<n; i++)
{
if (a[i]==p)
{
printf("\nEnter New Number",p);
scanf("%d",&d);
a[i]=d;
break;
}
}
printf("\nEnter item to be deleted\n");
scanf("%d",&p);
for (i=0;i<n; i++)
{
if (a[i]==p)
{
for (j = i; j<n; j++)
{
a[j]=a[j+1];
}
n=n-1;
break;
}
}
printf("\n Array After modification\n");
for (i=0;i<n;i++)
printf("%d\t",a[i]);
getch();
}
OUTPUT
===================================
Search | Delete | Modify Operations
===================================
Enter No of elements
5
Enter elements
7
9
4
3
2

You have Entered


7
9
4
3
2
Enter item to be Searched
4
4 is present
Enter item to be modified
3
Enter New Number
5
Enter item to be deleted
4
Array After modification
7
9
5
2
Bitwise Operations
#include<stdio.h>
#include<math.h>
#include<conio.h>
void main()
{
int a,b,ch,result;
void dectobin(int);
int bintodec(int);
clrscr();
printf("==================\n\n");
printf("Bitwise Operations\n\n");
printf("==================\n\n");
printf("Menu\n");
printf("====\n");
printf("\n1.AND\n2.OR\n3.XOR\n4.Left shift\n5.Right Shift");
printf("\nEnter Choice\n");
scanf("%d",&ch);
switch(ch)
{
case 1:printf("\nEnter two Numbers in Binary form\n");
scanf("%d%d",&a,&b);
a = bintodec(a);
b = bintodec(b);
result=a&b;
dectobin(result);
break;
case 2:printf("\nEnter two Numbers in Binary form\n");
scanf("%d%d",&a,&b);
a = bintodec(a);
b = bintodec(b);
result=a|b;
dectobin(result);
break;
case 3:printf("\nEnter two Numbers in Binary form\n");
scanf("%d%d",&a,&b);
a = bintodec(a);
b = bintodec(b);
result=a^b;
dectobin(result);
break;
case 4:printf("\nEnter a Number in Binary form\n");
scanf("%d",&a);
a = bintodec(a);

printf("\nEnter Postions to be shifted\n");


scanf("%d",&b);
result=a<<b;
dectobin(result);
break;
case 5:printf("\nEnter a Number in Binary form\n");
scanf("%d",&a);
a = bintodec(a);
printf("\nEnter Postions to be shifted\n");
scanf("%d",&b);
result=a>>b;
dectobin(result);
break;
}
}
int bintodec(int n)
{
int rem,dec=0;
float i=0;
while(n>0)
{
rem=n%10;
dec=dec+(rem*pow(2,i));
i=i+1;
n=n/10;
}
return dec;
}
void dectobin(int n)
{
int a[10],i=0;
while(n>0)
{
a[i]=n%2;
n=n/2;
i++;
}
printf("\nResult = ");
for(i--;i>=0;i--)
printf("%d",a[i] );
getch();
}
OUTPUT
==================
Bitwise Operations
==================
Menu
====
1.AND
2.OR
3.XOR
4.Left shift
5.Right Shift
Enter Choice
1
Enter two Numbers in Binary form

11011
11110
Result = 11010
File Store
#include<stdio.h>
#include<conio.h>
void main()
{
FILE *fi;
char c;
clrscr();
printf("================================\n\n");
printf("File Writing and Reading\n\n");
printf("================================\n\n");
printf("\nDATA INPUT\n");
fi = fopen("input.txt","w");
while((c=getchar())!=EOF)
putc(c,fi);
fclose(fi);
printf("\nDATA OUTPUT\n");
fi = fopen("input.txt","r");
while((c=getc(fi))!=EOF)
printf("%c",c );
fclose(fi);
getch();
}
OUTPUT
================================
File Writing and Reading
================================
DATA INPUT
Courageous people do not fear forgiving . For The sake of peace
It always seems impossible until it's done.
Past cannot be changed, future is yet in our power.
^Z
DATA OUTPUT
Courageous people do not fear forgiving . For The sake of peace
It always seems impossible until it's done.
Past cannot be changed, future is yet in our power.

You might also like