1.Write a program that prints Hello World! on screen.
|
#include <stdio.h> int main() { printf("Hello World!"); return 0; } |
2. Sum of two integers
|
#include <stdio.h> int main() { int num1, num2, sum; printf("Enter first number :"); scanf("%d", &num1); printf("Enter second number :"); scanf("%d", &num2); sum = num1 + num2; printf("sum of two numbers is %d", sum); return 0; } |
3. Celsius to Farenheit conversion
|
#include <stdio.h> int main() { float celsius, fahrenheit; printf("Enter the temperature in celcius :"); scanf("%f", &celsius); /*Converting celcius to fahrenheit */ fahrenheit = 9.0 / 5 * celsius + 32; printf("Temperature in fahrenheit : %0.2f", fahrenheit); return 0; } |
4. Simple interest
|
#include <stdio.h> int main() { float principle, rate, time, simple_interest; printf("Enter the principle :"); scanf("%f", &principle); printf("Enter the rate :"); scanf("%f", &rate); printf("Enter the time :"); scanf("%f", &time); simple_interest = principle * rate * time / 100; printf("Simple interest is %0.2f", simple_interest); return 0; } |
5. Print ASCII value
|
#include <stdio.h> int main() { char letter; printf("Enter a character :"); scanf("%c", &letter); printf("ASCII value of %c is %d.", letter, letter); return 0; } |
6. Swapping of two numbers
|
#include <stdio.h> int main() { int num1, num2, temp; printf("Enter first number :"); scanf("%d", &num1); printf("Enter second number :"); scanf("%d", &num2); temp = num1; num1 = num2; num2 = temp; printf("After swapping, first is %d and second is %d.", num1, num2); return 0; } |
7. Area and circumference of Circle
|
#include <stdio.h> int main() { float radius, area, circumference; printf("Enter the radius of the circle :"); scanf("%f", &radius); area = 3.14 * radius * radius; circumference = 2 * 3.14 * radius; printf("\nThe area of the circle is %0.2f", area); printf("\nThe circumference of the circle is %0.2f", circumference); return 0; |
8.Area and circumference of Rectangle
|
#include <stdio.h> int main() { int length, width, area, circumference; printf("Enter the length of the rectangle :"); scanf("%d", &length); printf("Enter the width of the rectangle :"); scanf("%d", &width); area = length * width; circumference = 2 *(length + width); printf("\nThe area of the rectangle is %d.", area); printf("\nThe circumference of the rectangle is %d.", circumference); return 0; } |
9. Area of Triangle
|
#include <stdio.h> #include <math.h> int main() { float a, b, c, s, area; printf("Enter the length of side 1 :"); scanf("%f", &a); printf("Enter the length of side 2 :"); scanf("%f", &b); printf("Enter the length of side 3 :"); scanf("%f", &c); s = (a + b + c) / 2; area = sqrt(s*(s - a)*(s - b)*(s - c)); printf("\nThe area of the triangle is %0.2f", area); return 0; } |
[…]
Continue Reading