Pages

Showing posts with label for loop. Show all posts
Showing posts with label for loop. Show all posts

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

Friday, 21 February 2014

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 To Find A Maximum Number In Array

Wednesday, 8 May 2013


#include <stdio.h>
#include <conio.h>
int main()
{
  int array[100], maximum, s, d, l = 1;

  printf("Enter the number of elements in array\n");
  scanf("%d", &s);

  printf("Enter %d integers\n", s);

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

  maximum = array[0];

  for (d = 1; d < s; d++)
  {
    if (array[d] > maximum)
    {
       maximum  = array[d];
       l = d+1;
    }
  }

  printf("Maximum element is present at location %d and it's value is %d.\n", l, maximum);
 getch();
}

Write a program to calculate volum and area of sphere.

#include<stdio.h>
#include<conio.h>
int main()
{
    float r,v,area;
    printf("Enter the radius of the sphere\n ");
    scanf("%f", &r);
    area=4*3.14*r*r*r;
    v=(4/3.14)*3.14*r*r*r;
    printf("volume of the sphere=%f\n", v);
    printf("area of sphere=%f\n", area);
    getch();
    }

Write a program to get 9 numbers from user in two dimensional array and print it as a matrix.

Saturday, 4 May 2013


#include<stdio.h>
#include<conio.h>
int main()
{
int a[3][3];
int i,j;
printf("value in a case\n");
for(i=1;i<=3;i++)
{
for(j=1;j<=3;j++)
{
      printf("Enter Value of row %d and column %d: ", i, j);          
      scanf("%d", &a[i][j]);
}
}
for(i=1;i<=3;i++)
{
for(j=1;j<=3;j++)
{
printf("%d\t",a[i][j]);
}
printf("\n");
}
getch();
}

Write a program to get row number from user and print diamond of given rows


#include <stdio.h>
#include <conio.h>
int main()
{
    int i, j, k, r;
    printf("Enter number of rows: ");
    scanf("%d", &r);
    for(i=1; i<=r; i+=2)
    {
          for(j=r-2; j>=i; j-=2)
          {
               printf(" ");  
          }
          for(k=1; k<=i; k++)
          {
               printf("*");  
          }
          printf("\n");
    }
    for(i=r-2; i>=1; i-=2)
    {
          for(j=r-1; j>=i; j-=2)
          {
               printf(" ");  
          }
          for(k=1; k<=i-1; k++)
          {
               printf("*");  
          }
          printf("\n");
    }
    getch();
}

Write a program to get numbers from user and sort is print on screen

#include <stdio.h>
#include <conio.h>
int main()
{
    int a[10], i, temp;
    printf("Enter Numbers to sort: ");
    for(i=0; i<=9; i++)
    {
         scanf("%d", &a[i]);   
    }
    for(i=0; i<=9; i++)
    {
             if(a[i+1]<a[i])
             {
                    temp=a[i];
                    a[i]=a[i+1];
                    a[i+1]=temp;
                    i=-1;
             }
    }
   

    for(i=0; i<=9; i++)
    {
        printf("%d ", a[i]);    
    }
    getch();
}

Write a program to print star triangle form.

Friday, 19 April 2013


#include<stdio.h>

#include<conio.h>
int main()
{
    int a,b;
    for(a=7;a>=0;a--)
    {
                    printf("\n");          
                    for(b=0;b<=a;b++)
                    {
                                     printf("*");
                    }
     }
getch();
}

 

Search Box

Most Reading

Contact Form

Name

Email *

Message *