100 Program

Embed Size (px)

Citation preview

  • 8/11/2019 100 Program

    1/28

  • 8/11/2019 100 Program

    2/28

    51. Program to display the contents of a file using command line argument

    52. Caclulate the age of a person after giving the date of birth53. Cacluate the average marks of student looking at the following table54. Cacluate the amount to be paid after giving the total time.55. Program to convert upper case to lower case56. Program to calculate the power of a number57. INSERT AN ELMENT IN AN ARRAY AT DESIRED POSITION58. program to calculate the sum of the following series

    1 - x + x2/2! + x3/3! --------to nth term59. find the weekday of a particular date(ex-6 sep 2010 (monday)60.Write a program to convert given ip address 192.168.3.35 into 192.168.003.03561.Caclulate the net salary looking at the following table62. Write a program to display : *

    ********

    **********************

    *** *

    63. Write a program which will store roll name and age in student structure andaddress telephone no. In address structure. Implement the nested structure which

    will store information of ten students and their address and organize data in descending order by their roll no.

    64. Write a program to store the information of student such as roll, name and course to a file using read & write system call.65. Write a program to count no. of paragraphs, lines, words and characters present in a file.----------------------------------------------Semester Questions---------------------------------------------

    66. Write a C program that will generate a table of values for the equation;f(X,Y) = 2ex3 + (23 + Y) x Where 1 < x < 5 with an increment 0.5 and 1 < y < 5 w

    ith an increment 0.25.

    67. Write a C program using a do while loop, to calculate the sum of every thirdinteger, beginning with I = 2, for all values of I that are less than 100.

    68. Write a C program to solve a quadratic equation using switch statement.

    69. Write a C program that accepts a character as input data and determine. If the character is an uppercase letter. An uppercase letter is any character that is greater than or equal to `A' and less than or equal to `Z'. If the entered character s an uppercase letter, display the message The character just entered character i

    s an uppercase letter. If the entered character is not uppercase, display the message The character just entered character is not an uppercase letter.

    70. To find the longest word and its length in a give string.

    71. Write program : To create data for 50 students ( roll, name, mark 1, mark 2,mark 3, termmark ) and then find the total for each student and average mark ofall students.72. Write Programs : To round afloating point number to an indicate decimal place e. g. 17.457 will be rounded to 17.46 to two decimal places.

  • 8/11/2019 100 Program

    3/28

    73. Write a C program to create a file for RD account in a bank assuming the file structure as RD account no, instalment amount and number of instalments.74. Write a c program to open a file named BPUT and write a line of text in it byreading the text from the key board.

    75. Declare a 2-dimensional array a of integers of size 4 x 4.. Treat it as matrix. Write a C program to test if this matrix is symmetric.76. Write `C' program to read the contents of file, `f' and paste the contents at the bginning of another file `f' without taking help of any extra file77. To find the longest elements and its location in 2-d array assuming elementsof the array are distinet.* Program to read the current date and time

    * Program to read all files from current directory* Program to copy a file to another file* Program for file locking using flock* Program for file linking

    * Program for locking file using mutex* Program for locking file using Semaphore

    * Program for concurrent server on thread model

    * Program for Client to concurrent server* Program for deamon server

    * Program to insert records in MYSQL* Program to retrive records from MYSQL

    *

    ------------------------------------------------------1. Program to calculate the factorial of a numbermain(){ int x,n;

    printf("Enter a number :"); scanf("%d",&n); x=fact(n); printf("%d",x);}int fact(int n){ int f=1; while(n>0) { f=f*n; n--; }

    return f;}

    2. Program to calculate the sum digits of a number

    main(){ int x,n; printf("Enter a number :"); scanf("%d",&n);

  • 8/11/2019 100 Program

    4/28

    x=sum_digit(n); printf("%d",x);}int sum_digit(int n){ int s=0; while(n>0) { s=s + n%10; n=n/10; } return s;}3. Program to reverse a number

    main(){ int x,n; printf("Enter a number :"); scanf("%d",&n); x=reverse(n); printf("%d",x);}int reverse(int n)

    { int s=0; while(n>0) { s=s *10 + n%10; n=n/10; } return s;}

    4. Program to check the number is strong number or not.main(){

    int x,n; printf("Enter a number :"); scanf("%d",&n); x=strong(n); if(x==n) printf("Strong"); else printf("Not strong");}int strong(int n){ int s=0,r,f; while(n>0)

    { r=n%10; f=fact(r); s=s+f; n=n/10; } return s;}int fact(int n){

  • 8/11/2019 100 Program

    5/28

    int f=1; while(n>0) { f=f*n; n--; } return f;}5. Program to calculate the prime factors of a numbersmain(){ int x,n; printf("Enter a number :"); scanf("%d",&n); prime_factors(n);}int prime_factors(int n){ int i=1,k; while(i

  • 8/11/2019 100 Program

    6/28

    int sum=0,r; while(num!=0) { r=num%10; num=num/10; sum=sum+(r*r*r); } return sum;}7. Program to check given number is palendrome or notmain(){ int n,x; printf("Enter a number:"); scanf("%d",&n); x=palendrome(n); if(x==n) printf("Palendrome "); else printf("Not palendrome ");}

    int palendrome(int num){

    int r=0; while(num>0) { r=r* 10 + num%10; num=num/10; } return r;}8. Program to add between any two numbers using loopmain(){

    int x;int a,b;

    printf("Enter any two numbers :");scanf("%d%d",&a,&b);x=add(a,b);printf("%d ",x);

    }int add(int a,int b){

    while(a>0){

    b++;a--;

    }return b;

    }9. Program to calculate daily expenditure if monthely expenditure is given usingloop.main(){

    int x,n;printf("Enter monthely expenditure :");scanf("%d",&n);x=daily_exp(n);printf("%d ",x);

  • 8/11/2019 100 Program

    7/28

    }int daily_exp(int n){

    int c=0;while(n>0){

    c++;n=n-30;

    }return c;

    }

    10. Program to count number of bits are set to 1 in an integer.

    main(){

    int x,n;printf("Enter a number :");scanf("%d",&n);x=bit_count(n);printf("%d ",x);

    }

    int bit_count(int n){int c=0;while(n>0){

    c++;n=n&n-1;

    }return c;

    }11. Program to calculate G.C.D of any two numbersmain(){

    int n1,n2,x; printf("Enter two numbers:"); scanf("%d%d",&n1,&n2); x=gcd(n1,n2); printf("%d ",x);}int gcd(int n1,int n2){

    while(n1!=n2) { if(n1>n2)

    n1=n1-n2; else n2=n2-n1; } return n1;}12. Program to calculate L.C.M of two numbers.main(){

  • 8/11/2019 100 Program

    8/28

    int n1,n2,x; printf("Enter two numbers:"); scanf("%d%d",&n1,&n2); x=lcm(n1,n2); printf("%d ",x);}int lcm(int n1,int n2){ int x,y; x=n1,y=n2; while(n1!=n2) { if(n1>n2) n1=n1-n2; else n2=n2-n1; } return x*y/n1;}13. Program to calculate fibonacci seriesmain(){ int n; printf("Enter the number range:");

    scanf("%d",&n); fibo(n);}int fibo(int n){ int i=0,j=1,k=2,r,f; printf("%d %d ", i,j); while(k

  • 8/11/2019 100 Program

    9/28

    { temp=x[i]; x[i]=x[len-i-1]; x[len-i-1]=temp; }}15. Program to check the number is Prime number or notmain(){ int n,k; printf("Enter a number:");

    scanf("%d",&n); k=check_prime(n); if(k==2) printf("Prime"); else printf("Not prime");}int check_prime(int n){ int i=1,c=0; while(i

  • 8/11/2019 100 Program

    10/28

    big1 = un[0]; for ( i=1;i

  • 8/11/2019 100 Program

    11/28

    decimal_binary(n);

    }int decimal_binary(int n){ int m,no=0,a=1,rem; m=n; while(n!=0) { rem=n%2; no=no+rem*a; n=n/2; a=a*10; } printf("%d",no);}20. Program to convert binary to decimalmain(){ int n; printf("Enter data in binary format :"); scanf("%d",&n); binary_decimal(n);

    }int binary_decimal(int n){ int j=1,rem,n1=0; while(n!=0) { rem=n%10; n1=n1+rem*j; j=j*2; n=n/10; } printf("%d",n1);}

    21. Program to check the number is perfect number or not.main(){ int n,x; printf("Enter a number:"); scanf("%d",&n); x=check_perfect(n); if(x==n) printf("Perfect number :"); else printf("Not a perfect number :");

    }int check_perfect(int n){ int s=0,i=1; while(i

  • 8/11/2019 100 Program

    12/28

    return s;}22.Program to find generic root of a number.main(){ int n,k; printf("Enter a number"); scanf("%d",&n); k=generic(n); printf("%d",k);}int generic(int n){ int sum,r; if(n10) { sum=0; while(n!=0) { r=n%10; n=n/10; sum+=r;

    } if(sum>10) n=sum; else break; } return sum;}

    23. Program to check a year is leap year or not.main()

    { int year; printf("Enter the year :\n"); scanf("%d",&year);

    if((year % 400==0 )|| ((year % 4==0)&& (year %100!=0))) printf("Leap Year "); else printf("Not leap year");}

    24. Program to revese a string

    main(){

    char x[100];printf("Enter a string :");gets(x);strrev(x);printf("%s",x);

    }int strrev(char *x){

  • 8/11/2019 100 Program

    13/28

    int len=strlen(x); int i; char temp; for(i=0;i

  • 8/11/2019 100 Program

    14/28

    printf("%c",x[len]); len--; }

    }27. Program to count number of words,vowels,digits and space present in string.main(){ int word=0,space=0,digit=0,vowels=0,i; char x[100]; printf("Enter a string :"); gets(x);

    for(i=0;i=48 && x[i]

  • 8/11/2019 100 Program

    15/28

    printf("\n"); }}

    29. Program for multiplication between two matrixmain(){ int a[3][3]={ 1,2,1, 1,2,2, 3,2,1 }; int b[3][3]={ 2,2,1, 1,1,1, 2,3,1 }; int c[3][3]; int i,j,k,sum=0; for(i=0;i

  • 8/11/2019 100 Program

    16/28

    { printf("%d",b[i][j]); } printf("\n"); }

    }32. Program to calculate Amicable pairs from 1 to 1000

    #include "stdio.h"main(){ int n,k; int i=1,s1=0,s2=0; for(k=1;k

  • 8/11/2019 100 Program

    17/28

    s = (a + b + c)/2; area =sqrt (s*(s-a)*(s-b)*(s-c));

    printf("%lf",area);}

    35. Program for Bubble sortmain(){ int a[5]={4,9,40,2,25}; int i; bubble_sort(a); for(i=0;i

  • 8/11/2019 100 Program

    18/28

    { int a[5]={4,9,40,2,25}; int i; insert_sort(a); for(i=0;i

  • 8/11/2019 100 Program

    19/28

    x[j]=temp; quick_sort(x,first,j-1); quick_sort(x,j+1,last); }}

    42. Binary Search using an Array

    void main(){ int a[10],i,n,m,c=0,l,u,mid; printf("Enter the size of an array->"); scanf("%d",&n); printf("\nEnter the elements of the array->"); for(i=0;i

  • 8/11/2019 100 Program

    20/28

    mytime=localtime(&t);

    dd=mytime->tm_mday;mm=mytime->tm_mon+1;yy=mytime->tm_year+1900;

    printf("Enter birtd day,mon and year :");scanf("%d%d%d",&bd,&bm,&by);

    if(dd>=bd)nd=dd-bd;

    elseif(mm==1 || mm==3 || mm==5 || mm==7 || mm==8 || mm==10 || mm==12){

    dd=dd+31;nd=dd-bd;

    }elseif(mm==4 || mm==6 || mm==9 || mm==11){

    dd=dd+30;nd=dd-bd;

    }else

    if(mm==2){dd=dd+28;nd=dd-bd;

    }if(mm>=bm){

    nm=mm-bm;}else{

    mm=mm+12;yy=yy-1;

    nm=mm-bm;}ny=yy-by;printf("%d %d %d \n",ny,nm,nd);

    }53. Cacluate the average marks of student looking at the following table

    p1 p2 p3 average Result>=60% first>=50 second>=40 third

    avg=(p1+p2+p3)/3;

    where p1,p2 and p3 >=30

    main(){

    int p1,p2,p3,avg;

    printf("Enter Marks for p1 p2 & p3 : ");scanf("%d%d%d",&p1,&p2,&p3);

    avg=(p1+p2+p3)/3;

  • 8/11/2019 100 Program

    21/28

    if(p1>=30 && p2>=30 && p3>=30){

    if(avg>=60)printf("First\n");

    elseif(avg>=50)

    printf("Second\n");elseif(avg>=40)

    printf("Third\n");else

    printf("Failed\n");

    }else

    printf("Failed\n");}

    54. Cacluate the amount to be paid after giving the total time.

    Time Amount

    8 hours 100/-

    Next 4 hours 20/- phNext 4 hours 30/- phNext 4 hours 40/- ph

    main(){

    int time,amt;printf("Enter Total Time :");scanf("%d",&time);if(time==8)

    amt=100;elseif(time>8 && time12 && time16 && time

  • 8/11/2019 100 Program

    22/28

    printf("The string is->%s",str); for(i=0;i=65&&str[i]

  • 8/11/2019 100 Program

    23/28

    scanf("%d",&serise);while(looptm_mon+1;yy=mytime->tm_year+1900;mytime->tm_hour = 0;mytime->tm_min = 0;

    mytime->tm_sec = 1;mytime->tm_isdst = -1;

    printf("Enter the day,mon and year :");scanf("%d%d%d",&dd,&mm,&yy);

    if(mktime(mytime) == -1) fprintf(stderr, "Unkown -\n"); else strftime(daybuf, sizeof(daybuf), "%A", mytime);

    printf("It was a %s\n", daybuf);}

    60.Write a program to convert given ip address 192.168.3.35 into 192.168.003.035

    #includeint main(){

    char input[16];char p[4][4];int i,a,b,len;int j,c;

  • 8/11/2019 100 Program

    24/28

    printf("pl enter any ip address\n");scanf("%s",input);a=0;b=0;for(i=0;input[i];i++){

    if(input[i]!=

    .

    )p[a][b++]=input[i];

    else{

    p[a][b]=0;a++;b=0;

    }}p[a][b]=0;

    for(a=0;a=0;j--)

    p[a][j+3-len]=p[a][j];for(j=0;j=10000 200 300 100 ?>=500 100 100 100 ?

    main(){

    int basic,ta,da,pf,net;printf("Enter basic Salary :");scanf("%d",&basic);if(basic>=20000){

    ta=500;da=200;

    pf=200;}elseif(basic>=10000){

    ta=200;da=300;pf=100;

    }else

  • 8/11/2019 100 Program

    25/28

    if(basic>=5000){

    ta=100;da=100;pf=100;

    }else{

    printf("Invalid entry");exit(0);

    }net=(basic+ta+da)-pf;printf("%d", net);

    }

    62. Write a program to display : *

    ********

    **********************

    ***main()

    { int line,star=1,space,i,j,k;printf("Enter the no of line :\n");scanf("%d",&line);printf("Enter the no of space\n");scanf("%d",&space);for(i=0;i

  • 8/11/2019 100 Program

    26/28

    #define SIZE 3struct address{

    char addr[30];long int phoneno;

    };struct student{

    char name[20];int roll;int age;struct address p;

    }__attribute__((__packed__));

    main(){

    struct student details[SIZE],temp;int loop,outer,inner;

    for(loop = 0;loop details[inner].roll){

    temp = details[outer];details[outer] = details[inner];details[inner] = temp;

    }}

    }printf("After Sorting\n");for(loop = 0;loop < SIZE;loop++){

    printf("%s\t%d\t%d\t%s\t%d\n",details[loop].name,details[loop].roll,details[loop].age,details[loop].p.addr,details[loop].p.phoneno);

    }printf("\n");

    }

  • 8/11/2019 100 Program

    27/28

    64. Write a program to store the information of student such as roll, name and course to a file using read & write system call.

    #include "fcntl.h"#include "stdio.h"struct student{

    char name[30];int roll;int age;

    }__attribute__((__packed__));

    main(){

    int handlerStructure, numberOfStudent, loop;

    handlerStructure = open("studentDetails.txt",O_RDWR);

    printf("HOW MANY STUDENT

    S INFORMATION :");scanf("%d",&numberOfStudent);struct student details[numberOfStudent];

    for(loop = 0;loop < numberOfStudent;loop++)

    { write(1,"ENTER NAME OF STUDENT :",strlen("ENTER NAME OF STUDENT:"));

    memset(details[loop].name,0,sizeof(details[loop].name));read(0,details[loop].name,sizeof(details[loop].name));

    write(1,"ENTER THE ROLL NO. :",strlen("ENTER THE ROLL NO.:"));

    read(0,&details[loop].roll,sizeof(details[loop].roll));

    write(1,"ENTER THE STUDENT S AGE :",strlen("ENTER THE STUDENT S AGE :"));

    read(0,&details[loop].age,sizeof(details[loop].age));

    }

    //write(handlerStructure,&details,sizeof(struct student));

    for(loop = 0;loop < numberOfStudent;loop++){

    write(handlerStructure,&details[loop].name,strlen(details[loop].name));

    write(handlerStructure,&details[loop].roll,sizeof(details[loop].roll));

    write(handlerStructure,&details[loop].age,sizeof(details[loop].age));

    }

    loop = 0;while(read(handlerStructure,&details[loop],sizeof(struct student))){

    write(1,&details[loop].name,strlen(details[loop].name));write(1,&details[loop].roll,sizeof(details[loop].roll));write(1,&details[loop].age,sizeof(details[loop].age));loop++;

    }}65. Write a program to count no. of paragraphs, lines, words and characters pres

  • 8/11/2019 100 Program

    28/28

    ent in a file.