Wednesday, December 19, 2018
Tuesday, December 18, 2018
WAP in C to print an array in reverse order
Easy Programming All
December 18, 2018
0
#include<stdio.h>
int main()
{
int a[100], n, i;
printf("Enter number of elements, you want to insert in an array\n");
scanf("%d",&n);
printf("Enter array elements\n");
for(i = 0; i < n; i++)
scanf("%d",&a[i]);
printf("Array in Reverse Order is:\n");
for(i = n-1; i >= 0; i--)
printf("%d ",a[i]);
return 0;
}
INPUT:
Enter number of elements, you want to insert in an array
5
Enter array elements
11
22
33
44
55
OUTPUT:
Array in Reverse Order is:
55 44 33 22 11
int main()
{
int a[100], n, i;
printf("Enter number of elements, you want to insert in an array\n");
scanf("%d",&n);
printf("Enter array elements\n");
for(i = 0; i < n; i++)
scanf("%d",&a[i]);
printf("Array in Reverse Order is:\n");
for(i = n-1; i >= 0; i--)
printf("%d ",a[i]);
return 0;
}
INPUT:
Enter number of elements, you want to insert in an array
5
Enter array elements
11
22
33
44
55
OUTPUT:
Array in Reverse Order is:
55 44 33 22 11
WAP to print Fibinacci Serien upto nth term
Easy Programming All
December 18, 2018
0
#include<stdio.h>
int main()
{
int n, i, first = -1, second = 1, third;
printf("Enter nth term to print Fibonacci Series\n");
scanf("%d",&n);
printf("Fibonacci Series is:\n");
for(i = 1; i <= n; i++)
{
third = first + second;
printf("%d ",third);
first = second;
second = third;
}
return 0;
}
INPUT :
Enter nth term to print Fibonacci Series
8
OUTPUT :
Fibonacci Series is:
0 1 1 2 3 5 8 13
int main()
{
int n, i, first = -1, second = 1, third;
printf("Enter nth term to print Fibonacci Series\n");
scanf("%d",&n);
printf("Fibonacci Series is:\n");
for(i = 1; i <= n; i++)
{
third = first + second;
printf("%d ",third);
first = second;
second = third;
}
return 0;
}
INPUT :
Enter nth term to print Fibonacci Series
8
OUTPUT :
Fibonacci Series is:
0 1 1 2 3 5 8 13
WAP in C to Sort an Array in Descending Order
Easy Programming All
December 18, 2018
0
#include<stdio.h>
int main()
{
int a[100], n, i, j, temp;
printf("Enter number of elements, you want to insert in array\n");
scanf("%d",&n);
printf("Enter Array Elements\n");
for(i = 0; i < n; i++)
scanf("%d",&a[i]);
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("After Sorting Array is:\n");
for(i = 0; i < n; i++)
printf("%d ",a[i]);
return 0;
}
INPUT:
Enter number of elements, you want to insert in array
5
Enter Array Elements
33
11
22
55
44
OUTPUT:
After Sorting Array is:
55 44 33 22 11
int main()
{
int a[100], n, i, j, temp;
printf("Enter number of elements, you want to insert in array\n");
scanf("%d",&n);
printf("Enter Array Elements\n");
for(i = 0; i < n; i++)
scanf("%d",&a[i]);
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("After Sorting Array is:\n");
for(i = 0; i < n; i++)
printf("%d ",a[i]);
return 0;
}
INPUT:
Enter number of elements, you want to insert in array
5
Enter Array Elements
33
11
22
55
44
OUTPUT:
After Sorting Array is:
55 44 33 22 11
WAP in C to Sort an Array in Ascending Order
Easy Programming All
December 18, 2018
0
#include<stdio.h>
int main()
{
int a[100], n, i, j, temp;
printf("Enter number of elements, you want to insert in array\n");
scanf("%d",&n);
printf("Enter Array Elements\n");
for(i = 0; i < n; i++)
scanf("%d",&a[i]);
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("After Sorting Array is:\n");
for(i = 0; i < n; i++)
printf("%d ",a[i]);
return 0;
}
INPUT:
Enter number of elements, you want to insert in array
5
Enter Array Elements
33
11
22
55
44
OUTPUT:
After Sorting Array is:
11 22 33 44 55
WAP in C to Delete an element from an Array
Easy Programming All
December 18, 2018
0
#include<stdio.h>
int main()
{
int i, n, position, a[100], item;
printf("How many Array Element you want to Enter\n");
scanf("%d " ,&n);
printf("Enter an Array Elements\n");
for(i=0; i<n; i++)
scanf("%d ", &a[i]);
printf("which element you want to delete\n");
scanf("%d" , &item);
for(i = 0; i < n; i++)
{
if(a[i] = = item)
{
position = i;
break;
}
}
if( i = = n)
{
printf("Element can not find in this array");
}
else
{
for(i = position; i < n-1; i++)
{
a[i] = a[i+1];
}
n--;
printf("The Resultant array After Deletion is\n");
for(i = 0; i < n; i++)
printf("%d " , a[i]);
}
return 0;
}
INPUT 1:
How many Array Element you want to Enter
5
Enter an Array Elements
11
22
33
44
77
which element you want to delete
44
OUTPUT 1:
The Resultant array After Deletion is
11 22 33 77
INPUT 2:
How many Array Element you want to Enter
5
Enter an Array Elements
11
22
33
44
77
which element you want to delete
88
OUTPUT 2:
Element can not find in this array
int main()
{
int i, n, position, a[100], item;
printf("How many Array Element you want to Enter\n");
scanf("%d " ,&n);
printf("Enter an Array Elements\n");
for(i=0; i<n; i++)
scanf("%d ", &a[i]);
printf("which element you want to delete\n");
scanf("%d" , &item);
for(i = 0; i < n; i++)
{
if(a[i] = = item)
{
position = i;
break;
}
}
if( i = = n)
{
printf("Element can not find in this array");
}
else
{
for(i = position; i < n-1; i++)
{
a[i] = a[i+1];
}
n--;
printf("The Resultant array After Deletion is\n");
for(i = 0; i < n; i++)
printf("%d " , a[i]);
}
return 0;
}
INPUT 1:
How many Array Element you want to Enter
5
Enter an Array Elements
11
22
33
44
77
which element you want to delete
44
OUTPUT 1:
The Resultant array After Deletion is
11 22 33 77
INPUT 2:
How many Array Element you want to Enter
5
Enter an Array Elements
11
22
33
44
77
which element you want to delete
88
OUTPUT 2:
Element can not find in this array
WAP in C to insert an element to an array at given position
Easy Programming All
December 18, 2018
0
#include<stdio.h>
int main()
{
int i, a[100], n, item, position;
printf("How many array elements you want to enter\n");
scanf("%d", &n);
printf("Enter an array elements\n");
for(i = 0; i<n; i++)
scanf("%d", &a[i]);
printf("which position you want to insert an element\n");
scanf("%d", &position); //Here position is array Index Number
printf("Enter new array Element to insert\n");
scanf("%d",&item);
if(position > n)
{
printf("New array Element cannot be Inserted at this Position");
}
else if(position = = n)
{
a[position] = item;
n++;
}
else
{
for(i = n; i > position; i--)
{
a[i] = a[i-1];
}
a[position] = item;
n++ ;
}
printf("The Resultant array after inserting Element is\n");
for(i = 0; i < n; i++)
printf("%d ", a[i]);
return 0;
}
INPUT 1:
How many array elements you want to enter
5
Enter an array elements
11
22
33
44
55
which position you want to insert an element
3
Enter new array Element to insert
57
OUTPUT 1:
The Resultant array after inserting Element is
11 22 33 57 44 55
INPUT 2:
How many array elements you want to enter
5
Enter an array elements
11
22
33
44
55
which position you want to insert an element
7
Enter new array Element to insert
57
OUTPUT 2:
New array Element cannot be Inserted at this Position
int main()
{
int i, a[100], n, item, position;
printf("How many array elements you want to enter\n");
scanf("%d", &n);
printf("Enter an array elements\n");
for(i = 0; i<n; i++)
scanf("%d", &a[i]);
printf("which position you want to insert an element\n");
scanf("%d", &position); //Here position is array Index Number
printf("Enter new array Element to insert\n");
scanf("%d",&item);
if(position > n)
{
printf("New array Element cannot be Inserted at this Position");
}
else if(position = = n)
{
a[position] = item;
n++;
}
else
{
for(i = n; i > position; i--)
{
a[i] = a[i-1];
}
a[position] = item;
n++ ;
}
printf("The Resultant array after inserting Element is\n");
for(i = 0; i < n; i++)
printf("%d ", a[i]);
return 0;
}
INPUT 1:
How many array elements you want to enter
5
Enter an array elements
11
22
33
44
55
which position you want to insert an element
3
Enter new array Element to insert
57
OUTPUT 1:
The Resultant array after inserting Element is
11 22 33 57 44 55
INPUT 2:
How many array elements you want to enter
5
Enter an array elements
11
22
33
44
55
which position you want to insert an element
7
Enter new array Element to insert
57
OUTPUT 2:
New array Element cannot be Inserted at this Position
Monday, December 17, 2018
WAP in C to check Whether a given Number is Krishnamurthi or Not
HindiKisseKahaniyaan
December 17, 2018
0
#include<stdio.h>
int main()
{
int i, n, fact, sum = 0, copy, rem;
printf("Enter any positive integer number to check Krishnamurthi or Not\n");
scanf("%d",&n);
copy = n;
while(n > 0)
{
rem = n % 10;
fact = 1;
for(i = 1; i <= rem; i++)
fact = fact * i;
sum = sum + fact;
n = n / 10;
}
if(copy = = sum)
{
printf("%d given Number is Krishnamurthi",copy);
}
else
{
printf("%d Number is Not Krishnamurthi",copy);
}
return 0;
}
INPUT 1:
Enter any positive integer number to check Krishnamurthi or Not
145
OUTPUT 1:
145 Number is Krishnamurthi
INPUT 2:
Enter any positive integer number to check Krishnamurthi or Not
123
OUTPUT 2:
123 Number is Not Krishnamurthi
int main()
{
int i, n, fact, sum = 0, copy, rem;
printf("Enter any positive integer number to check Krishnamurthi or Not\n");
scanf("%d",&n);
copy = n;
while(n > 0)
{
rem = n % 10;
fact = 1;
for(i = 1; i <= rem; i++)
fact = fact * i;
sum = sum + fact;
n = n / 10;
}
if(copy = = sum)
{
printf("%d given Number is Krishnamurthi",copy);
}
else
{
printf("%d Number is Not Krishnamurthi",copy);
}
return 0;
}
INPUT 1:
Enter any positive integer number to check Krishnamurthi or Not
145
OUTPUT 1:
145 Number is Krishnamurthi
INPUT 2:
Enter any positive integer number to check Krishnamurthi or Not
123
OUTPUT 2:
123 Number is Not Krishnamurthi
WAP in C to check Whether a given Number is Armstrong or Not
HindiKisseKahaniyaan
December 17, 2018
0
#include<stdio.h>
#include<math.h>
int main()
{
int i, n, sum = 0, rem, copy, count = 0;
printf("Enter any integer number to check armstrong or not\n");
scanf("%d",&n);
copy = n;
while(n > 0)
{
count = count + 1;
n = n / 10;
}
n = copy;
while(n > 0)
{
rem = n % 10;
sum = sum + pow(rem, count);
n = n/10;
}
if(copy = = sum)
{
printf("The given %d number is Armstrong",copy);
}
else
{
printf("The given %d number is Not Armstrong",copy);
}
return 0;
}
INPUT 1:
Enter any integer number to check armstrong or not
153
OUTPUT 1:
The given 153 number is Armstrong
Enter any integer number to check armstrong or not
153
OUTPUT 1:
The given 153 number is Armstrong
INPUT 2:
Enter any integer number to check armstrong or not
1634
OUTPUT 2:
The given 1634 number is Armstrong
Enter any integer number to check armstrong or not
1634
OUTPUT 2:
The given 1634 number is Armstrong
INPUT 3:
Enter any integer number to check armstrong or not
126
OUTPUT 3:
The given 126 number is Not Armstrong
Enter any integer number to check armstrong or not
126
OUTPUT 3:
The given 126 number is Not Armstrong