Preliminary C programming

  • Write a program to print “Hellow World”.#include<stdio.h>
    #include<conio.h>
    void main()
    {
    clrscr();
    printf(“Hellow World”);
    getch();
    }
  • The length and height of a rectangle and radius of a circle are input through the keyboard.Write a program to find the area & perimeter of the rectangle and circumference of the circle.
    #include<stdio.h>
    #include<conio.h>void main()
    {
    clrscr();
    int length,height,area,per,rad,cir;
    printf(“Enter a length? \n”);
    scanf(“%d”,&length);
    printf(“Enter a height? \n”);
    scanf(“%d”,&height);
    printf(“Enter a radius?\n”);
    scanf(“%d”,&rad);area=length*height;

    per=2*(length+height);
    cir=2*3.1416*rad;
    printf(“The perimiter is: %d\n”,per);

    printf(“The area is: %d\n”,area);
    printf(“The circumference is:%d”,cir);

    getch();
    }

  • Rahim’s basic salary is inpute through the keyboard.His house rent allowarnce is 30% of his basic salary and medical allowance is 5% of basic salary.He gets extra 1000 tk as technical allowance.Write a program to calculate his gross salary and print the result.#include<stdio.h>
    #include<conio.h>
    void main()
    {
    clrscr();
    int b,t,g;
    float h,m;
    printf(“input rahim’s basic salary:\n”);
    scanf(“%d”,&b);
    h=(b*30)/100;
    m=(b*5)/100;
    t=1000;
    g=(b)+(h)+(m)+(t);
    printf(“Rahim’s gross salary is:%d”,g);
    getch();
    }
  • Two anumbers  are input  through the keyboard into two locations A and B. Write a program to interchange the contents of A and B.#include<stdio.h>
    #include<conio.h>
    void main()
    {
    clrscr();
    int a,b,temp;
    printf(“Enter the value of A:”);
    scanf(“%d”,&a);
    printf(“Enter the value of B:”);
    scanf(“%d”,&b);
    temp=a;
    a=b;
    b=temp;printf(“\n\nAfter interchange the value of A is:%d”,a);
    printf(“\n\nAfter interchange the value of B is:%d”,b);
    getch();
    }
  • If a 5 digit number is input  through the keyboard, Write a program to calculate  and print  the sum of its digits.#include<stdio.h>
    #include<conio.h>
    void main()
    {
    clrscr();
    int rem,sum=0;
    int num;
    printf(“A 5 digit number is?\n”);
    scanf(“%d”,&num);
    rem=num%10;
    sum=rem+sum;
    num=num/10;
    rem=num%10;
    sum=rem+sum;
    num=num/10;
    rem=num%10;
    sum=rem+sum;
    num=num/10;
    rem=num%10;
    sum=sum+rem;
    num=num/10;
    sum=sum+num;
    printf(“\nThe sum of the digits of this number is:%d”,sum);
    getch();
    }
  • If  a 5 digit number is input  through the keyboard, Write a program to reverse the number.#include<stdio.h>
    #include<conio.h>
    void main()
    {
    clrscr();
    long int rem,numb=0;
    long int num;
    printf(“Enter the 5 digit number ?\n”);
    scanf(“%ld”,&num);
    rem=num%10;
    numb=numb+(10000*rem);
    num=num/10;
    rem=num%10;
    numb=numb+(1000*rem);
    num=num/10;
    rem=num%10;
    numb=numb+(100*rem);
    num=num/10;
    rem=num%10;
    numb=numb+(10*rem);
    num=num/10;
    numb=numb+num;
    printf(“The reverse number of this number is:%ld”,numb);
    getch();
    }
  • If  a 4 digit number is input  through the keyboard, Write a program to obtain the sum of the first and last digit of this number.
    #include<stdio.h>
    #include<conio.h>
    void main()
    {
    clrscr();
    int rem,sum=0;
    int num;
    printf(“A 4 digit number is?\n”);
    scanf(“%d”,&num);
    rem=num%10;
    sum=rem+sum;
    num=num/10;
    rem=num%10;
    num=num/10;
    rem=num%10;
    num=num/10;
    rem=num%10;
    sum=sum+rem;
    printf(“\nThe sum of the first and last digit of this number is:%d”,sum);
    getch();
    }
Advertisements

2 responses to “Preliminary C programming

  1. for example :#include
    int main()
    {
    int i , j , x = 0 ;
    for(i=0;i<3;i++)
    {
    for(j=0;j<i;j++)
    {
    switch(i+j-1)
    {
    case 1 : x+=3;
    break ;
    case -1 : x+=1;
    break ;
    case 0 : x-=2;
    break ;
    default : x+=1;
    }
    }
    }
    printf("%d",x);
    return 0;
    }

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s