Thursday, 11 September 2014

Write a program to do swapping of two numbers using third variable.

#include<stdio.h>

main()
{
    int a,b,c;
    printf("\nEnter two numbers=");
    scanf("%d%d",&a,&b);
    printf("\nBefore swapping");
    printf("\na=%d,b=%d",a,b);
    c=a;
    a=b;
    b=c;
    printf("\nafter swapping");
    printf("\na=%d,b=%d",a,b);
}

Friday, 29 August 2014

Q.Which of the following is not an unconditional control statement in ‘C’?
a) break
b) continue
c) exit()
d) while

Ans: while

Friday, 30 May 2014

Write a program to print even numbers from 1 to 50.

#include<stdio.h>

main()
{
    int i=1;
   
    printf("\nEven numbers from 1 to 50=");
   
    while(i<=50)
    {
        if(i%2==0)
            printf("%d ",i);
        i++;
    }
}

Write a program to display your name upto 10 times using while loop.

#include<stdio.h>

main()
{
    int i=1;
    char name[100];
    printf("\nEnter your name=");
    gets(name);
    while(i<=10)
    {
        printf("\n%s",name);
        i++;
    }
}

Program to calculate area of a triangle. Base and height given by the user.

#include<stdio.h>

main()
{
    float l,b,area;
    printf("\nEnter base and height of the triangle=");
    scanf("%f%f",&b,&h);
    area=0.5*b*h;
    printf("\nThe area=%d",area);
}

Thursday, 29 May 2014

Write a program to simple interest, compound interest and amount.

#include<stdio.h>
#include<math.h>
main()
{
    float p,r,n,si,ci,cia,temp;
   
    printf("\nEnter Principal, rate of interest and number of years=");
    scanf("%f%f%d",&p,&r,&n);

    si=p*n*r/100;
    cia=p*pow((1+(r/100)),n);
    ci=cia-p;

    printf("\nSimple Interest=%f, Amount=%f",si,si+p);
    printf("\nCompound Interest=%f, Amount=%f",ci,cia);
}

Monday, 26 May 2014

Write a program to calculate the sum of all the numbers from 1 to 50 using for loop.

#include<stdio.h>

main()
{
    int i,sum=0;
    for(i=1;i<=50;i++)
    {
        sum=sum+i;
    }
    printf("\nSum of all the number from 1 to 50=%d",sum);
}