Archive for the ‘Basic Programming’ Category

Largest Among Three Numbers

Posted: February 12, 2010 in Basic Programming

/* Program to find the largest among three numbers */

#include<stdio.h>
main()
{
int a,b,c,large;
printf(“\nEnter three integers: “);
scanf(“%d%d%d”,&a,&b,&c);
large=a>b?(a>c?a:c):(b>c?b:c);
printf(“\nLargeest number: %d\n\n”,large);
}

Advertisements

N Fibonacci Numbers

Posted: February 12, 2010 in Basic Programming
Tags:

/* Program to generate ‘n’ fibonacci nubers */

#include<stdio.h>

main()
{
int first=0,second=1,third,n,i;
printf(“\nEnter the value of n: “);
scanf(“%d”,&n);
printf(“\nThe fibonacci series is ……\n”);
for(i=0;i<n;i++)
{
third=first+second;
printf(“%d\t”,first);
first=second;
second=third;
}
printf(“\n\n”);
}

Factorial of a Number

Posted: February 12, 2010 in Basic Programming

/* Program to find the factorial of a number */

#include<stdio.h>

main()
{
int num,i;
long int factorial=1;
printf(“\nEnter an integer number: “);
scanf(“%d”,&num);
for(i=1;i<=num;i++)
factorial*=i;
printf(“\nFactorial= %ld\n\n”,factorial);
}

Even or Odd

Posted: February 12, 2010 in Basic Programming

/* Program to print  n even and odd numbers */

#include<stdio.h>
main()
{
int n,i;
printf(“\nEnter the value of n; “);
scanf(“%d”,&n);
printf(“\nEven Nubers\n”);
for(i=0;i<n;i++)
printf(“%d\t”,i*2);
printf(“\nOdd Numbers\n”);
for(i=0;i<n;i++)
printf(“%d\t”,i*2+1);
printf(“\n”);
}

Amstrong or Not

Posted: February 12, 2010 in Basic Programming

/* Program to check whether the given number is amstrong or not */

#include<stdio.h>

main()
{
int num,temp,remainder,sumCube=0;
printf(“\nEnter the number: “);
scanf(“%d”,&num);
temp=num;
while(temp>0)
{
remainder=temp%10;
sumCube+=remainder*remainder*remainder;
temp/=10;
}
if(sumCube==num)
printf(“\nThe given number is amstrong!\n\n”);
else
printf(“\nThe given number is not amstrong!\n\n”);
}