Friday, November 29, 2013
/* C program to find LCM of two positive integers entered by user */
#include<stdio.h>
return 0;
}
Output:
Enter two positive numbers: 15 9
LCM of two numbers 15 and 9 is 45
/* C Program to Find Highest Common Factor. */
#include<stdio.h>
int main()
{
int num1,num2;
printf("Enter two integers: ");
scanf("%d %d",&num1,&num2);
printf("HCF of %d and %d is ",num1 , num2);
while(num1!=num2)
{
if(num1>num2)
num1-=num2;
else num2-=num1;
}
printf("%d",num1);
return 0;
}
Output:
Enter two integers:
14 35
HCF of 14 and 35 is 7
#include<stdio.h>
/* C program to check whether a year is leap year or not using if else statement.*/
#include<stdio.h>
int main()
{
int year;
printf("Enter a year: ");
scanf("%d",&year);
if(year%4 == 0)
{
if( year%100 == 0) /* Checking for a century year */
{
if ( year%400 == 0)
printf("%d is a leap year.", year);
else
printf("%d is not a leap year.", year);
}
else
printf("%d is a leap year.", year );
}
else
printf("%d is not a leap year.", year);
return 0;
}
Output 1:
Enter year: 2000
2000 is a leap year.
Output 2:
Enter year: 1900
1900 is not a leap year.
#include<stdio.h>
/* C program to find largest number using if...else statement */
#include<stdio.h>
int main()
{
float a, b, c;
printf("Enter three numbers: ");
scanf("%f %f %f", &a, &b, &c);
if (a>=b)
{
if(a>=c)
printf("Largest number = %.2f",a);
else
printf("Largest number = %.2f",c);
}
else
{
if(b>=c)
printf("Largest number = %.2f",b);
else
printf("Largest number = %.2f",c);
}
return 0;
}
Output:
Enter three numbers:
12.2
13.452
10.193
Largest number = 13.45
#include<stdio.h>
/* Source code to find ASCII value of a character entered by user */
#include<stdio.h>
int main()
{
char c;
printf("Enter a character: ");
scanf("%c",&c); /* Takes a character from user */
printf("ASCII value of %c = %d",c,c);
return 0;
}
----------------------------------------------------------------------------------------
/* This program computes the size of variable using sizeof operator.*/
#include<stdio.h>
int main()
{
int a;
float b;
double c;
char d;
printf("Size of int: %d bytes\n",sizeof(a));
printf("Size of float: %d bytes\n",sizeof(b));
printf("Size of double: %d bytes\n",sizeof(c));
printf("Size of char: %d byte\n",sizeof(d));
return 0;
}
Output:
Size of int: 4 bytes
Size of float: 4 bytes
Size of double: 8 bytes
Size of char: 1 byte
#include<stdio.h>
Subscribe to:
Posts
(
Atom
)


