Skip to main content

Posts

Showing posts from May, 2014

Compute area of Circle,Squar,Triangle

#include<stdio.h> int main() {     char ch;     printf("Enter c to compute area of Circle\n");     printf("Enter s to compute area of Square\n");     printf("Enter c to compute area of Triangle\n");     ch=getchar();     printf("\n");     if(ch=='c')     {         printf("Enter radius of circle : ");         scanf("%f",&s1);         printf("Area is : %f ",3.1416*radius*radius);     }     else if(ch=='s')     {         printf("Enter Length of first side : ");         scanf("%f",&s1);         printf("Enter Length of second side : ");         scanf("%f",&s2);  ...

Finding digit number of a number

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 #include<stdio.h> int main() { long long int a,b, sum ,temp,count = 0 ,count_1 = 1 ; while ( (scanf( "%lld %lld" , & a, & b)) != EOF) { if (a <= 1000000 && b <= 1000000 ) { sum = a + b; temp = sum ; while (temp != 0 ) { sum /= 10 ; temp = sum ; count ++ ; } printf( "%lld \n " ,count); } count = 0 ; if (count_1 > 200 ) break ; count_1 ++ ; } return 0 ; }

Use of islower function in c

#include<stdio.h> #include<ctype.h> void main() {    char ch;    for(;;)     {         ch=getchar();         if(ch==' ')             break;         if(islower(ch))             printf("%c is a lower case char\n",ch);     } }

Use of isupper function

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 #include<stdio.h> #include<ctype.h> void main() { char ch; for (;;) { ch = getchar(); if (ch == ' ' ) break ; if (isupper(ch)) printf( " %c is a upper case char \n " ,ch); } }

Calender Program in C Programming Language Display Day of the month

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 #include<stdio.h> int fm( int date, int month, int year) { int fmonth,leap; /// leap function ... 1 for leap & 0 for non - leap if ((year % 100 == 0 ) && (year % 400 != 0 )) leap = 0 ; else if (year % 4 == 0 ) leap = 1 ; else leap = 0 ; fmonth = 3 + ( 2 - leap) * ((month + 2 ) / ( 2 * month)) + ( 5 * month + month / 9 ) / 2 ; /// f(m) formula fmonth = fmonth % 7 ; /// bring it in range of 0 to 6 return fmonth; } int day_of_week( int date, int month, int year) { int dow; // day of week int YY = year % 100 ; int century = year / 100 ; printf( " \n Date: %d / %d / %d \n\n " ,date,month,year); dow = ...

Collatz/Hailstone sequence

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 #include<stdio.h> int main() { int a; printf( "ENTER A POSITIVE NUMBER:" ); scanf( " %d " , & a); printf( "Collatz/Hailstone Sequence For This Number: \n\n " ); printf( " %d " ,a); while (a != 1 ) { if (a % 2 == 0 ){ a = a / 2 ; } else { a = 3 * a + 1 ; } printf( ", %d " ,a); } getch(); return 0 ; }

CREATING FLOYD'S TRIANGLE

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 #include<stdio.h> int main() { int i,j,n,k = 1 ; printf( "Enter the range: " ); scanf( " %d " , & n); printf( "FLOYD'S TRIANGLE \n\n " ); for (i = 1 ;i <= n;i ++ ) { for (j = 1 ;j <= i;j ++ ,k ++ ) printf( " %d " ,k); printf( " \n " ); } return 0 ; }

How to print top 3 hill from a list

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 #include<stdio.h> int main() { int hight[ 10 ]; int a,b,t; for (a = 0 ;a < 10 ;a ++ ) // input 10 hill hight scanf( " %d " , & hight[a]); for (a = 1 ;a < 10 ;a ++ ) { for (b = 9 ;b >= a;b -- ) { if (hight[b - 1 ] < hight[b]) // putting big hight first { t = hight[b - 1 ]; hight[b - 1 ] = hight[b]; hight[b] = t; } } } for (t = 0 ;t < 3 ;t ++ ) printf( " %d \n " ,hight[t]); // print top three hill return 0 ; }

Finding Right Triangle

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 #include<stdio.h> #include<math.h> int main() { long long int a,b,d,n,w; float c; scanf( "%lld" , & n); if (n <= 1000 ) { for (w = 1 ;w <= n;w ++ ) { scanf( "%lld%lld%lld" , & a, & b, & d); if (a <= 1000 && b <= 1000 && d <= 1000 ) { c = sqrt(a * a + b * b); if (c == d) printf( "YES \n " ); else printf( "NO \n " ); } } } return 0 ; }