Posts

Showing posts from January, 2013

Math Functions (Using COSINE Function)

Write a program to show the use of Math Functions. Hints: We often use standard mathematical functions such as cos,sin,exp,etc. We shall see now the use of a mathematical function in a program. The standard mathematical functions are defined and kept as a part of C math library. #include<math.h> #define PI       3.1416 #define MAX       180 main() {  int angle;  float x,y;  angle = 0;  printf("        Angle        Cos(angle)\n\n");  while (angle <= MAX)  {    x = (PI / MAX) * angle;    y = cos(x);    printf("%15d  %13.4f\n", angle,y);    angle = angle + 10;   } } Output:         Angle        Cos(angle)                0         1.0000               10         0.9848               20         0.9397               --            ----               --            ----               180       -1.0000

Use of Subroutines

Write a program to show the use of subroutines Hints: We have used only printf function that has been provided for us by the C system. The program below uses a user-defined function. A function defined by the user is equivalent to subroutine in FORTRAN or Subprogram in Basic. main() {  int a,b,c;  a=5;  b=10;  c=mul(a,b);  printf("Multiplication of  %d and %d is %d", a,b,c);  } mul(x,y) int p,x,y; {   p =x*y;   return (p);  } << Go to Index Page >>

Interest Calculation

এই প্রোগ্রামটির মাধ্যমে একজন শিক্ষার্থী ডাটা টাইপের ব্যাবহার এবং While লুপ নিয়ে কাজ করা শিখতে পারবে ।  আউটপুটকে কিভাবে ২ টি কলামে/সারিতে আলাদা করে প্রিন্ট করা যায় তাও এখানে আছে । প্রোগ্রামটি পাটিগনিতের সহজ অংকের প্রতিফলন। এখানে একজন ব্যাক্তির ৫০০০ টাকার বিনিয়োগের বিপরীতে প্রতি বছরে ১১% হারে সুদ সংযুক্ত করলে বছর শেষে তার কত টাকা সুদে-আসলে দাঁড়াবে তা নির্নয় করা হয়েছে ।  এভাবে ১ম থেকে ১০তম বছর পর্যন্ত টাকাটি বিনিয়োগ হতে থাকলে ১০ তম বছর শেষে তার মোট মূলধন কত দাড়াবে তাও এই প্রোগ্রামটির মাধ্যমে নির্নয় করা যাবে । Problem:  Write a program which calculates the value of money at the end of each year of investment . Hints: Assuming an interest rate of 11 percent and prints the year and the corresponding amount, in two columns. The sample output is shown below for a period of 10 years with an initial investment of 5000.00. The program uses the following formula: value at end of year = Value at start of year (1+ interest rate) Source Code: #include<stdio.h> #define PERIOD 10

Adding Two numbers using float and integer data

নিম্নের সোর্সকোডের মাধ্যমে পূর্ণসংখ্যাকে(Integer) এবং বাস্তব সংখ্যাকে(real number) কিভাবে যোগ করা যায় এবং তা প্রিন্ট(show) করা যায় তা শেখা যাবে । ভেরিয়েবল এবং ডাটা টাইপ সম্পর্কে বিস্তারিত বুঝার জন্য ভিজিট করুন:  http://www.cprogramming-bd.com/tutorial/c_tutorial_page_6.aspx Problem: Write a program which performs addition on two numbers and display the result. Use float and Integer data type Source Code: #include<stdio.h> main() {   int number;   float amount;   //integer data representation   number=100+10;   //float data representation   amount =30.75 +  75.35;   printf("%d\n", number);   printf("%5.2f",amount); } Output: 110 106.10 << Go to Index Page >>