Sie sind auf Seite 1von 7

SSN COLLEGE OF ENGINEERING AJAY S

Record Sheet EEE A

ASCENDING AND DESCENDING SORTING OF INTEGERS


Program Code:

#include<stdio.h>
#include<conio.h>
main()
{
int a[10],i,n,j,t;
printf("Enter the size of the array : ");
scanf("%d",&n);
printf("Enter the numbers : \n");
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
for(i=0;i<n;i++)
{
for(j=i+1;j<n;j++)
{
if(a[i]>a[j])
{
t=a[i];
a[i]=a[j];
a[j]=t;
}
}
}
printf("\n Ascending Order \n");
for(i=0;i<n;i++)
{
printf("%d ",a[i]);
}
SSN COLLEGE OF ENGINEERING AJAY S
Record Sheet EEE A

for(i=0;i<n;i++)
{
for(j=i+1;j<n;j++)
{
if(a[i]<a[j])
{
t=a[i];
a[i]=a[j];
a[j]=t;
}
}
}
printf("\n Descending Order\n");
for(i=0;i<n;i++)
{
printf("%d ",a[i]);
}
getch();
}

Output:

Enter the size of the array : 5


Enter the numbers :
55 42 33 10 62
Ascending Order
10 33 42 55 62
Descending Order
62 55 42 33 10
SSN COLLEGE OF ENGINEERING AJAY S
Record Sheet EEE A

FIBONACCI SERIES
Program Code:

#include<stdio.h>
#include<conio.h>
main()
{
int a=-1,b=1,c=0,n,i;
printf("\n Enter a value to generate Fibonacci series : ");
scanf("%d",&n);
for(i=0;i<=n;i++)
{
c=a+b;
a=b;
b=c;
printf("%d\n",c);
}
getch();
}

Output :
Enter a value to generate Fibonacci series : 6
0
1
1
2
3
5
8

Finding Digit, Vowel or Consonant


SSN COLLEGE OF ENGINEERING AJAY S
Record Sheet EEE A

Program Code:

#include<stdio.h>
#include<conio.h>
main()
{
int x;
char y;
printf("\nEnter a character :\t");
scanf("%d",&x);
scanf("%c",&y);
if((x==0)||(x==1)||(x==2)||(x==3)||(x==4)||(x==5)||(x==6)||(x==7)||(x==8)||(x==9))
{
printf("\nThe given number '%d' is an integer",x);
}
else if((y=='a')||(y=='e')||(y=='i')||(y=='o')||(y=='u'))
{
printf("\nThe given letter '%c' is a vowel",y);
}
else
{
printf("\nThe given letter '%c' is a consonant",y);
}
getch();
}

Output :
Enter a character : d
The given letter ‘d’ is consonant
Enter a character : e
The given letter ‘e’ is a vowel
Enter a character : 5
The given number ‘5’ is an integer
SSN COLLEGE OF ENGINEERING AJAY S
Record Sheet EEE A

PATTERN GENERATION
Program Code:

#include<stdio.h>
#include<conio.h>
main()
{
int n,i,j,a;
printf("\nEnter the number of rows\t");
scanf("%d",&a);
n=90;
for(i=1;i<=a;i++)
{
n=90;
for(j=1;j<=i;j++)
{
printf("%c",n--);
}
printf("\n");
}
getch();
}

Output:
Enter the number of rows 5
Z
ZY
ZYX
ZYXW
ZYXWV
SSN COLLEGE OF ENGINEERING AJAY S
Record Sheet EEE A

EVEN OR ODD SERIES


Program Code:

#include<stdio.h>
#include<conio.h>
main()
{
int i,n;
printf("\n Enter any positive integer : ");
scanf("%d",&n);
if(n%2==0)
{
for(i=0;i<=n;i+=2)
printf("%d\n",i);
}
else
{
for(i=1;i<=n;i+=2)
printf("%d\n",i);
}
getch();
}

Output:
Enter any positive integer : 10
0
2
4
6
8
SSN COLLEGE OF ENGINEERING AJAY S
Record Sheet EEE A

PALINDROME
Program Code:

#include<stdio.h>
#include<conio.h>
main()
{
int n,n1,rev=0,rem;
printf("\n Enter any number : ");
scanf("%d",&n);
n1=n;
while(n>0)
{
rem=n%10;
rev=rev*10+rem;
n=n/10;
}
if(n1==rev)
{
printf("\n The given number %d is a palindrome ",rev);
}
else
{
printf("\n The given number %d is not a palindrome ",rev);
}
getch();
}

Output:
Enter any number : 654456
The given number 654456 is a palindrome

Das könnte Ihnen auch gefallen