Basic c programs
Basic C Programs
Aim:
1.1 - Write a program to calculate the area of a circle
Algorithm:
Accept radius
Print the area of a circle using formula
Program:
#include <stdio.h>
#include <stdlib.h>
int main(){
float radius;
printf("enter radius : ");
scanf("%f",&radius);
printf("the area of circle is %f \n",3.14*radius*radius);
printf("the circumference of circle is %f",3.14*2*radius);
return 0;
aim:
1.2 - Write a program to swap two numbers using a temporary variable
Algorithm:
Accept two numbers
Interchange the values using temporary variable
Print the interchanged values;
Program:
#include <stdio.h>
#include <stdlib.h>
int main(){int a,b;
printf("a = ");
scanf("%d",&a);
printf("b = ");
scanf("%d",&b);
int t=a;
a=b;
b=t;
printf("a = %d ,b = %d",a,b);
}
Aim:
1.3 - Write a program to Convert degrees fahrenheit into celcius
Algorithm:
Accept the temperature in fahrenheit then use the formula to print the temperature in celcius
Program:
//9c/5=f-32
#include <stdio.h>
#include<stdlib.h>
int main(){
float fahreinheit;
float x;
printf("give fahreinheit = ");
scanf("%f",&fahreinheit);
x=(fahreinheit-32.0)*5/9;
printf("the degree in celcius is %f",x);
return 0;
}
Aim:
1.4- Write a program to calculate the total amount of money in the piggybank, given the coins of
Rs.10,Rs.5 and Re.1
Algorithm:
Accept the number of coins
Multiply their values and the add it and print the result
Program:
#include<stdio.h>
#include<stdlib.h>
int main(){
int ten,five,one;
printf("give the number of 10,5,1 coins ");
scanf("%d,%d,%d",&ten,&five,&one);
printf(" your total amoint is %d",ten*10+five*5+one*1);
return 0;
}