Basic C Programs


 Table Of Contents

  1. C Program to Print Hello World
  2. C Program to add Two numbers
  3. C Program to Calculate Compound Interest
  4. C Program to Check Odd or Even
  5. C Program to Print Multiplication Table using For Loop


Basic C Programs

1) C Program to Print Hello World
Code:
#include <stdio.h>
int main()
{
printf("\n Hello World");
return 0;
}
Output:

2) Program to add Two numbers
Code:
#include <stdio.h>
int main()
{
int number1, number2, sum;
printf(" Enter two integer values \n ");
scanf("%d %d", &number1, &number2);
sum = number1 + number2;
printf(" Sum of the two integer values is %d", sum);
return 0;
}
Output:

3) C Program to Calculate Compound Interest
Code:
#include <stdio.h>
#include <math.h>

int main()
{
float PAmount, ROI, Time_Period, CIFuture, CI;

printf("\nPlease enter the Principal Amount : \n");
scanf("%f", &PAmount);

printf("Please Enter Rate Of Interest : \n");
scanf("%f", &ROI);

printf("Please Enter the Time Period in Years : \n");
scanf("%f", &Time_Period);

CIFuture = PAmount * (pow(( 1 + ROI/100), Time_Period));
CI = CIFuture - PAmount;

printf("\nFuture Compound Interest for Principal Amount %.2f is = %.2f", PAmount, CIFuture);
printf("\nCompound Interest for Principal Amount %.2f is = %.2f", PAmount, CI);

return 0;
}
Output:

4) C Program to Check Odd or Even
Code:
#include <stdio.h>
int main()
{
int number;

printf(" Enter an int value to check Even or Odd \n");
scanf("%d", &number);

if ( number%2 == 0 ) //Check whether remainder is 0 or not
printf("Given number %d is EVEN NUMBER \n", number);

else
printf("Given number %d is ODD NUMBER \n", number);

return 0;
}
Output:

5) C Program to Print Multiplication Table using For Loop
Code:
#include <stdio.h>
int main()
{
  int i, j;
  printf("\n Multiplication Table of 8 and 9 are: \n");
for (i = 8; i < 10; i++) { for (j = 1; j <= 10; j++) { printf("%d * %d = %d\n",i ,j, i*j); } printf("\n ==========\n"); } return 0; }
Output:

More Questions Coming Soon..

Post a Comment

Previous Post Next Post
Best Programming Books

Facebook

AJ Facebook
Checkout Our Facebook Page
AJ Blogs
Checkout Our Instagram Page