Some Basic programs to practice in C Programming Language

Codynn
5 Min Read

We also have mobile app where you can view all the c programs. For better experience we highy recommend you to use our mobile app

Please download our app by clicking the link. If link is not clicking please use this full url => https://play.google.com/store/apps/details?id=com.allbachelor.cprograms

  1. Write a C program to print the message “Welcome to C Programming”.

#include <stdio.h>

int main() {

    printf("Welcome to C Programming\n");

    return 0;

}
  1. Write a C program to input a number and print the square of a number.

#include <stdio.h>

int main() {

  int number;

  printf("Enter a number: ");

  scanf("%d", &number);

  int square = number * number;

  printf("The square of %d is %d\n", number, square);

  return 0;

}
  1. Write a C program to input a number and print the cube of a number.

#include <stdio.h>

int main() {

  int number;

  printf("Enter a number: ");

  scanf("%d", &number);

  int cube = number * number * number;

   printf("The cube of %d is %d\n", number, cube);

  return 0;

}
  1. Write a C program to input a number and print the square and cube of the number.

#include <stdio.h>

int main() {

  int number;

  printf("Enter a number: ");

  scanf("%d", &number);

  int square = number * number;

  int cube = number * number * number;

  printf("The square of %d is %d\n", number, square);

  printf("The cube of %d is %d\n", number, cube);

  return 0;

}
  1. Write a c program to input 2 numbers and find the sum of the number.

#include <stdio.h>

int main() {

  int number1, number2, sum;

  printf("Enter two numbers: ");

  scanf("%d %d", &number1, &number2);

  sum = number1 + number2;

   printf("The sum of %d and %d is %d\n", number1, number2, sum);

  return 0;

}
  1. Write a C program to input 2 numbers and find the product of the number.

#include <stdio.h>

int main() {

  int number1, number2, product;

  printf("Enter two numbers: ");

  scanf("%d %d", &number1, &number2);

  product = number1 * number2;

    printf("The product of %d and %d is %d\n", number1, number2, product);

  return 0;

}
  1. Write a C program to input 2 numbers and find the sum, product and difference of the numbers.

#include <stdio.h>

int main() {

  int number1, number2, sum, product, difference;

   printf("Enter two numbers: ");

  scanf("%d %d", &number1, &number2);

  sum = number1 + number2;

  product = number1 * number2;

  difference = number1 - number2;

   printf("The sum of %d and %d is %d\n", number1, number2, sum);

  printf("The product of %d and %d is %d\n", number1, number2, product);

  printf("The difference of %d and %d is %d\n", number1, number2, difference);

  return 0;

}
  1. Write a program in C to input a length and find the area and perimeter of the square.

#include <stdio.h>

int main() {

  float length, area, perimeter;

  printf("Enter the length of the square: ");

  scanf("%f", &length);

  area = length * length;

  perimeter = 4 * length;

   printf("The area of the square is %f\n", area);

  printf("The perimeter of the square is %f\n", perimeter);

  return 0;

}
  1. Write a program in C to input length and breadth and find the area and perimeter of the rectangle.

#include <stdio.h>

int main() {

  float length, breadth, area, perimeter;

  printf("Enter the length of the rectangle: ");

  scanf("%f", &length);

  printf("Enter the breadth of the rectangle: ");

  scanf("%f", &breadth);

   area = length * breadth;

  perimeter = 2 * (length + breadth);

    printf("The area of the rectangle is %f\n", area);

  printf("The perimeter of the rectangle is %f\n", perimeter);

  return 0;

}
  1. Write a program in C to input length, breadth, and height and find the volume of the box.

#include <stdio.h>

int main() {

  float length, breadth, height, volume;

  printf("Enter the length of the box: ");

  scanf("%f", &length);

  printf("Enter the breadth of the box: ");

  scanf("%f", &breadth);

  printf("Enter the height of the box: ");

  scanf("%f", &height);

  volume = length * breadth * height;

   printf("The volume of the box is %f\n", volume);

  return 0;

}
Share This Article
Leave a comment

Leave a Reply

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