C Programming code on different problems

Spread the page link









***Write C prog code to find GCD of two integers.
***Write C prog code to find the area of triangle.
***Write C prog code to show a number positive or negative.
***Write C prog code to find the largest number among three numbers a,b,c.
***Write C prog code to Find LEAP YEAR.
***Write C prog code to transform centigrade temperature to farenhaite temperature.
***Write C prog code to show a character vowel or consonent.

***Write C prog code to find GCD of two integers.

#include
 main()
 {
     int a,b,x;
     printf("Enter the first number ");
     scanf("%d",&a);
     printf("Enter the second number ");
     scanf("%d",&b);
     if(a<b)
        x=a;
     else
        x=b;

    tt: if(a%x==0&&b%x==0)
        printf("The GCD is %d",x);
     else
     {
         x=x-1;
         goto tt;
     }
 }








***Write C prog code to find GCD of two integers.(Alternative method)

#include
main()
{
    int a,b,x;
    printf("Enter the 1st number ");
    scanf("%d",&a);
    printf("Enter the 2nd number ");
     scanf("%d",&b);
     x=(a<b)?a:b;
    tt: if(a%x==0&&b%x==0)
        printf("The GCD is %d",x);
else
     {
         x=x-1;
         goto tt;
     }

}

***Write C prog code to find the area of triangle.

#include
 main()
 {
  float b,h,area;
  printf("Enter the value of b ");
  scanf("%f",&b);
  printf("Enter the value of h ");
  scanf("%f",&h);
  area=.5*b*h;
  printf("The area is %f",area);

 }

***Write C prog code to find the area of triangle.

 #include
 main()
 {
     float a,b,c,s,area;
     printf("Enter the value of a ");
     scanf("%f",&a);
     printf("Enter the value of b ");
     scanf("%f",&b);
     printf("Enter the value of c ");
     scanf("%f",&c);
     s=(a+b+c)/2;
     area=sqrt(s*(s-a)*(s-b)*(s-c));
     printf("the area is %f",area);

 }








***Write C prog code to show a number positive or negative.

 #include
 main()
 {
     int a;
     printf("Enter the number ");
     scanf("%d",&a);
     if(a>=0)
        printf("%d is positive",a);
     else
        printf("%d is negative",a);
}

***Write C prog code to find the largest number among three numbers a,b,c.

 #include
 main()
 {
   int a,b,c;
    printf("Enter the first number ");
   scanf("%d",&a);
   printf("Enter the second number ");
   scanf("%d",&b);
   printf("Enter the third number ");
   scanf("%d",&c);
   if(a>b&&a>c)
    printf("The largest number is %d",a);
if(b>c&&b>a)
printf("The largest number is %d",b);
if(c>a&&c>b)
printf("The largest number is %d",c);
     }








***Write C prog code to Find LEAP YEAR.

     #include
     main()
     {
         int year;
         printf("Enter year ");
         scanf("%d",&year);
         if(year%400==0||(year%100!=0&&year%4==0))
            printf("%d is the leap year",year);
         else
            printf("%d is not the leap year",year);
     }

***Write C prog code to transform centigrade temperature to farenhaite temperature.

 .
#include
main()
{
    float f,c;
printf("Enter Centregrade Temparature ");
scanf("%f",&c);
f=(9*c)/5+32;

printf("The result is %f",f);
}

***Write C prog code to show a character vowel or consonent.

#include
main()
{
 char vc;
 printf("Enter your letter ");
 scanf("%c",&vc);
 if(vc=='A'||vc=='a')
printf("The letter %c is vowel",vc);
else if(vc=='E'||vc=='e')
printf("The letter %c is vowel",vc);
else if(vc=='I'||vc=='i')
printf("The letter %c is vowel",vc);
else if(vc=='O'||vc=='o')
printf("The letter %c is vowel",vc);
else if(vc=='U'||vc=='u')
printf("The letter %c is vowel",vc);
else
printf("The letter %c is consonent",vc);
}








Leave a Reply

Your email address will not be published. Required fields are marked *