Professional Documents
Culture Documents
#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
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]);
}
#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");
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
#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");
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.