/********************************
* This is the first Program
* first.c
* Compile: cc -Wall first.c
********************************/
#include <stdio.h>
int main()
{
printf("Tamaso Ma Jyotir Gamaya\n") ;
return 0 ;
}
/*********************************
* Second program: second.c
* Compile: cc -Wall second.c
*********************************/
#include <stdio.h>
int main() {
int n ;
printf("Enter a non Negative integer: ") ;
scanf("%d", &n) ; /* Reads an integer */
printf("\nSum of (0 + ... + %d) = %d\n", n, n*(n + 1)/2 ) ;
return 0 ;
} // second.c
/*****************************************
* Third program: third.c
* Area of a Circle:
* Compile: cc -Wall -lm third.c
*****************************************/
#include <stdio.h>
#include <math.h>
int main() {
float radius, area ;
printf("Enter the radius :") ; scanf("%f", &radius) ;
area = 4.0 * atan(1.0) * radius * radius ;
printf("\n Circle-Area = %f for Radius = %f\n", area, radius) ;
return 0 ;
} // third.c
/******************************************
* Convert Fahrenheit to Celsius: fourth.c
******************************************/
#include <stdio.h>
int main(){
float cel, fah ;
printf("Enter temp. in F: ") ;
scanf("%f", &fah) ;
cel = 5.0*(fah-32.0)/9.0 ;
printf("%6.2f F = %6.2f C\n", fah, cel) ;
return 0 ;
}
/*************************************
* Fifth program: fifth.c
* ***********************************/
#include <stdio.h>
int main() {
int first, second, max ;
printf("Enter two integers :") ;
scanf("%d%d", &first, &second) ;
if(first > second) max = first ;
else max = second ;
printf("\nMax(%d,%d) = %d\n", first, second, max) ;
return 0 ;
}
/************************************
* Sixth: sixth.c
************************************/
#include <stdio.h>
int main() {
int n, i, sum = 0 ;
printf("Enter a non-negative integer:") ;
scanf("%d", &n) ;
for(i = 0; i <= n; ++i) sum += i ;
printf("\nSum of (0 + ... + %d) = %d\n", n, sum ) ;
return 0 ;
}