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

Thursday, 23 January 2014

/*WAP to find Factorial of a number using for loop */

/* Factorial of a number using for loop */

#include<stdio.h>
#include<conio.h>
void main()
{
    int num,i,fact=1;

    printf("Enter a Number:");
    scanf("%d",&num);

    for(i=1;i<=num;i++)
    {
        fact=fact*i;
    }

    printf("%d!=%d",num,fact);
}

/* WAP to find the ASCII value of given character */

/* WAP to find the ASCII value of given character */

#include<stdio.h>
#include<conio.h>
void main()
{
    char ch;

    printf("Enter a character:");
    scanf("%c",&ch);

    printf("The ASCII value of %c is %d",ch,ch);

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