sg great c programes

Upload: shabbirghadiali

Post on 09-Apr-2018

225 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/7/2019 SG Great C programes

    1/63

    Govt.

    Engg.Collegemodasa Shamlaji Road,Modasa-383315.

    C Programing

    Name :- Gevariya Sachin S.

    Roll No :- 616

    Branch:-Computer Engineering

    (1)

    Implement Opration +,-,*,/#include

    #include

    void main()

    {

    float a,b,ad,m,s,d;clrscr();

    printf("Enter The Number 1 :- ");

    scanf("%f",& a);

    printf("\n Enter The Number 2 :- ");

    scanf("%f",& b);

  • 8/7/2019 SG Great C programes

    2/63

    Name :- Gevariya Sachin S.

    C Programming

    ad=a+b;

    s=a-b;

    m=a*b;

    d=a/b;

    printf("\n a+b = %.2f", ad);

    printf("\n a-b = %.2f", s);

    printf("\n a*b = %.2f", m);

    printf("\n a/b = %.2f", d);

    getch();

    }

    :- Out Put -:Enter The Number 1 :- 10

    Enter The Number 2 :- 20

    a+b = 30.00

    a-b = -10.00

    a*b = 200.00a/b = 0.50

    (2)

    Calculate Intrest#include

    #include

    void main()

    { float p,r,n,i;

    clrscr();

    printf(" Enter The Value of P :- ");

    scanf("%f",& p);

    printf("\n Enter The Value of R :- ");

    scanf("%f",& r);

    Goverment. Engineering College, Modasa

    2

  • 8/7/2019 SG Great C programes

    3/63

    Name :- Gevariya Sachin S.

    C Programming

    printf("\n Enter The Value of N :- ");

    scanf("%f",& n);

    i=(p*r*n)/100;

    printf("\n\n Intrest :- %.2f",i);

    getch();

    }

    :- Out Put -:

    Enter The Value of P :- 10

    Enter The Value of R :- 20

    Enter The Value of N :- 5

    Intrest :- 10.00(3)

    Convert Temperature#include

    #include

    void main()

    {

    float a,c,f;clrscr();

    printf("Enter The Temperature (c/f) :- ");

    scanf("%f",& a);

    c = (0.56)*(a-32);

    f = ((1.8)*a)+32;

    Goverment. Engineering College, Modasa

    3

  • 8/7/2019 SG Great C programes

    4/63

    Name :- Gevariya Sachin S.

    C Programming

    printf("\n\n if The Temperature is C Then convert

    C->F is :- %.2f",f);

    printf("\n\n if The Temperature is F Then convert

    F->C is :- %.2f",c);

    getch();

    }

    :- Out Put -:

    Enter The Temperature (c/f) :- 1

    if The Temperature is C Then convert C->F is :- 33.80

    if The Temperature is F Then convert F->C is :- -17.36

    (4)

    Find Area and Volume#include

    #include

    void main()

    { int l,b,h;

    int a,v;

    clrscr();

    printf(" Enter The Value of l :- ");

    scanf("%d",& l);

    printf("\n Enter The Value of b :- ");scanf("%d",& b);

    Goverment. Engineering College, Modasa

    4

  • 8/7/2019 SG Great C programes

    5/63

    Name :- Gevariya Sachin S.

    C Programming

    printf("\n Enter The Value of h :- ");

    scanf("%d",& h);

    a=l*b;

    v=l*b*h;

    printf("\n\n The Area :- %d",a);

    printf("\n\n The Volume :- %d",v);

    getch();

    }

    :- Out Put -:

    Enter The Value of l :- 10

    Enter The Value of b :- 20

    Enter The Value of h :- 30

    The Area :- 200

    The Volume :- 6000

    (5)

    Find Root#include

    #include

    #include

    void main(){

    float a,b,c,r1,r2,m,n,p,o;

    clrscr();

    printf("Enter The Value of a :- ");

    scanf("%f",& a);

    printf("\n Enter The Value of b :- ");scanf("%f",& b);

    Goverment. Engineering College, Modasa

    5

  • 8/7/2019 SG Great C programes

    6/63

  • 8/7/2019 SG Great C programes

    7/63

    Name :- Gevariya Sachin S.

    C Programming

    #include

    void main()

    {

    int a,b,c,d,e;

    clrscr();

    printf("Enter The Value of a :- ");

    scanf("%d",& a);

    printf("\n Enter The Value of b :- ");

    scanf("%d",& b);

    printf("\n Enter The Value of c :- ");scanf("%d",& c);

    printf("\n Enter The Value of d :- ");

    scanf("%d",& d);

    printf("\n Enter The Value of e :- ");

    scanf("%d",& e);

    if(a>b && a>c && a>d && a>e)

    {

    printf("\n\n Max Number is a:- %d",a);

    }

    else if(b>a && b>c && b>d && b>e)

    {

    printf("\n\n Max Number is b:- %d",b);

    }else if(c>a && c>b && c>d && c>e)

    {

    printf("\n\n Max Number is c:- %d",c);

    }

    else if(d>a && d>b && d>c && d>e)

    {

    printf("\n\n Max Number is d:- %d",d);

    }

    Goverment. Engineering College, Modasa

    7

  • 8/7/2019 SG Great C programes

    8/63

    Name :- Gevariya Sachin S.

    C Programming

    else if(e>a && e>b && e>c && e>d)

    {

    printf("\n\n Max Number is e:- %d",e);

    }

    getch();

    }

    :- Out Put -:

    Enter The Value of a :- 10

    Enter The Value of b :- 20

    Enter The Value of c :- 50

    Enter The Value of d :- 30

    Enter The Value of e :- 40

    Max Number is c:- 50

    (7)

    Find Factorial#include

    #include

    void main()

    { int a,i,sum=1;

    clrscr();

    printf("Enter The Value of A :- ");

    scanf("%d",& a);

    for(i=1;i

  • 8/7/2019 SG Great C programes

    9/63

    Name :- Gevariya Sachin S.

    C Programming

    }

    printf("\n\n The Factorial Value of %d :- %d",a,sum);

    getch();

    }

    :- Out Put -:

    Enter The Value of A :- 5

    The Factorial Value of 5 :- 120

    (8)

    Find Number if Odd or Even and also Find

    Prime or Not#include

    #include

    void main(){

    int a,i,x=0;

    clrscr();

    printf("Enter The Value of A :- ");

    scanf("%d",& a);

    if(a%2==0)

    Goverment. Engineering College, Modasa

    9

  • 8/7/2019 SG Great C programes

    10/63

    Name :- Gevariya Sachin S.

    C Programming

    {

    printf("\n\n %d is The Even Number",a);

    }

    else

    {

    printf("\n\n %d is The Odd Number",a);

    }

    for(i=1;i

  • 8/7/2019 SG Great C programes

    11/63

    Name :- Gevariya Sachin S.

    C Programming

    Genrate Multiplication Table#include

    #include

    void main(){

    int i,j,mt;

    clrscr();

    for(i=1;i

  • 8/7/2019 SG Great C programes

    12/63

    Name :- Gevariya Sachin S.

    C Programming

    7*5=35 8*5=40 9*5=45 10*5=50

    7*6=42 8*6=48 9*6=54 10*6=60

    7*7=49 8*7=56 9*7=63 10*7=70

    7*8=56 8*8=64 9*8=72 10*8=80

    7*9=63 8*9=72 9*9=81 10*9=90

    7*10=70 8*10=80 9*10=90 10*10=100

    (10.1)

    Pattern#include

    #includevoid main()

    {

    int i,j;

    clrscr();

    for(i=1;i

  • 8/7/2019 SG Great C programes

    13/63

    Name :- Gevariya Sachin S.

    C Programming

    Pattern#include

    #include

    void main(){

    int i,j,k;

    clrscr();

    for(i=1;i

  • 8/7/2019 SG Great C programes

    14/63

    Name :- Gevariya Sachin S.

    C Programming

    void main()

    {

    int i,j;

    clrscr();

    for(i=1;i=i;j--)

    {

    printf("*");

    }

    printf("\n");

    }

    getch();

    }

    :- Out Put -:*****

    ****

    ***

    **

    *

    (10.4)Pattern

    # include

    # include

    void main()

    {

    int i,j,no;

    clrscr();

    Goverment. Engineering College, Modasa

    14

  • 8/7/2019 SG Great C programes

    15/63

    Name :- Gevariya Sachin S.

    C Programming

    printf("Enter the number :- ");

    scanf("%d",&no);

    printf("\n\n");

    for(i=1;i

  • 8/7/2019 SG Great C programes

    16/63

    Name :- Gevariya Sachin S.

    C Programming

    clrscr();

    printf("Enter the number :- ");

    scanf("%d",&n);

    printf("\n\n");

    for(i=1;i

  • 8/7/2019 SG Great C programes

    17/63

    Name :- Gevariya Sachin S.

    C Programming

    clrscr();

    for(i=1;i

  • 8/7/2019 SG Great C programes

    18/63

    Name :- Gevariya Sachin S.

    C Programming

    printf("\n");

    }

    getch();

    }

    :- Out Put -:

    * * * * *

    * * * *

    * * *

    * **

    (10.8)

    Pattern#include#include

    void main()

    {

    int i,j;

    clrscr();

    for(i=1;i

  • 8/7/2019 SG Great C programes

    19/63

    Name :- Gevariya Sachin S.

    C Programming

    getch();

    }

    :- Out Put -:*

    *#

    *##

    *###

    *####

    (11)

    Pattern

    #include#include

    void main()

    {

    char str[9]={'p','d','p','a','n','d','y','a'};

    int i,j;

    clrscr();

    for(i=0;i

  • 8/7/2019 SG Great C programes

    20/63

    Name :- Gevariya Sachin S.

    C Programming

    :- Out Put -:

    p

    pdpdp

    pdpa

    pdpan

    pdpand

    pdpandy

    pdpandya

    (12)

    Find length of String With Out Strlen

    Function#include

    #include

    void main()

    {

    char str[50];

    int i,count=0;

    clrscr();

    printf(" Enter The String :- ");

    gets(str);

    for(i=0;str[i]!=NULL;i++)

    {

    if(str[i]!=' ')

    {

    count++;

    Goverment. Engineering College, Modasa

    20

  • 8/7/2019 SG Great C programes

    21/63

    Name :- Gevariya Sachin S.

    C Programming

    }

    }

    printf("\n\n The Length of \"%s\" :- %d",str,count);

    getch();

    }

    :- Out Put -:

    Enter The String :- Patel ajay

    The Length of "Patel ajay" :- 9

    (13)

    Enter The String and Display The Revers

    String

    #include

    #include

    #include

    void main()

    {

    char str[50],temp;

    int i,j;clrscr();

    printf("\n Enter The String :- ");

    gets(str);

    for(i=0;i

  • 8/7/2019 SG Great C programes

    22/63

    Name :- Gevariya Sachin S.

    C Programming

    {

    temp=str[i];

    str[i]=str[j];

    str[j]=temp;

    }

    }

    printf("\n Revers The String is :- ");

    puts(str);

    getch();

    }

    :- Out Put -:Enter The String :- patel ajay

    Revers The String is :- yaja letap

    (14)

    Pallindrom or Not Pallindrom#include

    #include

    #include

    void main()

    {

    char str1[20],str2[20];

    clrscr();printf("Enter one string : ");

    scanf("%s",str1);

    strcpy(str2,str1);

    strrev(str2);

    if(strcmp(str1,str2)==0)

    {

    printf("\n\n This String is PALLINDROM");

    }else

    Goverment. Engineering College, Modasa

    22

  • 8/7/2019 SG Great C programes

    23/63

    Name :- Gevariya Sachin S.

    C Programming

    {

    printf("\n\n This String is NOT PALLINDROM");

    }

    getch();

    }

    :- Out Put -:

    Enter one string : ajay

    This String is NOT PALLINDROM

    (15)

    Find Vowel, Digit or Character

    #include

    #include

    #include

    void main()

    {

    char ch[100];

    int c=0,i,d=0,count=0;

    clrscr();printf("\n Enter string :- ");

    gets(ch);

    for(i=0;ch[i]!='\0';i++)

    {

    /* Find Total vowels */

    if(ch[i]=='a'||ch[i]=='A')

    {

    c=c+1;}

    Goverment. Engineering College, Modasa

    23

  • 8/7/2019 SG Great C programes

    24/63

    Name :- Gevariya Sachin S.

    C Programming

    if(ch[i]=='e'||ch[i]=='E')

    {

    c=c+1;

    }

    if(ch[i]=='i'||ch[i]=='I')

    {

    c=c+1;

    }

    if(ch[i]=='o'||ch[i]=='O')

    {

    c=c+1;

    }

    if(ch[i]=='u'||ch[i]=='U'){

    c=c+1;

    }

    /* Find Total Digits */

    if(ch[i]=='0')

    {

    d++;

    }if(ch[i]=='1')

    {

    d++;

    }

    if(ch[i]=='2')

    {

    d++;

    }if(ch[i]=='3')

    {

    d++;

    }

    if(ch[i]=='4')

    {

    d++;

    }

    Goverment. Engineering College, Modasa

    24

  • 8/7/2019 SG Great C programes

    25/63

    Name :- Gevariya Sachin S.

    C Programming

    if(ch[i]=='5')

    {

    d++;

    }

    if(ch[i]=='6')

    {

    d++;

    }

    if(ch[i]=='7')

    {

    d++;

    }

    if(ch[i]=='8'){

    d++;

    }

    if(ch[i]=='9')

    {

    d++;

    }

    /* Find Total Character in String */

    if(ch[i]!=' ')

    {

    count++;

    }

    }

    printf("\n\n Total Vowels Character is: %d",c);printf("\n\n Total Digits Character is: %d",d);

    printf("\n\n Total Character in String is: %d",count);

    getch();

    }

    :- Out Put -:

    Goverment. Engineering College, Modasa

    25

  • 8/7/2019 SG Great C programes

    26/63

    Name :- Gevariya Sachin S.

    C Programming

    Enter string :- patel ajay 56

    Total Vowels Character is: 4

    Total Digits Character is: 2

    Total Character in String is: 11

    (16)

    Find character in String#include

    #include

    #includevoid main()

    {

    char str[100],ch;

    int i,count=0;

    clrscr();

    printf("Enter The String :- ");

    gets(str);

    printf("\nEnter The Character Find in String :- ");

    scanf("%c",& ch);

    for(i=0;str[i]!=NULL;i++)

    {

    if(str[i]==ch)

    {

    count++;

    Goverment. Engineering College, Modasa

    26

  • 8/7/2019 SG Great C programes

    27/63

    Name :- Gevariya Sachin S.

    C Programming

    }

    }

    if(count>0)

    {

    printf("\n\n\"%c\" is The Given in The

    String",ch);

    }

    else

    {

    printf("\n\n\"%c\" is The Not Given in

    The String",ch);}

    printf("\n\n\"%c\" is %d Time in Use of

    String",ch,count);

    getch();

    }

    :- Out Put -:

    Enter The String :- patel ajayEnter The Character Find in String :- a

    "a" is The Given in The String

    "a" is 3 Time in Use of String

    (17)

    Sum of 1-D Array#include

    #include

    Goverment. Engineering College, Modasa

    27

  • 8/7/2019 SG Great C programes

    28/63

    Name :- Gevariya Sachin S.

    C Programming

    void main()

    {

    int a[10],sum=0,i,no;

    clrscr();

    printf("\n\n How Many Number You Want in

    Array :- ");

    scanf("%d",&no);

    for(i=0;i

  • 8/7/2019 SG Great C programes

    29/63

    Name :- Gevariya Sachin S.

    C Programming

    (18)

    Add to 2-D Array#include

    #include

    void main()

    {

    int a[2][2],b[2][2],c[2][2],i,j;

    clrscr();

    for(i=0;i

  • 8/7/2019 SG Great C programes

    30/63

    Name :- Gevariya Sachin S.

    C Programming

    for(j=0;j

  • 8/7/2019 SG Great C programes

    31/63

    Name :- Gevariya Sachin S.

    C Programming

    :- Out Put -:

    Enter Value of [0][0] :- 10

    Enter Value of [0][1] :- 20Enter Value of [1][0] :- 30

    Enter Value of [1][1] :- 40

    10 20

    30 40

    Enter Value of [0][0] :- 40

    Enter Value of [0][1] :- 30Enter Value of [1][0] :- 20

    Enter Value of [1][1] :- 10

    40 30

    20 10

    The Sum of Array

    50 50

    50 50

    (19)

    Multiplication of 2-D Array

    #include#include

    void main()

    {

    int i,j,k;

    int a[2][2],b[2][2],ad[2][2];

    clrscr();

    printf("\n\n\n Matrix A \n\n\n");

    Goverment. Engineering College, Modasa

    31

  • 8/7/2019 SG Great C programes

    32/63

    Name :- Gevariya Sachin S.

    C Programming

    for(i=0;i

  • 8/7/2019 SG Great C programes

    33/63

    Name :- Gevariya Sachin S.

    C Programming

    getch();

    }

    :- Out Put -:

    Matrix A

    Enter Element for a[0][0] :- 10

    Enter Element for a[0][1] :- 20

    Enter Element for a[1][0] :- 30

    Enter Element for a[1][1] :- 40

    Matrix B

    Enter Element for b[0][0] :- 40

    Enter Element for b[0][1] :- 30

    Enter Element for b[1][0] :- 20

    Enter Element for b[1][1] :- 10

    Multiplication of Matrix :-

    800 500

    2000 1300

    (20)

    Fibonnanci Series

    #include

    #include

    void main()

    {int no,i,a,b=1,sum=0;

    Goverment. Engineering College, Modasa

    33

  • 8/7/2019 SG Great C programes

    34/63

    Name :- Gevariya Sachin S.

    C Programming

    clrscr();

    printf("Enter The Number :- ");

    scanf("%d",& no);

    printf("\n\n\n Fibonnanci Series :- \n\n\n\n");

    for(i=0;sum

  • 8/7/2019 SG Great C programes

    35/63

    Name :- Gevariya Sachin S.

    C Programming

    scanf("%d", & b);

    printf("\n\n\n choice");

    printf("\n\n 1 :- add");

    printf("\n\n 2 :- sub");

    printf("\n\n 3 :- div");

    printf("\n\n 4 :- multi");

    printf("\n\n 5 :- modu");

    printf("\n\n\n enter the choice :- ");

    scanf("%d",& c);

    switch (c){

    case 1:

    d=a+b;

    printf("\n\n\n the sum is:- %d",d);

    break;

    case 2:

    e=a-b;

    printf("\n\n\n the sub is:- %d",e);break;

    case 3:

    f=a/b;

    printf("\n\n\n the div is:- %d", f);

    break;

    case 4:

    g=a*b;

    printf("\n\n\n the multi is:- %d", g);break;

    case 5:

    h=a%b;

    printf("\n\n\n the modulo is:- %d", h);

    break;

    }

    getch();

    }

    Goverment. Engineering College, Modasa

    35

  • 8/7/2019 SG Great C programes

    36/63

    Name :- Gevariya Sachin S.

    C Programming

    :- Out Put -:

    enter the value of a:- 10enter the value of b:- 20

    choice

    1 :- add

    2 :- sub

    3 :- div

    4 :- multi5 :- modu

    enter the choice :- 4

    the multi is:- 200

    (22)

    Enter Unit and Display The Bill

    #include

    #include

    void main()

    {

    int un,bill;

    clrscr();

    printf("\n\n Enter The Unit :- ");

    scanf("%d",& un);

    if(un>0 && un100 && un

  • 8/7/2019 SG Great C programes

    37/63

    Name :- Gevariya Sachin S.

    C Programming

    printf("\n\n\n\n The Bill is :- %d

    Rs.",bill);

    }

    else if(un>200 && un300)

    {

    bill=(un*6)+100;

    printf("\n\n\n\n The Bill is :- %dRs.",bill);

    }

    getch();

    }

    :- Out Put -:

    Enter The Unit :- 350

    The Bill is :- 2200 Rs.

    (23)

    Short Array

    #include

    #include

    void main()

    {

    int a[5],i,j,temp;

    clrscr();

    for(i=0;i

  • 8/7/2019 SG Great C programes

    38/63

    Name :- Gevariya Sachin S.

    C Programming

    printf("\n Enter Value of [%d] :- " ,i);

    scanf("%d",& a[i]);

    }

    for(i=0;i

  • 8/7/2019 SG Great C programes

    39/63

    Name :- Gevariya Sachin S.

    C Programming

    Enter Value of [4] :- 50

    10

    20

    30

    40

    50

    50

    40

    30

    20

    10

    (24)

    Position of Element in Array

    #include

    #includevoid main()

    {

    int a[5],i,j,no;

    clrscr();

    for(i=0;i

  • 8/7/2019 SG Great C programes

    40/63

    Name :- Gevariya Sachin S.

    C Programming

    if(a[i]==no)

    {

    printf("\n\n\n The Position of

    Element \"%d\" is :- a[%d]",no,i);

    }

    }

    getch();

    }

    :- Out Put -:

    Enter Value of a[0] :- 10

    Enter Value of a[1] :- 20

    Enter Value of a[2] :- 30

    Enter Value of a[3] :- 40Enter Value of a[4] :- 50

    Enter The Element :- 30

    The Position of Element "30" is :- a[2]

    (25)Maths Function#include

    #include

    void add(int,int);

    void sub(int,int);

    void mul(int,int);

    void div(int,int);

    void main()

    Goverment. Engineering College, Modasa

    40

  • 8/7/2019 SG Great C programes

    41/63

    Name :- Gevariya Sachin S.

    C Programming

    {

    int no1,no2;

    clrscr();

    printf("Enter The No 1 :- ");

    scanf("%d",& no1);

    printf("\n\n Enter The No 2 :- ");

    scanf("%d",& no2);

    add(no1,no2);

    sub(no1,no2);

    mul(no1,no2);

    div(no1,no2);getch();

    }

    void add(int no1, int no2)

    {

    int add;

    add=no1+no2;

    printf("\n\n\n\n The Sum is :- %d",add);

    }void sub(int no1, int no2)

    {

    int sub;

    sub=no1-no2;

    printf("\n\n The Subtrection is :- %d",sub);

    }

    void mul(int no1, int no2)

    {int mul;

    mul=no1*no2;

    printf("\n\n The Multipication is :- %d",mul);

    }

    void div(int no1, int no2)

    {

    float div;

    div=no1/no2;

    Goverment. Engineering College, Modasa

    41

  • 8/7/2019 SG Great C programes

    42/63

    Name :- Gevariya Sachin S.

    C Programming

    printf("\n\n The Div is :- %.2f",div);

    }

    :- Out Put -:

    Enter The No 1 :- 20

    Enter The No 2 :- 10

    The Sum is :- 30

    The Subtrection is :- 10

    The Multipication is :- 200

    The Div is :- 2.00

    (26)

    Swap The Value Using Poiinter

    #include

    #includevoid main()

    {

    int no1,no2,temp,*p1,*p2;

    clrscr();

    printf("Enter the No 1 :- ");

    scanf("%d",&no1);

    printf("\n\n Enter the No 2 :- ");scanf("%d",&no2);

    p1=&no1;

    p2=&no2;

    temp=*p1;

    *p1=*p2;

    *p2=temp;

    Goverment. Engineering College, Modasa

    42

  • 8/7/2019 SG Great C programes

    43/63

    Name :- Gevariya Sachin S.

    C Programming

    printf("\n\n\n AFTER SWAPING");

    printf("\n\n The value of No 1 is :%d",no1);

    printf("\n\n The value of No 2 is :%d",no2);

    getch();

    }

    :- Out Put -:

    Enter the No 1 :- 10

    Enter the No 2 :- 20

    AFTER SWAPING

    The value of No 1 is :20

    The value of No 2 is :10

    (27)

    Read and Write File

    #include

    #includevoid main()

    {

    FILE *p1,*p2;

    char ch,cha;

    clrscr();

    p1=fopen("D:\\1.txt","r");

    p2=fopen("D:\\2.txt","w");

    printf("\n\n Read File \n\n");

    while((ch=getc(p1))!=EOF)

    {

    printf("%c",ch);

    }

    Goverment. Engineering College, Modasa

    43

  • 8/7/2019 SG Great C programes

    44/63

    Name :- Gevariya Sachin S.

    C Programming

    printf("\n\n Wirte File \n\n");

    while((cha=getc(p1))!=EOF)

    {

    putc(cha,p2);

    }

    fclose(p1);

    fclose(p2);

    getch();

    }

    :- Out Put -:

    Read File

    my name is ajay

    Wirte File

    File is Write

    (28)

    Copy File Form One File To Another

    #include#include

    void main()

    {

    FILE *p1,*p2;

    char ch;

    clrscr();

    p1=fopen("1.txt","r");p2=fopen("2.txt","w");

    Goverment. Engineering College, Modasa

    44

  • 8/7/2019 SG Great C programes

    45/63

    Name :- Gevariya Sachin S.

    C Programming

    while((ch=getc(p1))!=EOF)

    {

    putc(ch,p2);

    }

    printf("Success");

    fclose(p1);

    fclose(p2);

    getch();

    }

    :- Out Put -:Success

    (29)

    Illustrate Use of Pointer

    #include

    #includevoid main()

    {

    int x,*p;

    clrscr();

    printf("Enter the number :- ");

    scanf("%d",&x);

    p=&x;

    printf("\n\n Value of x is :- %d",x);

    printf("\n\n Value of x is :- %d",*p);

    printf("\n\n Value of x is :-

    %d",*(&x));

    printf("\n\n Value of x is :- %d",*(p));

    printf("\n\n Address of x is :- %u",&x);printf("\n\n Address of x is :- %u",p);

    Goverment. Engineering College, Modasa

    45

  • 8/7/2019 SG Great C programes

    46/63

    Name :- Gevariya Sachin S.

    C Programming

    printf("\n\n Address of x is :-

    %u",&(*p));

    getch();

    }

    :- Out Put -:

    Enter the number :- 10

    Value of x is :- 10

    Value of x is :- 10

    Value of x is :- 10Value of x is :- 10

    Address of x is :- 65524

    Address of x is :- 65524

    Address of x is :- 65524

    (30)

    Find Gretest Value With Out Use if

    Condition

    #include

    #include

    void main()

    {

    int a,b,c,d,ans;clrscr();

    printf("\n Enter The Value of a:- ");

    scanf("%d",& a);

    printf("\n Enter The Value of b:- ");

    scanf("%d", & b);

    Goverment. Engineering College, Modasa

    46

  • 8/7/2019 SG Great C programes

    47/63

    Name :- Gevariya Sachin S.

    C Programming

    printf("\n Enter The Value of c:- ");

    scanf("%d", & c);

    printf("\n Enter The Value of d:- ");

    scanf("%d", & d);

    ans=((a>b)&&(a>c)&&(a>d))?a:((b>a)

    &&(b>c)&&(b>d))?b:((c>a)&&(c>b)

    &&(c>d))?c:d;

    printf("\n\t %d is The Gretest

    Value",ans);

    getch();

    }

    :- Out Put -:

    Enter The Value of a:- 10

    Enter The Value of b:- 40

    Enter The Value of c:- 20Enter The Value of d:- 30

    40 is The Gretest Value

    (31)

    Find Largest, Minimum, Avg, Total Using

    Array

    #include

    #include

    void main()

    {

    int a[5],i,max,min,total=0,avg;

    clrscr();

    Goverment. Engineering College, Modasa

    47

  • 8/7/2019 SG Great C programes

    48/63

    Name :- Gevariya Sachin S.

    C Programming

    for(i=1;i

  • 8/7/2019 SG Great C programes

    49/63

    Name :- Gevariya Sachin S.

    C Programming

    avg=total/5;

    printf("\n\n Avg Is :- %d",avg);

    getch();

    }

    :- Out Put -:

    Enter the [1] value :10

    Enter the [2] value :20

    Enter the [3] value :50Enter the [4] value :30

    Enter the [5] value :40

    The Largest Value in The Entered Array is :50

    The Smallest Value in The Entered Array is :10

    Total is :- 150

    Avg Is :- 30

    (32)

    Find The Convert String From Upper To

    Lower Case

    #include

    #include

    #include

    void main()

    {

    char *str1,*str2;

    int i;

    clrscr();

    Goverment. Engineering College, Modasa

    49

  • 8/7/2019 SG Great C programes

    50/63

    Name :- Gevariya Sachin S.

    C Programming

    printf(" Enter The String :- ");

    gets(str1);

    for(i=0;str1[i]!=NULL;i++)

    {

    if(isupper(str1[i]))

    {

    str2[i]=str1[i]+32;

    }

    }

    str2[i]='\0';

    printf("\n\n Convert The String FromeUpper to Lower :- %s",str2);

    getch();

    }

    :- Out Put -:

    Enter The String :- AJAY

    Convert The String Frome Upper to Lower :- ajay

    (33)

    Structure Using array

    #include

    #includestruct

    {

    int rno;

    char name[100],address[100];

    }s1[10];

    void main()

    {

    Goverment. Engineering College, Modasa

    50

  • 8/7/2019 SG Great C programes

    51/63

    Name :- Gevariya Sachin S.

    C Programming

    int i;

    clrscr();

    for(i=0;i

  • 8/7/2019 SG Great C programes

    52/63

    Name :- Gevariya Sachin S.

    C Programming

    Enter Student`s Name :- ajay

    Enter Student's Roll No :- 56

    Enter The Address :- bapunagar

    Enter Student`s Name :- mahival

    Enter Student's Roll No :-70

    Enter The Address :-maninagar

    Enter Student`s Name :- abhi

    Enter Student's Roll No :- 62

    Enter The Address :- nagarvel

    Enter Student`s Name :- sagarEnter Student's Roll No :- 1

    Enter The Address :- park

    Enter Student`s Name :- chirag

    Enter Student's Roll No :- 16

    Enter The Address :- bapunagar

    Enter Student`s Name :- chiragEnter Student's Roll No :- 51

    Enter The Address :- ranip

    Enter Student`s Name :- chirag

    Enter Student's Roll No :- 60

    Enter The Address :- vatva

    Enter Student`s Name :- nikunjEnter Student's Roll No :- 85

    Enter The Address :- bapunagar

    Enter Student`s Name :- amit

    Enter Student's Roll No :- 58

    Enter The Address :- saraspur

    Enter Student`s Name :- divyesh

    Goverment. Engineering College, Modasa

    52

  • 8/7/2019 SG Great C programes

    53/63

    Name :- Gevariya Sachin S.

    C Programming

    Enter Student's Roll No :- 32

    Enter The Address :- hiravady

    Student Name :- ajay

    Student Roll No :- 56

    Student Address :- bapunagar

    Student Name :- mahival

    Student Roll No :-70

    Student Address :-maninagar

    Student Name :- abhi

    Student Roll No :- 62

    Student Address :- nagarvel

    Student Name :- sagar

    Student Roll No :- 1

    Student Address :- park

    Student Name :- chirag

    Student Roll No :- 16

    Student Address :- bapunagar

    Student Name :- chirag

    Student Roll No :- 51

    Student Address :- ranip

    Student Name :- chirag

    Student Roll No :- 60

    Student Address :- vatva

    Student Name :- nikunj

    Student Roll No :- 85

    Student Address :- bapunagar

    Goverment. Engineering College, Modasa

    53

  • 8/7/2019 SG Great C programes

    54/63

    Name :- Gevariya Sachin S.

    C Programming

    Student Name :- amit

    Student Roll No :- 58

    Student Address :- saraspur

    Student Name :- divyesh

    Student Roll No :- 32

    Student Address :- hiravady

    (34)

    create Table Using Structure

    #include#include

    struct

    {

    int rno,m1,m2,m3,total;

    char name[50];

    float per;}s1[5];

    void main()

    {

    int i;

    clrscr();

    for(i=0;i

  • 8/7/2019 SG Great C programes

    55/63

    Name :- Gevariya Sachin S.

    C Programming

    printf("\n Enter student's name :- ");

    scanf("%s",s1[i].name);

    printf("\n Enter mark of subject1 :- ");

    scanf("%d",&s1[i].m1);

    printf("\n Enter mark of subject2 :- ");

    scanf("%d",&s1[i].m2);

    printf("\n Enter mark of subject3 :- ");

    scanf("%d",&s1[i].m3);

    s1[i].total=s1[i].m1+s1[i].m2+s1[i].m3;

    s1[i].per=s1[i].total/3;

    printf("\n\n\n");

    }

    printf("\n\n\n Roll no \t Name \t m1 \t m2 \t m3 \t

    Total \t Per \n\n");

    for(i=0;i

  • 8/7/2019 SG Great C programes

    56/63

    Name :- Gevariya Sachin S.

    C Programming

    Enter student's name :- ajay

    Enter mark of subject1 :- 50

    Enter mark of subject2 :- 45

    Enter mark of subject3 :- 40

    Enter student's roll no :- 62

    Enter student's name :- abhi

    Enter mark of subject1 :- 45

    Enter mark of subject2 :- 40

    Enter mark of subject3 :- 50

    Enter student's roll no :- 70

    Enter student's name :- mahiEnter mark of subject1 :- 45

    Enter mark of subject2 :- 50

    Enter mark of subject3 :- 40

    Enter student's roll no :- 1

    Enter student's name :- sagar

    Enter mark of subject1 :- 40

    Enter mark of subject2 :- 45

    Enter mark of subject3 :- 50

    Enter student's roll no :- 32

    Enter student's name :- diey

    Enter mark of subject1 :- 50

    Enter mark of subject2 :- 45

    Enter mark of subject3 :- 40

    Roll no Name m1 m2 m3 Total Per

    56 ajay 50 45 40 135 45.00

    62 abhi 45 40 50 135 45.00

    70 mahi 45 50 40 135 45.00

    Goverment. Engineering College, Modasa

    56

  • 8/7/2019 SG Great C programes

    57/63

    Name :- Gevariya Sachin S.

    C Programming

    1 sagar 40 45 50 135 45.00

    32 diey 50 45 40 135 45.00

    (35)

    Use Structure & Array Defind Account

    Credit or Debit

    #include

    #include

    struct account

    {

    int no,bal;

    char name[100],type[100];

    }a1[10];

    int credit(int,int);

    int debit(int,int);

    void main()

    {

    int i,no,amount,amount1,temp,temp1,cho;

    char ans,ans1;

    clrscr();

    Goverment. Engineering College, Modasa

    57

  • 8/7/2019 SG Great C programes

    58/63

    Name :- Gevariya Sachin S.

    C Programming

    for(i=0;i

  • 8/7/2019 SG Great C programes

    59/63

    Name :- Gevariya Sachin S.

    C Programming

    printf("\n\n Choice \n\n ");

    printf("1) Debit ");

    printf("\n\n 2) Credit ");

    printf("\n\n Enter The Choice :- ");

    scanf("%d",& cho);

    switch (cho)

    {

    case 1:

    ans1='y';

    if(ans1=='y' || ans1=='Y')

    {

    printf("\n\n Enter The

    Debit Rs. :- ");

    scanf("%d",&

    amount1);temp1=debit(a1[i].bal,

    amount1);

    printf("\n\n The

    Balance is :-

    %d",temp1);

    break;

    }case 2:

    ans='y';

    if(ans=='y' || ans=='Y')

    {

    printf("\n\n Enter The

    Credit Rs. :- ");

    scanf("%d",&

    Goverment. Engineering College, Modasa

    59

  • 8/7/2019 SG Great C programes

    60/63

    Name :- Gevariya Sachin S.

    C Programming

    amount);

    temp=credit(a1[i].bal,

    amount);

    printf("\n\n The

    Balance is :-

    %d",temp);

    break;

    }

    }

    }

    }

    getch();}

    int credit(int ba,int amo)

    {

    int tem;

    tem=ba-amo;

    return (tem);}

    int debit(int ba1,int amo1)

    {

    int tem1;

    tem1=ba1+amo1;

    return (tem1);

    }

    :- Out Put -:

    Enter The Account No :- 1

    Enter The Account Holder :- jinal

    Enter The Account Type :- savingEnter The Account Balance :- 5000

    Goverment. Engineering College, Modasa

    60

  • 8/7/2019 SG Great C programes

    61/63

    Name :- Gevariya Sachin S.

    C Programming

    Enter The Account No :-2

    Enter The Account Holder :- manish

    Enter The Account Type :-current

    Enter The Account Balance :- 5500

    Enter The Account No :-3

    Enter The Account Holder :-mehul

    Enter The Account Type :- current

    Enter The Account Balance :-1000

    Enter The Account No :-4

    Enter The Account Holder :- sagarEnter The Account Type :-saving

    Enter The Account Balance :-1500

    Enter The Account No :-5

    Enter The Account Holder :-abhi

    Enter The Account Type :- current

    Enter The Account Balance :-5500

    Enter The Account No :-6

    Enter The Account Holder :-chirag

    Enter The Account Type :-saving

    Enter The Account Balance :-10000

    Enter The Account No :-7

    Enter The Account Holder :-ajay

    Enter The Account Type :- currentEnter The Account Balance :-15000

    Enter The Account No :-8

    Enter The Account Holder :-mahival

    Enter The Account Type :-saving

    Enter The Account Balance :-10000

    Enter The Account No :-9

    Goverment. Engineering College, Modasa

    61

  • 8/7/2019 SG Great C programes

    62/63

    Name :- Gevariya Sachin S.

    C Programming

    Enter The Account Holder :-nikunj

    Enter The Account Type :- current

    Enter The Account Balance :-5000

    Enter The Account No :-10

    Enter The Account Holder :- nikhil

    Enter The Account Type :- saving

    Enter The Account Balance :-10500

    Enter Your Account No :- 7

    Account No :- 7

    Account`s Holder :- ajayAccount Type :- Current

    Account Balance :- 15000

    Choice

    1) Debit

    2) Credit

    Enter The Choice :- 1

    Enter The Debit Rs. :- 5000

    The Balance is :- 20000

    (36)

    Find The Symbol Given The File

    #include

    #include

    void main()

    {

    FILE *p1;

    char ch,sym;

    int no;

    clrscr();

    Goverment. Engineering College, Modasa

    62

  • 8/7/2019 SG Great C programes

    63/63

    Name :- Gevariya Sachin S.

    C Programming

    p1=fopen("d:\\1.txt","r");

    printf(" Enter The Symbol :- ");

    scanf("%c",& sym);

    while((ch=getc(p1))!=EOF)

    {

    if(ch==sym)

    {

    no=ftell(p1);

    printf("\n\n %c is The %dCharacter in File",sym,no);

    }

    }

    getch();

    }

    :- Out Put -:

    Enter The Symbol :- @@ is The 17 Character in File

    @ is The 35 Character in File

    63