computer programming lab (1)

Upload: kumarrohit352

Post on 04-Jun-2018

228 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/14/2019 Computer Programming Lab (1)

    1/22

    1

    COMPUTER PROGRAMMING LAB

    (B.Tech(Electrical Engineering)1stSEMESTER (CS)

    School of Engineering

    Gautam Buddha University

    (Session-2012-2013)

    Submitted To: Submitted By:

    Mr: KULDEEP KUMAR SANJAY SINGH

    Roll Number :13/IEE/032

  • 8/14/2019 Computer Programming Lab (1)

    2/22

    2

    INDEX

    S.No PRACTICAL NAME DATE

    REMARKS

    1.

    Write a C program to reverse a given number ,

    find the sum of digits of the number.

    2.

    Write a C program to concatenate two strings.

    3.

    Write a C program totake marks of a student

    as input and print his/her grades bases on

    criteria.

    a. Marks

  • 8/14/2019 Computer Programming Lab (1)

    3/22

    3

    EXPERIMENT NUMBER : 1

    Objective :WRITE A C PROGRAM TO FIND REVERSE AND SUM OF DIGITS OFNUMBER?

    #include

    #include

    #include

    void main()

    {

    clrscr();int sum=0,n,rev=0,r;

    printf("enter a number ");

    scanf("%d", &n);

    while(n!=0)

    {

    r=n%10;

    rev=rev*10+r;

    sum=sum+r;n=n/10;

    }

    printf("Reverse is : %d \n",rev );

    printf("Sum of digits is : %d",sum);

    getch();

    }

  • 8/14/2019 Computer Programming Lab (1)

    4/22

    4

    OUTPUT:

  • 8/14/2019 Computer Programming Lab (1)

    5/22

    5

    EXPERIMENT NUMBER:2

    Objective : WRITE A C PROGRAM TO CONCATENATE TWO STRINGS?

    #include

    #include

    #include

    void main()

    {

    clrscr();

    char a[100], b[100];

    printf("Enter the value of first string : ");

    gets(a);

    printf("Enter the value of second string : ");

    gets(b);

    strcat(a,b);

    printf("String after concatenate : %s",a,b);

    getch();}

  • 8/14/2019 Computer Programming Lab (1)

    6/22

    6

    OUTPUT:

  • 8/14/2019 Computer Programming Lab (1)

    7/22

    7

    EXPERIMENT NUMBER:3

    Objective : WRITE A C PROGRAM TO TAKE MARKS OF A STUDENT AS INPUT AND

    PRINT HIS/HER GRDES BASES ON FOLLOWING CRITERIA USING IF ELSE

    STATEMENT.A.MARKS

  • 8/14/2019 Computer Programming Lab (1)

    8/22

  • 8/14/2019 Computer Programming Lab (1)

    9/22

    9

    EXPERIMENT NUMBER : 4

    Objective : WRITE A C PROGRAM TO TAKE MARKS OF A STUDENT AS INPUT AND

    PRINT HIS/HER GRDES BASES ON FOLLOWING CRITERIA USING SWITCH CASE

    STATEMENT.A.MARKS

  • 8/14/2019 Computer Programming Lab (1)

    10/22

    10

    OUTPUT:-

  • 8/14/2019 Computer Programming Lab (1)

    11/22

    11

    EXPERIMENT NUMBER : 5

    Objective :Write a C program to compute the length of a string using while loop.

    #include

    #include

    #include

    void main()

    {

    clrscr();

    charstr[100];

    int i=0;

    printf("Enter the character");

    gets(str);

    while(str[i]!=NULL)

    i++;

    printf("The length of the string is %d", i);

    getch();

    }

  • 8/14/2019 Computer Programming Lab (1)

    12/22

  • 8/14/2019 Computer Programming Lab (1)

    13/22

    13

    EXPERIMENT NUMBER : 6

    Objective :Write a C program to convert all the lowercase character to

    uppercase letter or vice versa.

    #include#include

    #include#include

    void main()

    {clrscr();int i=0,j=0;

    char a[50];

    printf("Enter a string ");

    gets(a);while(a[i]!=NULL)

    {i++;

    }

    for(int j=0;j

  • 8/14/2019 Computer Programming Lab (1)

    14/22

    14

    OUTPUT :

  • 8/14/2019 Computer Programming Lab (1)

    15/22

    15

    EXPERIMENT NUMBER : 7

    Objective :Write a C program to compute the roots of a quadratic equation.

    #include

    #include

    #include

    void main()

    {

    clrscr();

    inta,b,c; float x,y,d;

    printf("Enter the value of a ");

    scanf("%d",&a);

    printf("Enter the value of b ");

    scanf("%d",&b);

    printf("Enter the value of c ");

    scanf("%d",&c);

    d=b*b-4*a*c;

    x=(-b-sqrt(d))/2*a;

    y=(-b+sqrt(d))/2*a;

    printf("First root is %f",x);

    printf("Second root is %f",y);

    getch();

    }

  • 8/14/2019 Computer Programming Lab (1)

    16/22

    16

    OUTPUT :

  • 8/14/2019 Computer Programming Lab (1)

    17/22

    17

    EXPERIMENT NUMBER :8

    Objective :Write a C program to check whether a given number is aprogram or not, also checkwhetherit is divisible by a number or not.

    #include

    #include

    #include

    void main()

    { clrscr();

    inta,i,l=0;

    printf("Enter the number ");

    scanf("%d",&a);

    for(i=1;i

  • 8/14/2019 Computer Programming Lab (1)

    18/22

    18

    OUTPUT :

  • 8/14/2019 Computer Programming Lab (1)

    19/22

    19

    EXPERIMENT NUMBER :9

    Objective :Write a C program to check whether a given year is aleap or not.

    #include

    #include

    #include

    void main()

    {

    clrscr();

    int y;

    printf("Enter the year ");

    scanf("%d",&y);

    if(y%4==0)

    printf("Leap Year");

    else

    printf("Not Leap year");

    getch();

    }

  • 8/14/2019 Computer Programming Lab (1)

    20/22

    20

    OUTPUT :

  • 8/14/2019 Computer Programming Lab (1)

    21/22

    21

    .COMPUTER PROGRAMMING LAB

    (B.Tech(Electrical Engineering)1stSEMESTER (CS)

    School of Engineering

    Gautam Buddha University

    (Session-2012-2013)

    Submitted To: Submitted By:Mr: KULDEEP KUMAR UTKARSH SHARMA

    Roll Number : 13/IEE/044

  • 8/14/2019 Computer Programming Lab (1)

    22/22

    22

    COMPUTER PROGRAMMING LAB

    (B.Tech(Electrical Engineering)1stSEMESTER (CS)

    School of Engineering

    Gautam Buddha University

    (Session-2012-2013)

    Submitted To: Submitted By:

    Mr: KULDEEP KUMAR ZAFAR IQBAL

    Roll Number : 13/IEE/047