Pages

Write a program in c language to reverse a string in reverse order without using strrev function or any other function

Sunday 6 July 2014

#include <stdio.h>
#include <string.h>
#include <conio.h>

int main()
{
char str[100], ch, str2[100];
int count = 1, i, count2 = 0;

printf("Enter String: ");
while(ch != 13)
{
ch = getche();
str[count] = ch;
count++;
}
 
    for(i=0; i<=99; i++)
    {
str2[i] = str[i];
}

    for(i=count; i>=0; i--)
    {
str[count2] = str2[i];
count2++;
}

printf("\nRevered string is\n");

for(i = 0; i < count; i++)
{
printf("%c", str[i]);
}

   getch();
}

Write a program in c language to reverse a string by using strrev function or ptrint a string in reverse order

#include <stdio.h>
#include <string.h>
#include <conio.h>

int main()
{
   char str[100];

   printf("Enter a string to reverse: ");
   gets(sttr);

   strrev(str);  //function to reverse a string

   printf("Reverse of entered string is: %s\n", str);

   getch();
}

Write a program in c language to compare two strings by using pointers.

#include <stdio.h>
#include <conio.h>

int compare_strings(char*, char*);

int main()
{
    char str1[100], str2[100], result;

    printf("Enter first string: ");
    gets(str1);

    printf("Enter second string: ");
    gets(str2);

    result = compare_strings(str1, str2);

    if ( result == 0 )
       printf("Strings are same.\n");
    else
       printf("Entered strings are not equal.\n");

    getch();
}

int compare_strings(char *str1, char *str2)
{
   while(*str1==*str2)
   {
      if ( *str1 == '\0' || *str2 == '\0' )
         break;

      str1++;
      str2++;
   }
   if( *str1 == '\0' && *str2 == '\0' )
      return 0;
   else
      return 1;
}

Write a program in c language to compare two strings without strcmp function or any other function

#include <stdio.h>
#include <string.h>
#include <conio.h>

int main()
{
   char str1[100], str2[100], ch;
   int i, check = 0, count = 0;

for(i=0; i<=100; i++)
{
str1[i] = str2[i] = 0;
}

   printf("Enter the first string: ");
   while(ch != 13)
   {
ch = getche();
str1[count] = ch;
count++;
   }
 
 
count = 0;
ch = NULL;
   printf("\nEnter the second string: ");
   while(ch != 13)
   {
ch = getche();
str2[count] = ch;
count++;
   }

for(i=0; i<=99; i++)
{
if(str1[i] != str2[i])
check = 1;
}


   if( check == 0 )
   {
      printf("\nEntered strings are equal.\n");
   }
   else
   {
      printf("\nEntered strings are not equal.\n");
   }
 
getch();
}

Write a program to Compare two strings by using strcmp function in c language

#include <stdio.h>
#include <string.h>
#include <conio.h>

int main()
{
   char str1[100], str2[100];

   printf("Enter the first string: ");
   gets(str1);

   printf("Enter the second string: ");
   gets(str2);

   if( strcmp(str1, str2) == 0 )
   {
      printf("Entered strings are equal.\n");
   }
   else
   {
      printf("Entered strings are not equal.\n");
   }
 
getch();
}

Write a program that will determine the prime factors of a specified factorial

Tuesday 1 July 2014


#include <stdio.h>
#include <iostream>
using namespace std;

int main()
{

int number,div, num1;
int arr[20], i=0; 
int result=0, large_no;
cout<<"Enter a number to know its prime factor: "; 
cin>>number;
num1= number;
cout<<"\nThe prime factors of "<<number<<" are: \n\n";

div = 2;

while(number!=0)
{
if(number%div!=0)
div = div + 1;

else {
number = number / div;
cout<<div<<" ";
arr[i]= div;
i++;

if(number==1)
break;
}
}
large_no= arr[i-1];


cout<<endl;
cout<<"In this prime factorss.. "<<endl;
for(int j=2;j<=large_no;j++)
{
for(int k=0;k<=large_no;k++)
{

if(j==arr[k])
{
result=result+1;
}


cout<<j<<" comes "<< result<<" time "<<endl;
result=0;
}


system("pause");
}

Write a program in C language to add two numbers using pointers




#include <stdio.h>
#include <conio.h>

int main()
{
   int num1, num2, *p, *q, sum;

   printf("Enter two integers to add: ");
   scanf("%d %d", &num1, &num2);

   p = &num1;
   q = &num2;

   sum = *p + *q;

   printf("Sum of given numbers is: %d",sum);

   getch();
}

Write a program in c language to print Floyd's triangle


#include <stdio.h>
#include <conio.h>

int main()
{
  int n, i,  c, a = 1;

  printf("Enter the number of rows of Floyd's triangle to print: ");
  scanf("%d", &n);

  for (i = 1; i <= n; i++)
  {
    for (c = 1; c <= i; c++)
    {
      printf("%d ", a);
      a++;
    }
    printf("\n");
  }

  getch();
}


Write a program to find given given number is armstrong or not?

Note: Armstrong numbers are those numbers if we take cube of their digits individually and add them then it will equal to the number.
e.g: 153
1^3 + 5^3 + 3^3 = 153


#include <iostream>
#include <conio.h>
using namespace std;

int main()
{
int remainder, temp, sum=0, num, i;


cout << "Enter a number: ";
cin >> i;


num = temp = i;
while(temp != 0)
{
remainder = temp%10;
sum = sum + remainder*remainder*remainder;
temp = temp/10;
}
if(num == sum)
cout << "Number is Armstrong." <<endl;
else
cout << "Number is not Armstrong." <<endl;

getch();
}

Write a program in c language to find minimum number from array

#include <stdio.h>
#include <conio.h>

int main()
{
    int array[100], min, size, c, location = 1;

    printf("How many elements you want to enter in array: ");
    scanf("%d",&size);

    printf("Enter %d integers: ", size);

    for ( c = 0 ; c < size ; c++ )
        scanf("%d", &array[c]);

    min = array[0];

    for ( c = 1 ; c < size ; c++ )
    {
        if ( array[c] < min )
        {
           min = array[c];
           location = c+1;
        }
    }

    printf("Minimum element is located at location %d and value is %d: ", location, min);
    getch();
}

 

Search Box

Most Reading

Contact Form

Name

Email *

Message *