Tuesday, February 13, 2024

12. (ii) WAP to display Fibonacci series (i)using recursion, (ii) using iteration

 12. (ii) WAP to display Fibonacci series (i)using recursion, (ii) using iteration


PROGRAME CODE

#include<stdio.h>

#include<iostream>

using namespace std;

class fibo{

                public:

                                void fibo1(int num){

                                                int a=1,b=1,c=0;

                                                for(int i=1;i<=num;i++){

                                                                if(i==1)

                                                                                cout<<a<<" ";

                                                                else if(i==2)

                                                                                cout<<b<<" ";

                                                                else{

                                                                                c=a+b;

                                                                                a=b;

                                                                                b=c;

                                                                                cout<<c<<" ";                                   

                                                                }

                                                }

                                }

                                int fib(int num){

                                                if(num==1||num==2)

                                                                return 1;

                                                return(fib(num-1)+fib(num-2));

                                }                             

                                void fibo2(int num){

                                                for(int i=1;i<=num;i++){

                                                                cout<<fib(i)<<" ";

                                                }

 

                                }

};

int main(){

                fibo ob;

                int num=0,opt=0;

                do{

                                cout<<"\nPRESS 0 TO EXIT ..."<<endl;

                                cout<<"PRESS 1 TO CALCULATE FIBONACCI SERIES ...."<<endl;

                                cout<<"PRESS 2 TO CALCULATE FIBONACCI SERIES USING RECERSION..........."<<endl;

                                cin>>opt;

                                switch(opt){

                                                case 0:

                                                                break;

                                                case 1:

                                                                cout<<"ENTER THE POSITION OF SEREIES....."<<endl;

                                                                cin>>num;

                                                                ob.fibo1(num);

                                                                break;

                                                case 2:

                                                                cout<<"ENTER THE POSITION OF SEREIES....."<<endl;

                                                                cin>>num;

                                                                ob.fibo2(num);

                                                                break;                                                  

                                                default:

                                                                cout<<"...........ERROR............"<<endl;

                                }

                }while(opt!=0);

                return 0;

}


Friday, January 19, 2024

Find the roots of equation(x3-4x-9)Newton Raphson method.

 #include<stdio.h>

#include<math.h>

double f(double x)

{

return x*x*x-4*x-9;

}

double fd(double x)

{

return 3*x*x-4;

}

void main()

{

int i=1;

double a,b,tol;

printf("Enter value of y0:");

scanf("%lf",&a);

printf("Enter tolerance:");

scanf("%lf",&tol);

while(1)

{

       b=a;

       a=a-f(a)/fd(a);

       printf(" y%d ---> %f\n",i++,a);

       if(fabs(a-b)<tol)

           break;

}

printf("\n Solution=%f",a);

}

Output:

Enter value of y0:2

Enter tolerance:0.00001

y1 ---> 3.125000

y2 ---> 2.768530

y3 ---> 2.708196

y4 ---> 2.706529

y5 ---> 2.706528


Solution=2.706528

Enter value of y0:3

Enter tolerance:0.00001

y1 ---> 2.739130

y2 ---> 2.706998

y3 ---> 2.706528

y4 ---> 2.706528


Solution=2.706528

Enter value of y0:5

Enter tolerance:0.00001

y1 ---> 3.647887

y2 ---> 2.953279

y3 ---> 2.730187

y4 ---> 2.706777

y5 ---> 2.706528

y6 ---> 2.706528


Solution=2.706528

Simpson 3/8 Rule C Program

 #include<stdio.h>

#include<math.h>

float f(float x)

{

    return(x);

}


void main()

{

    int i,n;

    float x0,xn,h,y[20],so,se,ans,x[20];

    printf("\n Enter values of x0,xn,h: ");

    scanf("%f%f%f",&x0,&xn,&h);

    n=(xn-x0)/h;

    if(n%2==1)

    {

        n=n+1;

    }

    h=(xn-x0)/n;

    printf("\n Refined value of n and h are:%d %f\n",n,h);

    printf("\n Y values: \n");

    for(i=0; i<=n; i++)

    {

        x[i]=x0+i*h;

        y[i]=f(x[i]);

        printf("\n %f\n",y[i]);

    }

    so=0;

    se=0;

    for(i=1; i<n; i++)

    {

        if(i%3==0)

        {

            so=so+y[i];

        }

        else

        {

            se=se+y[i];

        }

    }

    printf("  i        x           y\n");

    for (i=0;i<n;i++)

    {

        printf("  %d    %lf    %lf\n",i,x[i],y[i]);

    }

    ans=h/3*(y[0]+y[n]+4*so+2*se);

    printf("\n Final integration is %f",ans);


}

trapezoidal rule numerical in c

 #include<stdio.h>

float f(float x)

{

    return(x*x);

}

void main()

{

    int i,n;

    float x0,xn,h,y[20],s=0,ans,x[20];

    printf("\n Enter values of x0,xn,h: ");

    scanf("%f%f%f",&x0,&xn,&h);

    n=(xn-x0)/h;

    if(n%2==1)

    {

        n=n+1;

    }

    h=(xn-x0)/n;

    printf("\n Refined value of n and h are:%d %f\n",n,h);

    printf("\n Y values: \n");

    for(i=0; i<=n; i++)

    {

        x[i]=x0+i*h;

        y[i]=f(x[i]);

        printf("\n %f\n",y[i]);

    }


    for(i=1; i<n; i++)

    {

            s=s+y[i];

    }


    printf("  i        x           y\n");


    for (i=0;i<n;i++)

    {

        printf("  %d    %lf    %lf\n",i,x[i],y[i]);

    }

    ans=h/2*(y[0]+y[n]+2*s);

    printf("\n Final integration is %f",ans);

}

SIMPSON'S 1/3RD RULE NUMERICAL PROGRAM IN C

 #include<stdio.h>

#include<math.h>

float f(float x)

{

    return(x);

}

void main()

{

    int i,n;

    float x0,xn,h,y[20],so,se,ans,x[20];

    printf("\n Enter values of x0,xn,h: ");

    scanf("%f%f%f",&x0,&xn,&h);

    n=(xn-x0)/h;

    if(n%2==1)

    {

        n=n+1;

    }

    h=(xn-x0)/n;

    printf("\n Refined value of n and h are:%d %f\n",n,h);

    printf("\n Y values: \n");

    for(i=0; i<=n; i++)

    {

        x[i]=x0+i*h;

        y[i]=f(x[i]);

        printf("\n %f\n",y[i]);

    }

    so=0;

    se=0;

    for(i=1; i<n; i++)

    {

        if(i%2==1)

        {

            so=so+y[i];

        }

        else

        {

            se=se+y[i];

        }


    }

    printf("  i        x           y\n");

    for (i=0;i<n;i++)

    {

        printf("  %d    %lf    %lf\n",i,x[i],y[i]);

    }

    

    ans=h/3*(y[0]+y[n]+4*so+2*se);

    printf("\n Final integration is %f",ans);


    getch();

}

Wednesday, January 10, 2024

Skill Enhancement Courses (SEC) python language

Question Set 2

1.Describe arithmetic operators in python.
2. Describe string function (any 5).
3. Describe list and its function.(any 5).
4. Compare list, tuple, dictionaries with example.
5. WAP to find all prime number between a range.
6. WAP to find an element from a list.
7. Input a word from user and count all occurrences of the word in a string.
8. Describe bitwise operators in python.
9. Explain nested if with an example in python.
10. WAP to find all armstrong number between a range.

Saturday, January 6, 2024

Os Assignment 3rd Semester General

 1. Input two numbers and print the sum.

2. Input a number an  print the factorial of a number.

3. Print fibbonacci series upto n terms.

4. Input a number and check it is even or odd.

5. Input year and check it is leap year or not.

6. Print the sum of the series 1+2+3+4+5+6...+N

7. Input a number and check it is prime or not.

8. Input a number and print the reverse of the number.

9.Input a number and check it is palindrome or not.

10. Input a string from user and the find a pattern from the user.

11. Print all file and folders under current directory.

12. Print total number of lines, characters, words in a file.

Saturday, December 9, 2023

c language question set 3

c language question set 3


What are enumerations?

What do the functions atoi(), itoa()?







introduction 

types of type conversions in C

Describe the different types of constants in C with example? 

what are C tokens?

What are C identifiers?

Difference between syntax vs logical error? 

Explain formatted input and output statement with examples.

return value of printf() and scanf().

What is dangling else problem? Explain how to handle tis in C programming

variable declaration vs variable definition

What is the difference between „a‟ and “a” in C?






operator

Explain the hierarchy (priority) and associativity(clubbing)of operators in „C‟ with example?

explain sizeof operator



LOOP

entry controlled loop vs exit controlled

difference between break and continue

use of goto


STRING 

1.Difference between strdup and strcpy?

2.What is the difference between Strings anD character Arrays?

3. getchar(),getch(),getche(),getc,gets()

4.puts(),putchar()

5.strlen(),strcpy(),strcmp(),strcat()

isalnum(c) Is c an alphanumeric character? 

isalpha(c) Is c an alphabetic character

 isdigit(c) Is c a digit? 

islower(c) Is c alower case letter?

 isprint(c) Is c a character?

 ispunct(c) Is c a punctuation mark?

 isspace(c) Is c a white space character?

 isupper(c) Is c an upper case letter?

 tolower(c) Convert ch to lower case

 toupper(c) Convert ch to upper case


ARRAY 

What is an array? How to declare and initialize arrays? Explain with examples

How can we declare and initialize 2D arrays? Explain with examples

IF ELSE SWITCH



pointer

What is a far pointer? Where we use it?

why is the void pointer useful? When would you use it?

What is a NULL Pointer? Whether it is same as an uninitialized pointer?

What is static memory allocation?

What is dynamic memory allocation?

. What is pointer to a pointer?

What is an array of pointers?

Difference between an array of pointers and a pointer to an array?

Discuss on pointer arithmetic?

What is the invalid pointer arithmetic?

Are the expressions *ptr ++ and ++ *ptr same?

Explain in detail how to access a one dimensional array using pointers with an example program?

Explain in detail how to access a two dimensional array using pointers with an example program?

Write in detail about pointers to functions? Explain with example program.



STRUCTURE

1. What are the differences between structures and union?

2.What are the differences between structures and arrays?

3.What is the use of typedef?

4.What the advantages of using Unions?

5. Explain array of structure and structure within a structure with an example




FILE

How would you use the functions fseek(), freed(), fwrite() and ftell()?

fopen,fclose

ftell,fseek,rewind


DYNAMIC MEMORY ALLOCATION 

1.What are the differences between malloc () and calloc ()?

What is the purpose of realloc(),free()?


PREPROCESSOR

1. What are macros? What are its advantages and disadvantages?

What is a preprocessor, what are the advantages of preprocessor?

What are the two forms of #include directive?

List and explain compiler control directives

difference  between object macro and funtion macro



FUNCTION

Difference between pass by reference and pass by value?

What is recursion?

Difference between formal argument and actual argument? 

Distinguish between Library functions and User defined functions in C and Explain with examples.

Function Declaration vs Function Definition

Explain the Parameter Passing Mechanisms in C-Language with examples.

How can we pass the Whole Array to Functions? Explain with example 

Explain function call, function definition and function prototype with examples


command line argument 

What do the ‘c’ and ‘v’ in argc and argv stand for?




storage class

What does static variable mean?

What are different types of storage classes in ‗C‘




 

Tuesday, October 10, 2023

Stack using linked list

 Stack using linked list (pranjali)



#include<stdio.h>

#include<malloc.h>

struct node

  {

    int data;

    struct node *link;

  };

 struct node * top= NULL;  //Initially stack is empty

  void push()

   {

       struct node*temp;

       temp=(struct node *)malloc(sizeof(struct node));

       printf("Enter a value");

       scanf("%d",&temp->data);

       temp->link=top;

       top=temp;

   void pop()

    {

    if(top==NULL)

    {

    printf("Stack underflow");

}

else

{

struct node*temp=top;

top=top->link;

printf("poped value=%d",temp->data);

free(temp);

}

}

    void display()

  {

  struct node *temp=top;

  if(top==NULL)

  {

  printf("Empty stack");

   }

  else

   {

 while(temp!=NULL)

    {

    printf("%d",temp->data);

    temp=temp->link;

}

  }

  

int main()

    {

    while(1)

    {

    printf("enter 1 for push\n");

    printf("enter 2 for pop\n");

    printf("enter 3 for display\n");

    printf("enter 4 for exit");

   

int choice;

    scanf("%d",&choice);

    switch(choice)

    {

    case 1:

    push();

break;

case 2:

pop();

break;

case 3:

display();

break;

case 4:

printf("end of the program");

break;

default:

printf("wrong choice\n"); 

  }

  if (choice==4)

  break;

}

}

sparse matrix representation in 2d array

sparse matrix representation in 2d array(arik mukherjee)



 # include<iostream>

using namespace std;


int main()

{

int a[10][10],row,col,count=0,i,j,k=1;

int s[10][3];

cout<<"total number of row";

cout<<"total number of column";

cin>>row;

cin>>col;

cout<<"enter value";

for(i=0;i<row;i++)

{

for(j=0;j<col;j++)

{

cin>>a[i][j];

}

}

cout<<"matrix element\n";

for(i=0;i<row;i++)

{

for(j=0;j<col;j++)

{

cout<<a[i][j]<<" ";

}

cout<<"\n";

}

//count total number of nonzero elements

for(i=0;i<row;i++)

{

for(j=0;j<col;j++)

{

if(a[i][j]!=0)

{

count++;

}

}

}

cout<<count;

s[0][0]=row;

s[0][1]=col;

s[0][2]=count;

for(i=0;i<row;i++)

{

for(j=0;j<col;j++)

{

if(a[i][j]!=0)

{

s[k][0]=i;

s[k][1]=j;

s[k][2]=a[i][j];

k++;

}

}

}

cout<<"\n output array \n";

for(i=0;i<count+1;i++)

{

for(j=0;j<3;j++)

{

  cout<<s[i][j]<<" ";

}

cout<<"\n";

}

}