Pages

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

Tuesday, 1 July 2014




#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 *