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();
}

Write a program in assembly language to get ASCII and convert it into Character.

Saturday 14 June 2014

Tags: convert ascii into character in assembly language, assembly program to convert ascii into character

Note: This program is compiled in EMU software. Click Here to Download 

Write a program in assembly language to multiply matrices of 3x3 [Updated]

Tags: Multiplication is assembly language, multiplication of matrices in assembly language,

Note: This program is compiled in EMU software. Click Here to Download 

Write a program in c language to multiply matrices of NxN order by recursion

Wednesday 14 May 2014

#include <stdio.h>
#include <conio.h>
#define MAX 10

int m,n,o,p;
int c[MAX][MAX];

void multiplyMatrix(int a[MAX][MAX],int b[MAX][MAX]){

    static int sum,i=0,j=0,k=0;

    if(i<m){ //rows of first matrix
    if(j<p){  //columns of second matrix
         if(k<n){
             sum=sum+a[i][k]*b[k][j];
             k++;
             multiplyMatrix(a,b);
         }
         c[i][j]=sum;
             sum=0;
             k=0;
             j++;
             multiplyMatrix(a,b);
    }
    j=0;
    i++;
    multiplyMatrix(a,b);
    }
}

int main(){
 
    int a[MAX][MAX],b[MAX][MAX],i,j,k;

    printf("Enter the row and column of first matrix: ");
    scanf("%d %d",&m,&n);
    printf("Enter the row and column of second matrix: ");
    scanf("%d %d",&o,&p);

    if(n!=o){

         printf("Matrix multiplication is not possible");
         printf("\nColumn of first matrix must be same as row of second matrix");
    }
  else{

      printf("Enter the First matrix: ");
      for(i=0;i<m;i++)
      for(j=0;j<n;j++)
           scanf("%d",&a[i][j]);

      printf("Enter the Second matrix: ");
      for(i=0;i<o;i++)
      for(j=0;j<p;j++)
           scanf("%d",&b[i][j]);

      printf("\nThe First matrix is: \n");
      for(i=0;i<m;i++){
      printf("\n");
      for(j=0;j<n;j++){
           printf("%d\t",a[i][j]);
      }
      }

      printf("\nThe Second matrix is: \n");
      for(i=0;i<o;i++){
      printf("\n");
      for(j=0;j<p;j++){
           printf("%d\t",b[i][j]);
      }
      }

      multiplyMatrix(a,b);

  }

  printf("\nThe multiplication of two matrix is: \n");
  for(i=0;i<m;i++){
      printf("\n");
      for(j=0;j<p;j++){
           printf("%d\t",c[i][j]);
      }
  }
 
  getch();
}

Write a program to check given number is prime or not using recursion

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

int isPrime(int number, int i)
{

    if(i==1)
    {
        return 1;
    }
    else
    {
       if(number%i==0)
         return 0;
       else
         isPrime(number,i-1);
    }
}

int main(){

    int number, prime;

    printf("Enter a positive number: ");
    scanf("%d", &number);

    prime = isPrime(number, number/2);

   if(prime==1)
        printf("%d is a prime number.", number);
   else
      printf("%d is not a prime number.", number);

   getch();
}

Write a Program to print numbers in squire but with a rectangle

Wednesday 26 March 2014




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

int main()
{
    int i, j=1,k, max_val, count=0, max, fl = 0;
    cout << "Enter Maximum Number: ";
    cin >> max_val;
    cout << endl;
    max = max_val;
for(k=1; k<=max_val; k++)
{
    i = 1;
    count = 0;
    while(i)
    {
           if(i < max_val && count == 0)
           {
                if(i < max)
                {
                    cout << i << " ";
                }
                i++;
           }
           else if(i == max_val)
           {
                count = 1;
                i--;
             if(fl == 1)
             {
                if(max == max_val)
                {
                    max--;
                    cout << "  ";
                }
                else
                {
                    for(j=1; j<= max_val-max; j++)
                    {
                         cout << "    ";
                    }
                    cout << "  ";
                    max--;
                }
             }
             else
                 cout << max_val << " ";
           }
           else if(count == 1)
           {
                if(i-1 < max)
                {
                    cout << i << " ";
                }
                i--;
           }
           else if(i == 0)
                break;
    }
    cout << endl;
    fl = 1;
    
}
    cout << endl;
    system("pause");

}

Write a program in C language that replace spaces by another character or remove spaces

Sunday 23 March 2014

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

int main()
{
    char arr[500];
    int ch, count = 0;
    while(ch != 13)
    {
           ch = arr[count] = getche();
           if(ch == 32)
           {
               arr[count] = '-'; //space is replaced by -
           }
           count++;
    }
    cout << endl;
    for(int i = 0; i<= count-1; i++)
    {
         cout << arr[i];
    }
    cout << endl;
    system("pause");
}

How to make diamond in C++. Size of diamond is depend upon user ??

Thursday 13 March 2014

How to make diamond in C++. Size of diamond is depend upon user ??

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

{
int size;
cout<<"how large u want.. ";
cin>>size;
for(int i=1;i<=size;i++)
{for(int j=size;j>=i;j--)
cout<<" ";
for(int j=1;j<=i;j++)
cout<<"* ";
cout<<"\n";}

for( int i=size;i>=1;i--)
{for( int j=size;j>=i;j--)
cout<<" ";
for(int j=1;j<=i;j++)
cout<<"* ";
cout<<"\n";}

getch();

}

Write a program which takes input in Cartesian coordinates (x, y) and calculate and display the Polar coordinates.

Wednesday 12 March 2014

Write a program which takes input in Cartesian coordinates (x, y) and calculate and display the Polar  coordinates.

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

int main()
{
    float r, thet = 0, rad, x, y;
    cout << "Enter value of x-axis: ";
    cin>>x;
    cout << "Enter value of y-axis: ";
    cin>>y;
    r = (x*x) + (y*y);
    r = sqrt(r);
    thet = atan2(x,y) * 180 / 3.1415;
    cout << endl << "Coordinates in Polar is (" << r << " , " << thet << ")" << endl;
    system("pause");
}

Write a program to check whether the given number is palindrome or not?

Friday 21 February 2014

Note: Polindrome is a number that is same if we reverse it. e.g: 151 reverse is 151



#include <iostream>
using namespace std;

int main()
{
    int number, ans = 0, temp;
    cout << "Enter a number: ";
    cin >> number;
    temp = number;
    while( number != 0)
    {
           ans = ans*10;
           ans = ans + number%10;
           number = number/10;
    }
    if(ans == temp)
    {
           cout << "Number is polindrome.";
    }
    else
    {
           cout << "Number is not polindrome.";
    }
    system("pause");
}

Write a program in C++ to print Pascal Series on screen



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

long factorial(int);

int main()
{
   int i, n, c;

   printf("Enter the number of rows you wish to see in pascal triangle\n");
   scanf("%d",&n);

   for ( i = 0 ; i < n ; i++ )
   {
      for ( c = 0 ; c <= ( n - i - 2 ) ; c++ )
         printf(" ");

      for( c = 0 ; c <= i ; c++ )
         printf("%ld ",factorial(i)/(factorial(c)*factorial(i-c)));

      printf("\n");
   }

   getch();
}

long factorial(int n)
{
   int c;
   long result = 1;

   for( c = 1 ; c <= n ; c++ )
         result = result*c;

   return ( result );
}

Write a program to find GCD and LCM in C++ language

#include <iostream>
using namespace std;

int main()
{
    int a, b, temp, gcd, lcm, x, y;
    cout << "Enter two number: ";
    cin >> x>>y;
   
    a = x;
    b = y;
   
    while(b!= 0)
    {
           temp = b;
           b = a%b;
           a = temp;
    }
   
    gcd = a;
    lcm = x*y/gcd;
   
    cout << "GCD is: "<<gcd<<"\nLCM is: "<<lcm<<endl;
    system("pause");
}

Write a program to find first 1000 armstrong numbers in C++ language

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;
for(i=1; i<=1000; i++)
{
    num = temp = i;
    sum = 0;
    while(temp != 0)
    {
          remainder = temp%10;
          sum = sum + remainder*remainder*remainder;
          temp = temp/10;
    }
    if(num == sum)
           cout <<sum<<endl;
}
    getch();
}

Write a program in C++ to find angle between minutes and second hand, hour and second hand and hour and minute hand.

#include <iostream>
using namespace std;

int main()
{
    int hour, minut, second, angle1, angle2, angle;
    cout << "Enter hour: ";
    cin >> hour;
    cout << "Enter minut: ";
    cin >> minut;
    cout << "Enter second: ";
    cin >> second;
   
    //angle between hour and minut.
    if(angle1 == 12)
    angle1 = 0;
   
    angle1 = hour*30;
    angle2 = minut*6;
 
    angle = angle2 - angle1;
    if(angle < 0)
    {
         angle1 = 360 - angle1;
         angle = angle1 + angle2;
    }
    cout << "Angle between hour and minut is: ";
    cout << angle << endl;
   
    //angle between hour and second.
    if(angle1 == 12)
    angle1 = 0;
   
    angle1 = hour*30;
    angle2 = second*6;

    angle = angle2 - angle1;
    if(angle < 0)
    {
         angle1 = 360 - angle1;
         angle = angle1 + angle2;
    }
    cout << "Angle between hour and second is: ";
    cout << angle << endl;
   
    //angle between hour and second.
    angle1 = minut*6;
    angle2 = second*6;

    angle = angle2 - angle1;
    if(angle < 0)
    {
         angle1 = 360 - angle1;
         angle = angle1 + angle2;
    }
    cout << "Angle between hour and second is: ";
    cout << angle << endl;
   
    cout <<endl;
    system("pause");
}

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

#include <iostream>
using namespace std;

int main()
{
    int a, b, *p1, *p2, sum;
    cout << "Enter both numbers: ";
    cin >> a >> b;
    p1 = &a;
    p2 = &b;
    sum = *p1 + *p2;
    cout << "Sum is " << sum <<endl;
    system("pause");
}

Write a program in C language to find nCr and nPr

Sunday 26 January 2014

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

int fict(int n)
{
    int i, sum=1;
    for(i=1; i<=n; i++)
    {
         sum = sum*i;
    }
    return sum;
}

main()
{
      char status, find;
      int n, r, ans;
   
      while(status != 'n')
      {
             cout << "\n1: nCr\n2: nPr\n";
             find = getch();
             cout << "Enter value of n: ";
             cin >> n;
             cout << "Enter value of r: ";
             cin >> r;
           
             if(find == '1')
             {
                     ans = fict(n) /( fict(r) * fict(n-r));
                     cout << "\nAnswer of "<<n<<"C"<<r<<" is: "<<ans<<endl;
             }
             else if(find == '2')
             {
                     ans = fict(n) / fict(n-r);
                     cout << "\nAnswer of "<<n<<"P"<<r<<" is: "<<ans<<endl;
             }
             else
             {
                     cout << "Enter valid input."<<endl;
             }
           
           
             cout << "You like to calculate again? n/y.";
             status = getch();
      }
       
      system("pause");  
}

 

Search Box

Most Reading

Contact Form

Name

Email *

Message *