Contact : +88 01840-723661

|

Email : info@jakafind.com

Cpp Programming Practice Part-01

C++ Programming Practice Part-01

 

01. Write a C program to compute the perimeter and area of a rectangle with a height of 7 inches and a width of 5 inches. 

Expected Output: 

The perimeter of the rectangle = 24 inches 

Area of the rectangle = 35 square inches 

    #include <stdio.h> 
    int main() { 
    int height, width, area, primeter; 
    height = 7; 
    width = 5; 
    primeter = 2*(height+width); 
    area = height*width; 
    printf("Perimeter = %d inchies\n", primeter); 
    printf("Area = %d square inchies\n", area); 
    return 0; } 

02. Write a C program to compute the perimeter and area of a circle with a given radius. 

Expected Output: 

Perimeter of the Circle = 37.680000 inches 

Area of the Circle = 113.040001 square inches 

    #include <stdio.h> 
    int main() { 
    double radius, perimeter, area, pi; 
    pi = 3.14159; 
    radius = 6; 
    perimeter = 2 * pi * radius; 
    area = pi * radius * radius; 
    printf("Perimeter of the Circle = %.6lf inches\n", perimeter); 
    printf("Area of the Circle = %.6lf square inches\n", area); 
    return 0; } 

03. Write a C program to convert specified days into years, weeks and days. 

Note: Ignore leap year. 

#include <stdio.h>  
int main() { 
int total_days, years, weeks, days; 
total_days = 1329; 
years = total_days / 365;  
weeks = (total_days % 365) / 7;  
days = total_days - ((years*365)+(weeks*7)); 
printf("Years: %d\n", years); 
printf("Weeks: %d\n", weeks); 
printf("Days: %d\n", days); 
return 0; 

04. Write a C program that reads two integers and checks whether they are multiplied or not. 

Test Data: 

Input the first number: 5 

Input the second number: 15 

Expected Output: Multiplied! 

  #include <stdio.h> 
  int main() { 
  int num_a, num_b; 
  printf("Input the first number: "); 
  scanf("%d", &num_a); 
  printf("Input the second number: "); 
  scanf("%d", &num_b); 
  if (num_b % num_a == 0) { 
    printf("Multiplied!"); 
  } else { 
    printf("Not multiplied!"); }
  return 0; } 

05. Write a C program to Check Whether a Number is Positive or Negative or Zero.

Explain the provided program using examples. 

    #include <stdio.h> 
    int main() { 
    int number; 
    printf("Enter a number: "); 
    scanf("%d", &number); 
    if (number > 0) { 
        printf("%d is positive.\n", number); 
    } else if (number < 0) { 
        printf("%d is negative.\n", number); 
    } else { 
        printf("The number is zero.\n"); } 
    return 0; } 

 06. Write a C program to Check Leap Year. Demonstrate the provided program using examples.

   #include<stdio.h> 
   int main() { 
   int year; 
   printf("Enter any year: "); 
   scanf("%d",&year); 
   if(year%400==0){ 
    printf("it's leap year = %d",year); 
    } else if(year%4==0 && year%100!=0){ 
    printf("it's leap year = %d",year); 
   } else printf("it's not leap year"); 
    return 0; } 

07. Write a C program for Even and Odd number. Provided program using examples: 

    #include <stdio.h> 
    int main() { 
    int num; 
    printf("Enter an integer: "); 
    scanf("%d", &num); 
    if(num % 2 == 0) 
    printf("%d is even.", num); 
    else 
    printf("%d is odd.", num); 
    return 0; } 

08. Write a C program for using If …. else and else if….

#include <stdio.h>
int main () {
int age;
printf("Enter value of age: ");
scanf("%d", &age);
if (age<2);{
printf("Intant\n");}
else if (age<10);{
printf("Child\n");
} else if (age<20);{
printf("Teenage\n");
} else if (age<30);{
printf("Adult\n");
} else {
printf("%d\n"); }
return 0; }

 

Thank You!

 

 

Leave a Reply

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