We can reverse a string in two different ways- (i) Using another string (ii) without using second string. As per question here no need to write the main() function.
void reverse_string()
{
char str[40],strrev[40];
int len,i,j=0;
printf("Enter a String");
gets(str);
len=strlen(str);
for(i=len-1;i>=0;i--)
{
strrev[j++]=str[i];
}
strrev[j]='\0';
puts(strrev);
getch();
}
In this method, we interchange the first characters with the last character, after then, interchange the second character with the second last character and so on up to reach at the mid of the given string.
void reverse_string()
{
char str[40],temp;
int len,i;
printf("Enter a String");
gets(str);
len=strlen(str);
for(i=0;i<len;i++)
{
if(if<=(len/2))
{
temp=str[i];
str[i]=str[len-1-i];
str[len-1-i]=temp;
}
}
puts(str);
getch();
}
Here we start the divide the given number by 2. If it is not divided by 2 then divide it by 3 and so on. By which no the given number is divisible is known as the smallest divisor of the given number. As per question here we must write the main() function.
void main()
{
int no,sd=2;
printf("Enter a number");
scanf("%d",&no);
while(no%sd!=0)
{
sd++;
}
printf("The smallest divisor of %d is %d",no,sd);
getch();
}