final list of c priyanka 2222222222222

Upload: karan-luthra

Post on 06-Apr-2018

218 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/3/2019 Final List of C PRIYANKA 2222222222222

    1/28

    Submitted To:- Submitted By:

    Ms. Priyanka Name:-

    Lect. In Comp. Science Roll No.

    Adm. No.

    Class-B.Com IIIrd Sem(Voc)

    Shah Satnam Ji Girls College,Sirsa

  • 8/3/2019 Final List of C PRIYANKA 2222222222222

    2/28

    INDEX

    Sr.

    No.

    Program Name Signature

    1 Program to print first 10 natural numbers

    2 Program to check whether a given number is

    positive or negative

    3 Program to check whether a number is prime or

    not

    4 Program to print factorial of a number

    5 Program to swap two numbers

    6 Program to find out Armstrong numbers

    between 1 & 500

    7 Program to find out greatest element of array

    8 Program to check whether a year is a leap year

    or not

    9 Program to multiply two matrices

    10 Program to find out the transpose of matrix

    11 Program to implement the concept of pointers

    12 Program to demonstrate writing of strings to a

    file

  • 8/3/2019 Final List of C PRIYANKA 2222222222222

    3/28

    // Program to implement the concept of pointers

    #include

    void main(){

    int i=3,*ptr,**c;

    float j=4,*ptr1;

    char k='w',*ptr2;

    clrscr();

    ptr=&i;

    ptr1=&j;

    ptr2=&k;c=&ptr;

    printf("\n address of i is=%u",ptr);

    printf("\n value of i at address %u is=%d",ptr,*ptr);

    printf("\n address of j is=%u",ptr1);

    printf("\n valuue of j at address %u is=%f",ptr1,*ptr1);

    printf("\n address of k is=%u",ptr2);

    printf("\n value of k at address %u is=%c",ptr2,*ptr2);printf("\n addreess of ptr=%u &value at this address is=%u &

    value is %d",c,*c,**c);

    getch();

    }

  • 8/3/2019 Final List of C PRIYANKA 2222222222222

    4/28

    OUTPUT IS:

    address of i is=65524

    value of i at address 65524 is=3address of j is=65518

    value of j at address 65518is=4.000000

    address of k is =65517

    value of k at address 65517is=w

    address of ptr=65522 & value at this address is=65524 & valus is

    3

  • 8/3/2019 Final List of C PRIYANKA 2222222222222

    5/28

    //Program to find out Armstrong numbers between 1 & 500

    #include

    #includevoid main()

    {

    int i=1,a,b,c,d;

    clrscr();

    printf("armstrong no:");

    while(i

  • 8/3/2019 Final List of C PRIYANKA 2222222222222

    6/28

    OUTPUT IS:

    Armstrong no:

    1153

    370

    371

    407

  • 8/3/2019 Final List of C PRIYANKA 2222222222222

    7/28

    // Program to print factorial of a number

    #include

    #includevoid main()

    {

    int number,i=1,fact=1,n;

    clrscr();

    printf("\nenter the number");

    scanf("%d",&n);

    while(i

  • 8/3/2019 Final List of C PRIYANKA 2222222222222

    8/28

    OUTPUT IS:

    enter the number

    5

    factorial=120

  • 8/3/2019 Final List of C PRIYANKA 2222222222222

    9/28

    // Program to find out greatest element of an array

    #include

    #includevoid main()

    {

    int max,a[10],i,j,k,n;

    clrscr();

    printf("enter the size of array\n");

    scanf("%d",&n);

    printf("enter the elements of array\n");

    for(i=0;i

  • 8/3/2019 Final List of C PRIYANKA 2222222222222

    10/28

    OUTPUT IS:

    enter the size of array

    5enter the elements of array

    1

    4

    6

    7

    8

    greatest no. of array is =8

  • 8/3/2019 Final List of C PRIYANKA 2222222222222

    11/28

    // Program to check whether a year is a leap year or not

    #include

    #includevoid main()

    {

    int year;

    clrscr();

    printf("\n enter the year");

    scanf("%d",&year);

    if(year%400==0||(year%4==0&&year%100!=0))

    printf("it is a leap year");else

    printf("it is not a leap year");

    getch();

    }

  • 8/3/2019 Final List of C PRIYANKA 2222222222222

    12/28

    OUTPUT IS:

    Enter the year2003

    It is not leap year

  • 8/3/2019 Final List of C PRIYANKA 2222222222222

    13/28

    // Program to multiply two matrices

    #include

    #includevoid main()

    {

    int a[6][6],b[6][6],c[6][6],i,j,k,n,m,d,r;

    clrscr();

    printf("enter no of rows & columns of 1st matrix\n");

    scanf("%d%d",&m,&n);

    printf("enter no of rows & columns of 2nd matrix\n");

    scanf("%d%d",&r,&d);if(n!=r)

    printf("\n multiplication is not possible");

    else

    {

    printf("enter the elements of a\n");

    for(i=0;i

  • 8/3/2019 Final List of C PRIYANKA 2222222222222

    14/28

    printf("\n");

    }

    printf("enter elements of b\n");

    for(i=0;i

  • 8/3/2019 Final List of C PRIYANKA 2222222222222

    15/28

    }

    }

    }

    getch();}

  • 8/3/2019 Final List of C PRIYANKA 2222222222222

    16/28

    OUTPUT IS:

    enter no of rows & columns of 1st matrix2 3

    enter no of rows & columns of 2nd matrix

    3 2

    enter the elements of a

    2 3 1

    1 2 3

    1st matrix is

    231123

    enter elements of b

    1 2

    2 3

    1 2

    2nd matrix is

    1223

    12

    The resultant matrix is

    9 15

    8 14

  • 8/3/2019 Final List of C PRIYANKA 2222222222222

    17/28

    // Program to find out the transpose of matrix

    #include

    #includevoid main()

    {

    int a[3][3],b[3][3],i,j;

    clrscr();

    printf("enter values for a 3*3 matrix");

    for(i=1;i

  • 8/3/2019 Final List of C PRIYANKA 2222222222222

    18/28

    OUTPUT IS:

    enter values for a 3*3 matrix1 2 3

    5 7 8

    9 7 6

    The transpose of given matrix is:

    1 5 9

    2 7 7

    3 8 6

  • 8/3/2019 Final List of C PRIYANKA 2222222222222

    19/28

    // Program to swap two numbers

    #include

    #includevoid swap(int x,int y);

    void main()

    {

    int a,b;

    clrscr();

    printf("enter the value of a&b");

    scanf("%d%d",&a,&b);

    swap(a,b);printf("\na=%d b=%d",a,b);

    getch();

    }

    void swap(int x,int y)

    {

    int t;

    t=x;x=y;

    y=t;

    printf("\nx=%d y=%d",x,y);

    }

  • 8/3/2019 Final List of C PRIYANKA 2222222222222

    20/28

    OUTPUT IS:

    enter the value of a&b7

    9

    x=9 y=7

    a=7 b=9

  • 8/3/2019 Final List of C PRIYANKA 2222222222222

    21/28

    // Program to print first 10 natural numbers

    #include

    #includevoid main()

    {

    int i;

    clrscr();

    i=1;

    printf(\nThe first 10 natural numbers are:);

    do

    {printf("\n%d",i++);

    }

    while(i

  • 8/3/2019 Final List of C PRIYANKA 2222222222222

    22/28

    OUTPUT IS:

    The first 10 natural numbers are:

    12

    3

    4

    5

    6

    7

    8

    910

  • 8/3/2019 Final List of C PRIYANKA 2222222222222

    23/28

    // Program to check whether a number is prime or not

    #include

    #includevoid main()

    {

    int i,j,n;

    clrscr();

    printf("enter the no.\n");

    scanf("%d",&n);

    i=2;

    while(i

  • 8/3/2019 Final List of C PRIYANKA 2222222222222

    24/28

    OUTPUT IS:

    enter the no.5

    no. is prime

  • 8/3/2019 Final List of C PRIYANKA 2222222222222

    25/28

    // Program to check whether a given number is positive or

    negative

    #include#include

    void main()

    {

    int number;

    clrscr();

    printf("enter the no.\n");

    scanf("%d",&number);

    if(number

  • 8/3/2019 Final List of C PRIYANKA 2222222222222

    26/28

    OUTPUT IS:

    enter the no.38

    number is positive

  • 8/3/2019 Final List of C PRIYANKA 2222222222222

    27/28

    // Program to demonstrate writing of strings to a file

    #include

    #include

    #includemain()

    {

    FILE *fptr;

    char str[5];

    clrscr();

    if((fptr=fopen("str.txt","w"))==NULL)

    {printf("\n unable to open file\n");

    //exit(1);

    }

    printf("\n enter a set of strings,press enter key to finish\n");

    while(strlen(gets(str))>0)

    {

    fputs(str,fptr);

    fputs("\n",fptr);

    }

    fclose(fptr);

    getch();

    }

  • 8/3/2019 Final List of C PRIYANKA 2222222222222

    28/28

    OUTPUT IS: