Showing posts with label c programming. Show all posts
Showing posts with label c programming. Show all posts

Thursday, 23 January 2014

,

/* WAP to Print the age of person in days */

/* WAP to Print the age of person in days  */

#include<stdio.h>
#include<conio.h>
main()
{
    int age,days;
    printf("Enter your age:");
    scanf("%d",&age);
    days=age*365;
    printf("You are %d days old.\n",days);
    getch();
}

Monday, 20 January 2014

,

Write a program to read a number and to test whether it is an Armstrong number or not?

#include<stdio.h>
#include<conio.h>
void main()
{
    int num,temp,rem,sum=0;

    printf("Enter a number:");
    scanf("%d",&num);
    temp=num;

    while(temp!=0)
    {
        rem=temp%10;
        sum=sum+(rem*rem*rem);
        temp=temp/10;
    }

    if(sum==num)
        printf("\n%d is an Armstrong Number.",num);
    else
        printf("\n%d is not an Armstrong Number.",num);

    getch();
}

Friday, 17 January 2014

Write a program to convert decimal to binary??

#include<stdio.h>
#include<conio.h>
void main()
{
    int dec,temp,bin[100],i=1,j;

    printf("Enter A Decimal Number:");
    scanf("%d",&dec);

    temp=dec;

    while(temp!=0)
    {
        bin[i++]=temp%2;
        temp=temp/2;
    }

    printf("The Equivalent Binary Number Of %d is ",dec);

    for(j=i-1;j>0;j--)
    {
        printf("%d",bin[j]);
    }

    getch();
}

Tuesday, 14 January 2014

, ,

use of printf

printf("lets start\n");
This is the printf command and it prints text on the screen. The data that is to be printed is put inside brackets. You will also notice that the words are inside inverted commas because they are what is called a string. Each letter is called a character and a series of characters that is grouped together is called a string. Strings must always be put between inverted commas. The \n is called an escape sequence and represents a newline character and is used because when you press ENTER it doesn't insert a new line character but instead takes you onto the next line in the text editor. You have to put a semi-colon after every command to show that it is the end of the command.