Professional Documents
Culture Documents
C Programing Project QUestion Solved
C Programing Project QUestion Solved
Write a program to check whether a triangle is valid or not, where the three angles of the
triangle are entered through the keyboard (A triangle is valid if the sum of all the three angles is
equal to 180 degrees.)
Ans:
#include <stdio.h>
int main()
{
int side1, side2, side3;
printf("Enter three sides of triangle: \n");
scanf("%d%d%d", &side1, &side2, &side3);
By Living Loves
{
printf("Triangle is not valid.");
}
return 0;
}
2. A five-digit number is entered through the keyboard. Write a program to obtain the reversed
number and to determine whether the original and reversed numbers are equal or not.
#include <stdio.h>
int main()
{
int n, reversedInteger = 0, remainder,
originalInteger;
printf("Enter an integer: ");
scanf("%d", &n);
originalInteger = n;
while( n!=0 )
{
remainder = n%10;
reversedInteger = reversedInteger*10 +
remainder;
n /= 10;
}
printf("reversed Number Is :%d",reversedInteger);
if (originalInteger == reversedInteger)
printf("%d is equal to the Original Number.",
originalInteger);
else
printf("%d is not equal to the Original
Number.", originalInteger);
else.", originalInteger);
By Living Loves
return 0;
}
3. Write a program using conditional operators to determine whether a year entered through the
keyboard is a leap year or not.
#include <stdio.h>
int main()
{
int year;
printf("Enter any year: ");
scanf("%d", &year);
(year%4==0 && year%100!=0) ? printf("LEAP YEAR") :
(year%400 ==0 ) ? printf("LEAP YEAR") :
printf("COMMON YEAR");
return 0;
}
4. Write a program to find the greatest of the three numbers entered through the keyboard using
conditional operators.
# include <stdio.h>
void main()
{
int a, b, c, big ;
printf("Enter three numbers : ") ;
scanf("%d %d %d", &a, &b, &c) ;
big = a > b ? (a > c ? a : c) : (b > c ? b : c) ;
printf("\nThe biggest number is : %d", big) ;
}
5. Write a program to print out all Armstrong numbers between 1 and 500.
#include<stdio.h>
int main(){
int num,r,sum,temp;
By Living Loves
for(num=1;num<=500;num++){
temp=num;
sum = 0;
while(temp!=0){
r=temp%10;
temp=temp/10;
sum=sum+(r*r*r);
}
if(sum==num)
printf("%d ",num);
}
return 0;
}
Output:
1 153 370 371 407
By Living Loves
A B C D D C B A
A B C C B A
A B B A
A A
#include<stdio.h>
#include<conio.h>
int main()
{
int i,a=71,l,j,b=1,c=71,k;
for(l=1;l<=7;l++)
{
for(i=65;i<=a;i++)
printf("%c", i);
if(l>1)//space loop
{
for(j=1;j<=b;j++)
printf(" ");
b=b+2;
}
for(k=c;k>=65;k--)
{
if(k==71)
continue;
printf("%c", k);
}
printf("\n");
By Living Loves
a--;
c--;
}
getch();
return 0;
}
7. Write a C Program to convert any given year into its roman equivalent.
1 i 100 c
5 v 500 d
10 x 1000 m
50 l
Example:
#include<stdio.h>
void main()
{
int a;
printf("\nInput the year to get it in Roman numerals");
scanf("%d",&a);
roman(a);
}
roman(int year)
{
if(year>=1000)
By Living Loves
{
printf("m");
roman(year-1000);
}
else if(year>=500)
{
printf("d");
roman(year-500);
}
else if(year>=100)
{
printf("c");
roman(year-100);
}
else if(year>=50)
{
printf("l");
roman(year-50);
}
else if(year>=10)
{
printf("x");
roman(year-10);
}
else if(year>=5)
By Living Loves
{
printf("v");
roman(year-5);
}
else if(year>=1)
{
printf("i");
roman(year-1);
}
}
8. Write a C program to multiply two matrices (two-dimensional arrays) which will be entered by a
user.
#include <stdio.h>
int main()
{
int a[10][10], b[10][10], result[10][10], r1, c1, r2, c2, i,
j, k;
By Living Loves
printf("Enter rows and column for first matrix: ");
scanf("%d %d", &r1, &c1);
printf("Enter rows and column for second matrix: ");
scanf("%d %d",&r2, &c2);
}
By Living Loves
// Multiplying matrices a and b and
// storing result in result matrix
for(i=0; i<r1; ++i)
for(j=0; j<c2; ++j)
for(k=0; k<c1; ++k)
{
result[i][j]+=a[i][k]*b[k][j];
}
sin( x ) = x − ( x 3 / 3 ! ) + ( x 5 / 5 ! ) − ( x 7 / 7 ! ) + ….......
#include <stdio.h>
int main()
{
int i, j, n, fact, sign = - 1;
float x, p, sum = 0;
By Living Loves
printf("Enter the value of x : ");
scanf("%f", &x);
printf("Enter the value of n : ");
scanf("%d", &n);
for (i = 1; i <= n; i += 2)
{
p = 1;
fact = 1;
for (j = 1; j <= i; j++)
{
p = p * x;
fact = fact * j;
}
sign = - 1 * sign;
sum += sign * p / fact;
}
return 0;
}
9. Write a function to find the binary equivalent of a given decimal integer and display it.
#include <stdio.h>
int main()
{
int n, c, k;
printf("Enter an integer in decimal number
system\n");
By Living Loves
scanf("%d", &n);
printf("%d in binary number system is:\n", n);
if (k & 1)
printf("1");
else
printf("0");
}
printf("\n");
return 0;
}
By Living Loves