To reverse a number
Topics Covered:
- To reads the age of 10 students and finds second highest age
- To reads the age of n students and finds second, third and fourth highest age
- To print multiplication table of 20 integer numbers
- To reverse a number
- To sort name and address of n number of students on the basis of name
- To sort name and age of n number of students on the basis of age
- To sort name, age and address of n number of students on the basis of name
//to reads the age of 10 students and finds second highest age
#include<conio.h>
#include<stdio.h>
int main()
{
int i,j,a[10],temp;
//input section
for(i=0;i<=9;i++)
{
printf(“please enter the age of students you want”);
scanf(“%d”,&a[i]);
}
//processing section
for(i=0;i<9;i++)
{
for(j=i+1;j<10;j++)
{
if(a[i]>a[j])
{
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
}
//output section
printf(“the second highest age=%d”,a[8]);
return 0;
}
//to reads the age of n students and finds second, third and fourth highest age
#include<conio.h>
#include<stdio.h>
int main()
{
int i,j,n,a[10],temp;
//input section
printf(“enter the no. of students”);
scanf(“%d”,&n);
for(i=0;i<=n-1;i++)
{
printf(“please enter the age of students you want”);
scanf(“%d”,&a[i]);
}
//processing section
for(i=0;i<=n-2;i++)
{q
for(j=i+1;j<=n-1;j++)
{
if(a[i]>a[j])
{
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
}
//output section
printf(“the second highest age=%d\n”,a[n-2]);
printf(“the third highest age=%d\n”,a[n-3]);
printf(“the fourth highest age=%d”,a[n-4]);
return 0;
}
//to print multiplication table of 20 integer numbers
#include<conio.h>
#include<stdio.h>
int main()
{
int i,j,m;
for(i=1;i<=20;i++)
{
printf(“\n”);
for(j=1;j<=10;j++)
{
m=i*j;
printf(“%d\t”,m);
}
}
return 0;
}
//to reverse a number
#include<conio.h>
#include<stdio.h>
int main()
{
int n,rev=0,r;
printf(“enter an integer number”);
scanf(“%d”,&n);
while(n!=0)
{
r=n%10;
rev=(rev*10)+r;
n=n/10;
}
printf(“the number in reversed form=%d”,rev);
return 0;
}
//to sort name and address of n number of students on the basis of name
#include<conio.h>
#include<stdio.h>
#include<string.h>
struct student
{
char name[30];
char add[30];
};
int main()
{
struct student s[100],temp;
int i,j,n;
printf(“enter number of students”);
scanf(“%d”,&n);
//reading section
for(i=0;i<=n-1;i++)
{
printf(“enter name”);
scanf(“%s”,&s[i].name);
printf(“enter address”);
scanf(“%s”,&s[i].add);
}
//processing section
for(i=0;i<n-1;i++)
{
for(j=i+1;j<n;j++)
{
if(strcmp(s[i].name,s[j].name)>0)
{
temp=s[i];
s[i]=s[j];
s[j]=temp;
}
}
}
//output section
printf(“name\t address\n”);
for(i=0;i<=n-1;i++)
{
printf(“%s\t%s\n”,s[i].name,s[i].add);
}
return 0;
}
//to sort name and age of n number of students on the basis of age
#include<conio.h>
#include<stdio.h>
struct student
{
char name[30];
int age;
};
int main()
{
struct student s[100],temp;
int i,j,n;
printf(“enter number of students”);
scanf(“%d”,&n);
//reading section
for(i=0;i<=n-1;i++)
{
printf(“enter name”);
scanf(“%s”,&s[i].name);
printf(“enter age”);
scanf(“%d”,&s[i].age);
}
//processing section
for(i=0;i<n-1;i++)
{
for(j=i+1;j<n;j++)
{
if(s[i].age>s[j].age)
{
temp=s[i];
s[i]=s[j];
s[j]=temp;
}
}
}
//output section
printf(“name\t age\n”);
for(i=0;i<=n-1;i++)
{
printf(“%s\t%d\n”,s[i].name,s[i].age);
}
return 0;
}
//to sort name, age and address of n number of students on the basis of name
#include<conio.h>
#include<stdio.h>
#include<string.h>
struct student
{
char name[30];
int age;
float height;
};
int main()
{
struct student s[100],temp;
int i,j,n;
printf(“enter number of students”);
scanf(“%d”,&n);
//reading section
for(i=0;i<=n-1;i++)
{
printf(“enter name”);
scanf(“%s”,&s[i].name);
printf(“enter age”);
scanf(“%d”,&s[i].age);
printf(“enter height”);
scanf(“%f”,&s[i].height);
}
//processing section
for(i=0;i<n-1;i++)
{
for(j=i+1;j<n;j++)
{
if(strcmp(s[i].name,s[j].name)>0)
{
temp=s[i];
s[i]=s[j];
s[j]=temp;
}
}
}
//output section
printf(“name\t age\t height\n”);
for(i=0;i<=n-1;i++)
{
printf(“%s\t%d\t%f\n”,s[i].name,s[i].age,s[i].height);
}
return 0;
}