Tuesday, November 1, 2011

Find whether a given number is Strong or not

Write a program in C to find whether a given number is Strong or not


Program:


#include<stdio.h>
#include<conio.h>
void main()
{
int sof=0,n,dn,ctr,prod,rem;
clrscr();
printf("Enter the number\n");
scanf("%d",&n);
dn=n;
while(n!=0)
{
prod=1,ctr=1;
rem=n%10;
while(ctr<=rem)
{
prod=prod*ctr;
ctr=ctr+1;
}
sof=sof+prod;
n=n/10;
}
if(sof==dn)
{
printf("The number entered is strong number");
}
else
{
printf("The number entered is not a strong number");
}
getch();
}
Read full history - Find whether a given number is Strong or not

Monday, October 31, 2011

Sorting the String in Dictionary order

Given an Array of Strings Write a Program to Sort the String in Dictionary Order.


Program:



#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char a[25][25],t[25];
int i,j ,n;
clrscr();
printf("enter the limit\n");
scanf("%d",&n);
printf("enter the elements:\n");
for(i=0;i<n;i++)
scanf("%s",&a[i]);
for(i=0;i<n-1;i++)
{
for(j=i+1;j<n;j++)
{
if(strcmp(a[i],a[j])>0)
{
strcpy(t,a[i]);
strcpy(a[i],a[j]);
strcpy(a[j],t);
}
}
}
printf("the sorted array:\n");
for(i=0;i<n;i++)
printf("%s\n",a[i]);
getch();
}
Read full history - Sorting the String in Dictionary order

About Me