Posts

Showing posts from June, 2018

Chapter 5 : Functions & Pointers (Let us C)

Write a function to calculate the factorial value of any integerentered through the keyboard. #include <stdio.h> main() { int a, f; printf("enter any number="); scanf("%d",&a); f=fact(a); printf("%d!=%d",a,f); } fact(int x) { int i,f=1; for(i=x;i>=1;i--) { f=f*i; } } Output: enter any number=33 33!=-2147483648

Let Us C / Chapter 4 (The Case Control Structure)

Programming Solutions ( By:MK )                                 Exercise [C] Write a menu driven program which has following options: 1. Factorial of a number. 2. Prime or not 3. Odd or even 4. Exit                           Solution: #include<stdio.h> #include<conio.h> main() { int num,i,j=0,k=0,choice,fact=1; clrscr(); printf("Please enter any number: "); scanf("%d",&num); while(1) { printf("\n\n1. Factorial"); printf("\n2. Prime"); printf("\n3. Odd/Even"); printf("\n4. Exit"); printf("\n\nPlease enter your choice:  "); scanf("%d",&choice); switch(choice) { case 1:      for(i=num;i>=1;i--) {      fact=fact*i;      }      printf("\nFactorial = %d ",fact);      break; case 2:   ...

According to a study, the approximate level of intelligence of a person can be calculated using the following formula: i = 2 + ( y + 0.5 x ) Write a program, which will produce a table of values of i, y and x, where y varies from 1 to 6, and, for each value of y, x varies from 5.5 to 12.5 in steps of 0.5.

According to a study, the approximate level of intelligence of a person can be calculated using the following formula: i = 2 + ( y + 0.5 x ) Write a program, which will produce a table of values of i, y and x, where y varies from 1 to 6, and, for each value of y, x varies from 5.5 to 12.5 in steps of 0.5.  Let C Solution: #include<stdio.h> main() { int y; float i,x;    for (y=1; y<=6; y++)    {      for (x=5.5; x<=12.5;x=x+0.5)       {         i=2 + (y+ (0.5*x)) ;         printf("\n i=%.2f, y=%d, x=%.2f", i, y, x);       }    } } output:  i=5.75, y=1, x=5.50  i=6.00, y=1, x=6.00  i=6.25, y=1, x=6.50  i=6.50, y=1, x=7.00  i=6.75, y=1, x=7.50  i=7.00, y=1, x=8.00  i=7.25, y=1, x=8.50  i=7.50, y=1, x=9.00  i=7.75, y=1, x=9.50  i=8.00, y=1, x=10.00...

Write a program to find the range of a set of numbers. Range is the difference between the smallest and biggest number in the list.

#include<stdio.h> main() {        int elme,i,num,n,large,small,Range;     printf("Total Number of Element:");     scanf("%d",&elme);     printf("Enter first number=");     scanf("%d",&n);     large=n;     small=n;     for(i=1;i<=elme-1;i++)     {         printf("Enter another Number=");         scanf("%d",&n);                 if(n>large)         large=n;         if(n<small)         small=n;     }     printf("Largest=%d\n",large);     printf("Smallest=%d\n",small);     Range=large-small;     printf("Range=%d",Range); } OUTPUT: T...

Given the coordinates (x, y) of a center of a circle and it’s radius, write a program which will determine whether a point lies inside the circle, on the circle or outside the circle.

C Programm: #include<stdio.h> main() { int x,y,r; int di,ra; printf("Enter the value of x and y:"); scanf("%d %d",&x,&y); printf("Enter the radius:"); scanf("%d",&r); di=x^2+y^2; ra=r^2; if(di==r) printf("Point on the Circle"); else if(di>r) printf("Point outside the Circle"); else if(di<r) printf("Point inside the Circle"); } Math:The distance between ⟨ x c , y c ⟩ and ⟨ x p , y p ⟩ is given by the Pythagorean theorem as d = ( x p − x c ) 2 + ( y p − y c ) 2 − − − − − − − − − − − − − − − − − − √ . The point ⟨ x p , y p ⟩ is inside the circle if d < r , on the circle if d = r , and outside the circle if d > r . You can save yourself a little work by comparing d 2 with r 2 instead: the point is inside the circle if d 2 < r 2 , on the circle if d 2 = r 2 , and outside the circle if d 2 > r 2 . Thus, you want to compare the number ( x p − x c ) 2 + ( y p − y c ) 2 with...