Wednesday, June 9, 2021

Basic questions and answers of C program using constant, Variable, and keywords

Core questions of  C Program using constant, variable and keywords.



Here we will try to solve some questions

Question. Write a Program to print “HELLO MESSWITHAGE”?

Answer  To write this program we will use the function printf

          #include<stdio.h>

           int main()

          {

                         printf("HELLO MESSWITHAGE");

                         return 0;

           }

Output

The output of the above C program

Question. Write a program to calculate Sum, Difference, Product, Quotient, and Remainder of two numbers?

Answer

 #include<stdio.h>

int main()

{

    int a,b,c,sum,difference,product,quotient,remainder;

    printf("Enter first number : ");

    scanf("%d",&a);

    printf("Enter second number : ");

    scanf("%d",&b);

    sum=a+b;

    printf("Sum of numbers : %d",sum);

    difference=a-b;

    printf("\nDifference of numbers : %d",difference);

    product=a*b;

    printf("\nProduct of numbers : %d",product);

    quotient=a/b;

    printf("\nQuotient of numbers : %d",quotient);

    remainder=a%b;

    printf("\nRemainder of numbers : %d",remainder);

    return 0;

}

Output

The output of adding, subtracting, multiplication, and division

Question. Write a program to calculate the area of a circle?

Answer 

         #include<stdio.h>

         int main ()

         {

          float radius,area;

          printf("Radius of circle : ");

          scanf("%f",&radius);

          area=3.14*radius*radius;

          printf("Area of circle : %f",area);

          return 0;  

          }

Output 

                

Area of Circle by C programming


Question. Write a program to calculate the area and perimeter of a rectangle?

Answer 

#include<stdio.h>

int main ()

           {

    int length,breadth,area,perimeter;

               printf("Enter length of rectangle : ");

               scanf("%d",&length);

               printf("Enter breadth of rectangle : ");

               scanf("%d",&breadth);

               area=length*breadth;

               printf("Area of rectangle : %d",area);

               perimeter=2*(length+breadth)

               printf("\nPerimeter of rectangle : %d",perimeter);

               return 0;

           }

Output 

Area and perimeter of a rectangle


QuestionWrite a program to calculate the area and perimeter of the triangle?

Answer

 #include<stdio.h>

int main()

{

    float length,breadth,side,perimeter,area;

    printf("Enter first number : ");

    scanf("%f",&length);

    printf("Enter second number : ");

    scanf("%f",&breadth);

    printf("Enter third number : ");

    scanf("%f",&side);

    area=(length*breadth)/2;

    printf("Area of triangle : %f",area);

    perimeter=length+breadth+side;

    printf("\nPerimeter of triangle : %f",perimeter);

    return 0;

}

Output 

Area and perimeter of a triangle


Thanks for reading this, For further such question continue to visit our website messwithage. 

No comments:

Post a Comment

Please do not enter any spam link in the comment box

Best of Our Website

Popular Posts