Page Rank Checker

Web Tourer

This Web Browser Is Completely Design And Coded By Me. Click Here For More Information Or Download.

Hardware

Click here to learn complete Computer Hardware without paying any cost. Articles are provided free of cost by WOLWEB.

Get Free Attractive Templates For Your Blog or Website

This Website Provide Free Attractive Templates For Download. For Download Just Click Here.

Let Us C Solution

This Is A Solution For Let Us C Book Written By Yashwant Kanetkar Learning Basic C Programming.

Page Rank Checker

Page Rank checker is a free tool to check Google™ page ranking of any web site pages easily and to display your site's PageRank™ value on your web pages

Alexa

Alexa is the leading provider of free, global web metrics. Search Alexa to discover the most successful sites on the web by keyword, category, or country.

Showing posts with label Let Us C Chapter 3 Solution. Show all posts
Showing posts with label Let Us C Chapter 3 Solution. Show all posts

Saturday, 5 July 2014

Sum Of First 7 Terms Of Natural Logarithm Program In C


This article is from solution of Let Us C by Yashwant Kanetkar. I also posted many another articles regarding solutions of Let Us C. If you have any problem regarding solution then give comment, I will surely reply your question.

Q. The natural logarithm can be approximated by the following series.
 
Ans.

#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
    clrscr();
    float x, ans=0, f_ans=0, s_ans;
    int n;
    printf("enter the value of x ");
    scanf("%f",&x);
    for(n=1;n<=7;n++)
    {
        if(n==1)
        {
            ans=pow(((x-1)/x),n);
        }
        else
        {
            s_ans=pow(((x-1)/x),n);
            ans=s_ans/2;
        }
        f_ans=f_ans+ans;
    }
    printf("Sum of first seven terms is %f",f_ans);
    getch();
}

Calculate Amount In Compound Interest Program In C


This article is from solution of Let Us C by Yashwant Kanetkar. I also posted many another articles regarding solutions of Let Us C. If you have any problem regarding solution then give comment, I will surely reply your question.

Q. When interest compounds q times per year at an annual rate of r% for n years, the principal p compounds to an amount a as per the following formula   
       a = p(1 + r/q)nq
      Write a program to read 10 seats of p, r, n & q and calculate the corresponding a.

Ans.

#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
    clrscr();
    float p, r, n, q, a;
    int i;
    for(i=1;i<=10;i++)
    {
        printf("\nenter values of p, r, n, q ");
        scanf("%f%f%f%f",&p,&r,&n,&q);
        a=p*pow((1+(r/q)),n*q);
        printf("\nValue of a is %f\n",a);
    }
    getch();
}

Minimum Life For Attractive Investment Program In C


This article is from solution of Let Us C by Yashwant Kanetkar. I also posted many another articles regarding solutions of Let Us C. If you have any problem regarding solution then give comment, I will surely reply your question.

Q. A machine is purchased which will produce earning of Rs. 1000 per year while it lasts. The machine costs Rs. 6000 and  will have a salvage value of Rs.2000 when it is condemned. If 12 percent per annum can be earned on alternate investments What will be the minimum life of the machine to make it more attractive investment compared to alternate investment?

Ans.

#include<stdio.h>
#include<conio.h>
void main()
{
    clrscr();
    int mchn_invst, altrnt_invst, yr=0;
    while(altrnt_invst>mchn_invst)
    {
        altrnt_invst=120*yr;
        mchn_invst=1000*yr-(6000-2000);
        yr++;
    }
    printf("Minimum life of machine to make it attractive is %d",yr);
    getch();
}

Produce Given Pattern With Numbers Program In C


This article is from solution of Let Us C by Yashwant Kanetkar. I also posted many another articles regarding solutions of Let Us C. If you have any problem regarding solution then give comment, I will surely reply your question.

Q. Write a program to produce the following output:
                              1
                        1          1
                   1         2          1
              1         3         3         1
          1       4         6         4         1

#include<stdio.h>
#include<conio.h>
void main()
{
    clrscr();
    int lines, n=1, spaces, tabs=8, x, y=1;
    for(lines=1;lines<=5;lines++)
    {
        for(spaces=1;spaces<=tabs;spaces++)
            printf(" ");
        printf("%4d",n);
        if(lines>=3)
        {
            for(x=1;x<=y;x++)
            {
                if(x==2&&y==3)
                    printf("%4d",lines+1);
                else
                    printf("%4d",lines-1);
            }
                y++;
        }
            if(lines>=2)
                printf("%4d",n);
            tabs=tabs-2;
            printf("\n");
    }
    getch();
}

Produce Given Pattern With 1-10 Numbers Program In C


This article is from solution of Let Us C by Yashwant Kanetkar. I also posted many another articles regarding solutions of Let Us C. If you have any problem regarding solution then give comment, I will surely reply your question.

Q. Write a program to produce the following output:
                         1
                   2          3
               4        5         6
          7       8         9          10

Ans.

#include<stdio.h>
#include<conio.h>
void main()
{
    clrscr();
    int n, i=1, no_tab;
    for(n=1;n<=10;n++)
    {
        if(n==1||n==2||n==4||n==7)
        {
            printf("\n\n");
            if(n==1)
            printf("\t\t\t");
            if(n==2)
            printf("\t\t");
            if(n==4)
            printf("\t");
        }
        printf("\t\t%d",n);
    }
    getch();
}

Print Multiplication Table Of Number Program In C


This article is from solution of Let Us C by Yashwant Kanetkar. I also posted many another articles regarding solutions of Let Us C. If you have any problem regarding solution then give comment, I will surely reply your question.

Q. Write a program to print the multiplication table of the number entered by the user. The table should get displayed in the following form:
      29 * 1 = 29
      29 * 2 = 58
      ......

Ans.

#include<stdio.h>
#include<conio.h>
void main()
{
    clrscr();
    int n, i, ans;
    printf("Enter any number ");
    scanf("%d",&n);
    for(i=1;i<=10;i++)
    {
        ans=n*i;
        printf("\n%2d * %2d  = %3d",n,i,ans);
    }
    getch();
}

Produce Given Pattern With A, B, C, D, E, F, G Program In C


This article is from solution of Let Us C by Yashwant Kanetkar. I also posted many another articles regarding solutions of Let Us C. If you have any problem regarding solution then give comment, I will surely reply your question.

Q. Write a program to produce the following output:
       A B C D E F G F E D C B A
       A B C D E F     F E D C B A
       A B C D E            E D C B A
       A B C D                  D C B A
       A B C                          C B A
       A B                                 B A
       A                                        A

Ans.

#include<stdio.h>
#include<conio.h>
void main()
{
    clrscr();
    int i, j, l;
    for(j=0,l=72;j<=6;j++,l--)
    {
        for(i=65;i<=71;i++)
        {
            if(i<l)
            printf("%c ",i);
            else
            printf("  ");
            if(i==71)
            {
                i--;
                for(;i>=65;i--)
                {
                    if(i<l)
                    printf("%c ",i);
                    else
                    printf("  ");
                }
                break;
            }
        }
        printf("\n");
    }
    getch();
}

Calculate Approximate Intelligence Program In C


This article is from solution of Let Us C by Yashwant Kanetkar. I also posted many another articles regarding solutions of Let Us C. If you have any problem regarding solution then give comment, I will surely reply your question.

Q. According to a study, the approximate level of intelligence of a person can be calculated using the following formula:
     i = 2 + (y + 0.5x)
     Write a program that 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 0.5.

Ans.

#include<stdio.h>
#include<conio.h>
void main()
{
    clrscr();
    float i, y, x;
    printf("Values Of\n");
    printf("i \ty \tx");
    for(y=1;y<=6;y++)
    {
        for(x=5.5;x<=12.5;x=x+0.5)
        {
            i=2+(y + (0.5*x));
            printf("%10f \t%10f \t%10f\n",i,y,x);
        }
    }
    getch();
}

Find All Combinations 1, 2 and 3 Program In C


This article is from solution of Let Us C by Yashwant Kanetkar. I also posted many another articles regarding solutions of Let Us C. If you have any problem regarding solution then give comment, I will surely reply your question.

Q. Write a program to generate all combinations of 1, 2 and 3 using for loop.

Ans.

#include<stdio.h>
#include<conio.h>
void main()
{
    clrscr();
    int n1, n2, n3;
    for(n1=1;n1<=3;n1++)
    {
        for(n2=1;n2<=3;n2++)
        {
            if(n1==n2)
            continue;
            for(n3=1;n3<=3;n3++)
            {
                if(n1==n3 || n2==n3)
                continue;
                printf("%d%d%d\n",n1,n2,n3);
            }
        }
    }
    getch();
}

Find Sum Of First 7 Terms Of Series Program In C


This article is from solution of Let Us C by Yashwant Kanetkar. I also posted many another articles regarding solutions of Let Us C. If you have any problem regarding solution then give comment, I will surely reply your question.

Q. Write a program to add first seven terms of the following series using a for loop:     
         1/1! + 2/2! + 3/3! + ............

Ans.

#include<stdio.h>
#include<conio.h>
void main()
{
    clrscr();
    float n1, n2, ans=0, n1_fact=1;
    for(n1=1;n1<=7;n1++)
    {
        n1_fact=1;
        for(n2=1;n2<=n1;n2++)
        {
            n1_fact=n1_fact*n2;
        }
        ans=ans+(n1/n1_fact);
    }
    printf("Answer is %f",ans);
    getch();
}

Fill Entire Screen With Smiling Faces Program In C



This article is from solution of Let Us C by Yashwant Kanetkar. I also posted many another articles regarding solutions of Let Us C. If you have any problem regarding solution then give comment, I will surely reply your question.

Q. Write a program to fill the entire screen with a smiling face. The smiling face has an ASCII value 1.

Ans.

#include<stdio.h>
#include<conio.h>
void main()
{
    clrscr();
    int n=1, x, y=0;
    for(;y<=150;y++)
    {
        x=0;
        for(;x<=150;x++)
        {
            printf("%c",n);
        }
    }
    getch();
}

Print All Prime Numbers Between 1 - 300 Program In C


This article is from solution of Let Us C by Yashwant Kanetkar. I also posted many another articles regarding solutions of Let Us C. If you have any problem regarding solution then give comment, I will surely reply your question.

Q. Write a program to print all prime numbers from 1 to 300.
      (Hint: Use nested loops, break and continue)

Ans.

#include<stdio.h>
#include<conio.h>
void main()
{
    clrscr();
    int num=2,i;
    for(;num<=300;num++)
    {
        for(i=2;i<300;i++)
        {
            if(i==num)
                continue;
            if(num%i==0)
                break;
            if((num%i!=0) && i==299)
                printf(" %d ",num);
        }
    }
    getch();
}

Find Range Of Set Of Numbers Program In C


This article is from solution of Let Us C by Yashwant Kanetkar. I also posted many another articles regarding solutions of Let Us C. If you have any problem regarding solution then give comment, I will surely reply your question.

Q. 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.

Ans.

#include<stdio.h>
#include<conio.h>
void main()
{
    clrscr();
    int num, max=-32768, min=32767, range;
    char choice='y';
    while(choice=='y')
    {
        printf("\nenter any number ");
        scanf("%d",&num);
        if(num>max)
            max=num;
        if(num<min)
            min=num;

        printf("\nYou Want To Add Another Number(y/n) ");
        fflush(stdin);
        scanf("%c",&choice);
    }
    range=max-min;
    printf("Range Is %d",range);
    getch();
}

Receive Integer And Find Its Octal Equivalent Program In C


This article is from solution of Let Us C by Yashwant Kanetkar. I also posted many another articles regarding solutions of Let Us C. If you have any problem regarding solution then give comment, I will surely reply your question.

Q. Write a program to receive an integer and find its octal equivalent.

Ans.

#include<stdio.h>
#include<conio.h>
void main()
{
    clrscr();
    int n, oct[10], quo, i=0, j=-1;
    printf("Enter any number ");
    scanf("%d",&n);
    quo=n;
    while(quo!=0)
    {
        oct[i]=quo%8;
        quo=quo/8;
        i++;
        j++;
    }

    printf("\nOctal Equilvalent Is\n");
    for(;j>=0;j--)
    {
        printf("%d",oct[j]);
    }
    getch();
}

Sunday, 1 June 2014

Count Of Positive, Negative Numbers And Zeroes Program In C


This article is from solution of Let Us C by Yashwant Kanetkar. I also posted many another articles regarding solutions of Let Us C. If you have any problem regarding solution then give comment, I will surely reply your question.

Q. Write a program to enter the numbers till the user wants and at the end it should display the count of positive, negative, and zeros entered.

Ans.

#include<stdio.h>
#include<conio.h>
void main()
{
    clrscr();
    int i, pos=0, neg=0, zer=0;
    char choice='y';
    while(choice=='y')
    {
        printf("\nenter any number ");
        scanf("%d",&i);
        if(i>=1)
        pos=pos+1;
        if(i<=-1)
        neg=neg+1;
        if(i==0)
        zer=zer+1;
        printf("\nYou Wanted To Type Another Number(y/n) ");
        fflush(stdin);
        scanf("%c",&choice);
    }
    printf("\nCount Of Positive Numbers Entered By User Is %d",pos);
    printf("\nCount Of Negative Numbers Entered By User Is %d",neg);
    printf("\nCount Of Zeroes Entered by User Is %d",zer);
    getch();
}

Matchstick Game Program In C


This article is from solution of Let Us C by Yashwant Kanetkar. I also posted many another articles regarding solutions of Let Us C. If you have any problem regarding solution then give comment, I will surely reply your question.

Q. Write a program for a matchstick game being played between the computer and a user. Your program should ensure that the computer always wins. Rules for the game are as follows.
1.There are total 21 matchsticks.
2.You can select either 1, 2, 3 or 4 matchsticks at a time.
3.After the person picks Computer does its picking.
4.Whoever is forced to pick up the last matchstick loses the game.

Ans.

#include<stdio.h>
#include<conio.h>
void main()
{
    clrscr();
    int usr=0,i,comp=0,rmnf,rmn=21;
    printf("Rules For The Game:\n");
    printf("1.There are total 21 matchsticks.\n2.You can select either 1, 2, 3 or 4 matchsticks at a time.\n3.After the person picks Computer does its picking\n4.Whoever is forced to pick up the last matchstick loses the game.");
    do
    {
        rmn=rmn-comp;
        printf("\n\nRemaining Matchsticks: %d",rmn);
        printf("\nEnter number of matchsticks you pick: ");
        scanf("%d",&usr);
        clrscr();
        if((usr<=4 && rmn>=6) || (usr==1 && rmn<=6))
        {
            rmn=rmn-usr;
            if(rmn!=0)
            {
                comp=5-usr;
                printf("\nYou have selected %d Matchsticks",usr);
                printf("\nComputer Selected %d Matchsticks",comp);
            }
            else if(rmn==0)
            {
                printf("\nRemaining Matchsticks Are %d",rmn);
                printf("\nYou Picked Last Matchstick");
                printf("\nYOU LOST THE GAME");
                break;
            }
        }
        else
        {
            printf("\nPlease Enter a valid choice i.e. 1 2 3 or 4");
            comp=0;
        }
    }while(1);
    getch();
}

The logic behind the program is:
There are total 21 matchsticks and who forced to select last one is lost and we wanted to make a program in which computer always win so the last matchstick should be selected by the user. so we wanted that whenever the last selection of user is come into the picture at that time there should be only 1 matchstick remaining and there is a rule that user or computer can select at most 4 matchsticks at a time so for making force on user to select last matchstick whenever the user's second last (last is the turn when there is only 1 matchstick remaining) selection turn is arrived at that time there should be 6 matchsticks remaining so user selects any number of match sticks from 1,2,3 or 4 after that computer selects (5-number of matchsticks selected by the user ) so at the selection turn of user there is only one matchstick is remaining. This last step is possible only if at each turn the sum of selected matchsticks by computer and selected matchsticks by user is 5. so we tell the computer via program that after each time the selection done by user computer should select (5-number of matchsticks selected by the user) matchsticks so at each turn there should 5 matchsticks less than the previous turn.

So the whole program is run in following fashion
At 1st turn
Remaining Matchsticks :- 21
User selects 1,2,3 or 4 matchsticks
Computer Selects 5-number of matchsticks selected by the user

At 2nd turn
Remaining Matchsticks :- 16
User selects 1,2,3 or 4 matchsticks
Computer Selects 5-number of matchsticks selected by the user

At 3rd turn
Remaining Matchsticks :- 11
User selects 1,2,3 or 4 matchsticks
Computer Selects 5-number of matchsticks selected by the user

At 4th turn
Remaining Matchsticks :- 6
User selects 1,2,3 or 4 matchsticks
Computer Selects 5-number of matchsticks selected by the user

At 5th turn
Remaining Matchsticks :- 1
User selects 1 matchstick because only 1 matchstick is remaining

Calculate Armstrong Numbers Program In C


This article is from solution of Let Us C by Yashwant Kanetkar. I also posted many another articles regarding solutions of Let Us C. If you have any problem regarding solution then give comment, I will surely reply your question.

Q. Write a program to print out all Armstrong numbers between 1 and 500. If sum of cubes of each digit of the number is equal to the number itself, then the number is equal to the number itself, then the number is called an Armstrong number. For example, 153=(1*1*1)+(5*5*5)+(3*3*3).

Ans.

#include<stdio.h>
#include<conio.h>
void main()
{
    clrscr();
    int num=1, hun, dec, unit;
    for(;num<=500;num++)
    {
        hun=num/100;
        dec=(num-hun*100)/10;
        unit=(num-(hun*100)-(dec*10))/1;
        if((hun*hun*hun)+(dec*dec*dec)+(unit*unit*unit)==num)
        printf("\n%d is a Armstrong number",num);
    }
    getch();
}

Print ASCII Value Of All Characters Program In C


This article is from solution of Let Us C by Yashwant Kanetkar. I also posted many another articles regarding solutions of Let Us C. If you have any problem regarding solution then give comment, I will surely reply your question.

Q. Write a program to print all the ASCII values and their equivalent characters using a while loop. The ASCII values vary from 0 to 255.

Ans.

#include<stdio.h>
#include<conio.h>
void main()
{
    clrscr();
    int i=0;
    while(i<=255)
    {
        printf("\nASCII Value Of %c is %d",i,i);
        i++;
    }
    getch();
}

Find value Of Number Raised To Another Number Program In C


This article is from solution of Let Us C by Yashwant Kanetkar. I also posted many another articles regarding solutions of Let Us C. If you have any problem regarding solution then give comment, I will surely reply your question.

Q. Two numbers are entered through the keyboard. Write a program to find the value of one number raised to the power of another.

Ans.

#include<stdio.h>
#include<conio.h>
void main()
{
    clrscr();
    int num1, num2, i, ans=1;
    printf("enter any two numbers ");
    scanf("%d%d",&num1,&num2);
    // we wanted to find out num1 raised to num2
    for(i=1;i<=num2;i++)
    {
        ans=ans*num1;
    }
    printf("Answer is %d",ans);
    getch();
}

Find Factorial Value Program In C


This article is from solution of Let Us C by Yashwant Kanetkar. I also posted many another articles regarding solutions of Let Us C. If you have any problem regarding solution then give comment, I will surely reply your question.

Q. Write a program to find the factorial value of any number entered through the keyboard.

Ans.

#include<stdio.h>
#include<conio.h>
void main()
{
    clrscr();
    int i, num, fact=1;
    printf("enter a number ");
    scanf("%d",&num);
    for(i=1;i<=num;i++)
    {
        fact=fact*i;
    }
    printf("\nFactorial Value Of The Number entered By User Is %d",fact);
    getch();
}