C Program To Find The Third Largets Number in An Array Using Sorting
C Program To Find The Third Largets Number in An Array Using Sorting
C Program To Find The Third Largets Number in An Array Using Sorting
sorting
#include <stdio.h>
void main()
{
int i, j, a, n, number[30];
printf("Enter the value of N \n");
scanf("%d", &n);
printf("Enter the numbers \n");
for (i = 0; i < n; ++i)
scanf("%d", &number[i]);
for (i = 0; i < n; ++i)
{
for (j = i + 1; j < n; ++j)
{
if (number[i] > number[j])
{
a = number[i];
number[i] = number[j];
number[j] = a;
}
}
}
printf("Third Largest number is %d\n", number[n-3]);
}
#include <stdio.h>
void main()
{
int i, j, a, n, number[30],m=0,b[30];
printf("Enter the value of N \n");
scanf("%d", &n);
printf("Enter the numbers \n");
for (i = 0; i < n; ++i)
scanf("%d", &number[i]);
for (i = 0; i < n; ++i)
{
for (j = i + 1; j < n; ++j)
{
if (number[i] > number[j])
{
a = number[i];
number[i] = number[j];
number[j] = a;
}
}
}
for(i=0;i<n;i++)
{
if(a[i]!=a[i+1])
{
b[m++]=number[i];
}
}
printf("Third Largest number is %d\n", b[m-3]);
}
#include <stdio.h>
void main()
{
int i, j, max,n,a[30],count=0;
printf("Enter the value of N \n");
scanf("%d", &n);
printf("Enter the numbers \n");
for (i = 0; i < n; i++)
scanf("%d", &a[i]);
l1: max=a[0];
for (i = 1; i < n; i++)
{
if(max<a[i])
{
max=a[i];
j=i;
}
}
for(i=j+1;j<n;j++)
{
a[i-1]=a[i];
}
n--;
count++;
if(count<3)
goto l1;
printf("Third Largest number is %d\n", max);
}
Palindrome number program c
#include <stdio.h>
int main()
{
int n, reverse = 0, temp;
printf("Enter a number to check if it is a palindrome or not\n");
scanf("%d",&n);
temp = n;
while( temp != 0 )
{
reverse = reverse * 10;
reverse = reverse + temp%10;
temp = temp/10;
}
if ( n == reverse )
printf("%d is a palindrome number.\n", n);
else
printf("%d is not a palindrome number.\n", n);
return 0;
}
#include<stdio.h>
int main()
{
char str[50], rev[50];
int i=-1,j=0;
printf("Enter any string : ");
scanf("%s",str);
while(str[++i]!='\0');
while(i>=0)
rev[j++] = str[--i];
rev[j]='\0';
printf("Reverse of string is : %s",rev);
return 0;
}
#include<stdio.h>
#include<conio.h>
void days(int,int,int,int,int,int);
int month(int,int);
int mon[12]={31,28,31,30,31,30,31,31,30,31,30,31};
void main()
{
int a1,b1,c1,a2,b2,c2;
clrscr();
printf("Enter first date(dd mm yyyy) : ");
scanf("%d%d%d",&a1,&b1,&c1);
printf("\nEnter second date(dd mm yyyy) : ");
scanf("%d%d%d",&a2,&b2,&c2);
if(c2>=c1)
days(c1,c2,b1,b2,a1,a2);
else
days(c2,c1,b2,b1,a2,a1);
getch();
}
#include<stdio.h>
int main()
{
int pow,num,i=1;
long int sum=1;
printf("\nEnter a number: ");
scanf("%d",&num);
printf("\nEnter power: ");
scanf("%d",&pow);
while(i<=pow)
{
sum=sum*num;
i++;
}
printf("\n%d to the power %d is: %ld",num,pow,sum);
return 0;
}
#include<stdio.h>
int main()
{
FILE *p,*q;
char file1[20],file2[20];
char ch;
p=fopen(input.txt,"r");
q=fopen(output.txt,"w");
while((ch=getc(p))!=EOF)
putc(ch,q);
fclose(p);
fclose(q);
return 0;
}
#include<stdio.h>
#include<conio.h>
void main()
{
char ch[10];
int i,count=0;
clrscr();
printf("Enter the string\n");
gets(ch);
for(i=0;ch[i]!='\0';i++)
{
if(ch[i]=='a' || ch[i]=='e' || ch[i]=='i' || ch[i]=='o' || ch[i]=='u')
{
count++;
}
}
printf("Vowels = %d",count);
getch();
}
#include<stdio.h>
#include<conio.h>
int main()
{
int a[10][10];
int no;
printf("Enter the number of rows for pascal triangle : ");
scanf("%d",&no); //taking input
for(int i=1; i<=no; i++)
{
for(int j=1; j<=i; j++)
{
if(j==1||j==i)
{
a[i][j]=1;
}
else // taking arrays value
{
a[i][j]=a[i-1][i-j]+a[i-1][i-j+1];
}
}
}
for(int i=1; i<=no; i++)
{
for(int k=1; k<=no-i; k++)
{
printf(" ");
}
for(int j=1; j<=i; j++)
{
printf("%d ",a[i][j]); //printing pascal triangle
}
printf("\n");
}
getch();
}
Sample output: