Posts

C program to find power of given number.

Question: Write a Program in C to find out value of given power(X,Y) of number using recursion. Source Code: #include void Pow1(int x,int y) { if(y==0) { printf("1"); } else { printf(x*Pow1(x,(y-1))); } } int main() { int x,y; printf("Enter the value of x and y\n"); scanf("%d \n %d \n",&x,&y); printf("Value is:\n"); Pow1(x,y); return 0; } Output: Enter the value of x and y 2 2 Value is: 4

C program to find roots of Quadratic Equation.

Question: Write a Program in C to find the roots of Quadratic Equation. Source Code: #include #include int main() { int a,b,c,det; double root1,root2; printf("Enter the value of a, b and c from Quadratic Equation\n"); scanf("%f \n %f \n %f \n" ,&a, &b, &c); det=(b*b)-(4*a*c); if(det Output: Enter the value of a, b and c from Quadratic Equation 1 -2 1 Root1=1.00 Root2=1.00

C program to find fibonacci series.|c |languagecopy.blogspot.

Question: Write a Program in C to take input from user and find the fibonacci series of number. Source Code: #include void fib(int num1) { if(num1==0) { printf("0"); } else if(num1==1) { printf("0 , 1"); } else { int term1=0,term2=1; int i,next; for(i=0;i Output: Enter the number to find the fibonacci series 5 fibonacci series: 0,1,1,2,3,

C program to take elements of Matrix 3x3 and find transpose of matrix.|C |languagecopy.blogspot.com|

Question: Write a Program in C to take elements of a matrix[3][3] and find the transpose of matrix. Source Code: #include int main() { int mat[3][3],i,j; printf("Enter the elements of matrix 3X3\n"); for(i=0;i Output: Enter the elements of matrix 3X3 Original Mtrix is: 1 2 3 4 5 6 7 8 9 Transpose of Mtrix is: 1 4 7 2 5 8 3 6 9

C program to find the factorial of number.|Recursion Function|

Question: Write a Program in C to take input from user and find the factorial of a given number. Source Code: #include int fact(int num) { if (num==0 || num==1) { return 1; } else { return (num*fact(num-1)); } } int main() { int num1; printf("Enter Number\n"); scanf("%d",&num1); printf("Factorial of numbers is :%d",fact(num1)); return 0; } Output: Enter Number 5 Factorial of numbers is:120

C program to create a simple Calculator using Function.

Question: Write a Program in C to create a simple calculator to perform addition, subtraction, multiplication division and modulus. Source Code: #include int add(int a, int b) { return a+b; } int sub(int a, int b) { return a-b; } int mul(int a, int b) { return a*b; } int divi(int a, int b) { return (a/b); } int mod(int a, int b) { return a%b; } int main() { int num1,num2,choice; char c; hello: printf("*Calculator*\n"); printf("Enter Choice\n"); printf("1. Addition \n 2. Subtraction \n 3. Multiplication \n 4. Division \n 5. Modulus \n "); scanf("%d",&choice); switch(choice) { case 1: printf("Enter two numbers;\n"); scanf("%d \n %d",&num1,&num2); printf("Addition:%d",add(num1,num2)); break; case 2: printf("Enter two numbers;\n"); scanf("%d \n %d",&num1,...

C program to subtract Matrix1 to Mtrix2.

Question: Write a C program to take elements of two matrix 3 X 3 and do the subtraction and display the result. Source Code: #include int main() { int mat1[3][3],i,j; int mat2[3][3],mat3[3][3]; printf("Enter elements of Matrix 1\n"); for(i=0;i Output: Enter elements of Matrix 1 1 2 3 4 5 6 7 8 9 Enter elements of Matrix 2 1 2 4 5 6 7 8 9 elements of Matrix 1 1 2 3 4 5 6 7 8 9 elements of Matrix 2 1 2 3 4 5 6 7 8 9 Subtraction of two matrix is: 0 0 0 0 0 0 0 0 0

C program to addition of two matrix.

Question: Write a C program to take elements of two matrix 3 X 3 and add both matrix. Source Code: #include int main() { int mat1[3][3],i,j; int mat2[3][3],mat3[3][3]; printf("Enter elements of Matrix 1\n"); for(i=0;i Output: Enter elements of Matrix 1 1 2 3 4 5 6 7 8 9 Enter elements of Matrix 2 1 2 4 5 6 7 8 9 elements of Matrix 1 1 2 3 4 5 6 7 8 9 elements of Matrix 2 1 2 3 4 5 6 7 8 9 Addition of two matrix is: 2 4 6 8 10 12 14 16 18

C program to swap elements of two Array.

Question: Write a C program to take two array of 5-5 elements and swap elements of Array A to Array B. Source Code: #include int main() { int arrA[5],arrB[5],i,temp; printf("Enter elements of Array A\n"); for(i=0;i Output: Enter elements of Array A 2 3 4 5 6 Enter elements of Array B 7 8 9 10 11 After Swapping arrayA arrayB 7 2 8 3 9 4 10 5 11 6

C program to find all even numbers from an Array.

Question: Write a C program to take 5 numbers from user and display all even numbers from them. Source Code: #include int main() { int arr[5],i; printf("Enter 5 numbers\n"); for(i=0;i Output: Enter 5 numbers 34 23 45 56 34 Even Numbers are: 34 56 34

C program to reverse the given number.|Without function | Using Function|

Question: Write a programm in C to reverse the given number. Source Code: #include int main() { int num,sum=0,rem; printf("Enter num \n"); scanf("%d",&num); while(num !=0) { rem=num%10; sum=(sum*10)+rem; num=num/10; } printf("Reverse of number: %d\n",sum); return 0; } Output: Enter num 345 Reverse of number: 543 Using Function: #include void reverse(int num) { int sum=0,rem; while(num !=0) { rem=num%10; sum=(sum*10)+rem; num=num/10; } printf("Reverse of number: %d\n",sum); } int main() { int num1; printf("Enter num1 \n"); scanf("%d",&num1); reverse(num1); return 0; } Output: Enter num 789 Reverse of number: 987

C program to find sum of square of digit.|without function| with Function.

Question: Write a programm in C to find sum of square of digit of the number. Source Code: #include int main() { int num1,sum=0,rem; printf("Enter num1 \n"); scanf("%d",&num1); while(num1 !=0) { rem=num1%10; sum=sum+(rem*rem); num1=num1/10; } printf("Sum of square of digit: %d\n",sum); return 0; } Output: Enter num1 23 Sum of square of digit: 13 Using Function: #include void squareDigit(int num) { int sum=0,rem; while(num !=0) { rem=num%10; sum=sum+(rem*rem); num=num/10; } printf("Sum of square of digit: %d\n",sum); } int main() { int num1; printf("Enter num1 \n"); scanf("%d",&num1); squareDigit(num1); return 0; } Output: Enter num1 13 Sum of square of digit: 10

Write a C program to swapping of two numbers with and without third variable.

Source Code: without third variable. #include int main() { int num1,num2; printf("Enter num1 \n"); scanf("%d",&num1); printf("Enter num2 \n"); scanf("%d",&num2); printf("Number before swapping:\n"); printf("num1:%d\n",num1); printf("num2:%d\n",num2); num1=num1+num2; num2=num1-num2; num1=num1-num2; printf("Number after swapping:\n"); printf("num1:%d\n",num1); printf("num2:%d\n",num2); return 0; } Output: Enter num1 67 Enter num2 45 Number before swapping: num1:67 num2:45 Number after swapping: num1:45 num2:67 With third variable: #include int main() { int num1,num2,num3; printf("Enter num1 \n"); scanf("%d",&num1); printf("Enter num2 \n"); scanf("%d",&num2); printf("Number before swapping:\n"); printf("num1:%d\n",num1); ...

Write C program to sort the given numbers in ascending orders.

Ascending order: Ascending order means the elements will be sorted in increasing order. Source Code: #include void main() { int num[5],i,j,temp; printf("Enter 5 numbers:\n"); for(i=0;i num[j]) { temp=num[i]; num[i]=num[j]; num[j]=temp; } } } printf("soted elements are:\n"); for(i=0;i Output: Enter 5 numbers: 34 67 45 87 90 soted elements are: 34 45 67 87 90

Functions in Python.

Python Functions: In python, function is a group of related statements that perform a specific task. A function is a block of organized, reusable cod that is used to perform a single, related action. Functions provide better modularity for your application and a high degree of code reusing. Types of Functions: i)Built in Functions ii) User defined Functions Built in Functions: You already know, Python gives you many built in functions like print(). User defined Function You can also create your own functions. These functions are called user defined function. Example: def swap(x,y): '''creating user temp=x define swap x=y function''' y=temp return x,y x=2 y=3 print(swap(x,y)) #calling function Outupt: (3,2) Defining a Function: Function Definition provides the information about function name, parameters and the definition what operation is to be performed. 'def...

Comments in Python.

Python Comments: A comment in python starts with the hash character(#). Comments are in the source code for humans to read, not for computers to execute. Example: #This is a comment Types of Python comments: 1)Single lined comment 2)Multi lined comment 3)Inline comments Single lined comment: In case user want to specify a single line comment,then comment must start with #. Example: int a=10 #here a is a variable. print("Hello,world") print(a) Output: Hello,world 10 Multi lined comments: Multi lined comment can be given inside triple quotes. Example: ''' This is multiline comment in python''' Inline comments: If a comment is placed on the same line as a statements,it is called an inline comments. Similar to the block comments, an inline comments beigns with a single hash(#) sign and followed by a space and comment. Example: N=10 n+=1 # increase n by 1

Operators in Python.

Operator: Operators are special symbol in python that carry out arithmatic or logical computation, Used to perform specific operation. For Example: >>>2+3 5 Types of Operator: 1. Arithmatic operator 2. Assignment operator 3. Comparison operator 4. Logical operator 5. Bitwise operator 6. Identity operator 7. Membership operator Arithmatic operator: Arithmatic operators are used to perform mathematical operation like addition,subtraction ,multiplication etc. Addition(+): Adds value on either of the operators. Example: a=10 b=20 print(a+b) Output: 30 Subtraction(-): Subtracts right hand operands form left hand oprand. Example: a=20 b=10 print(a-b) Output: 10 Multiplication(*): Multiply values on either side of the operators. Example: a=20 b=10 print(a*b) Output: 200 Division(/): divides left hand operand by right hand operand. Example: a=20 b=10 print(a/b) Output: 2 Module(%): Divides left hand operan...

C program to addition of square of n numbers.

Image
Question: Write C program to find out:   Source Code: #include void main() { int num,iter,sum=0; printf("Enter value of n:\n"); scanf("%d",&num); for(iter=1;iter Output: Enter value of n: 6 Sum of series is:91

Literals in Python.

Literls:- Literal is a raw data given in a variable or consatant. In python, there are various type of literls. Type of Literls:- 1. String 2. Numeric 3. Boolean 4. Special String: String is an immutable data type. String formed by enclosing a text in the qutoes. Both single and double quotes can be used. Example: string='This is python' char="C" print(string) print(char) Output: This is python C Numeric Literls: Numeric literals are immutable data type. Numeric literals can belong to four different Numeric type. Types of Numeric Literls: .Integer .Long .Float .Complex integer(signed integer): Number( can be +ve and -ve) with nuber fractional part. Example: 230 Long(long integer): Integer of unlimited size followed by lower case or uppercase. Example 8703285L Float(folating point): Real numer with both integer and fractional part. Example 35.2 Complex(complex): In the form ...

C program to calculate average of marks and display grade.

Question: Write a C program to take marks of 5 subjects from user and calculate its percentage and display the grade. Source code: #include int main() { int sub1,sub2,sub3,sub4,sub5; printf("Enter sub1 marks:"); scanf("%d",&sub1); printf("Enter sub2 marks:"); scanf("%d",&sub2); printf("Enter sub3 marks:"); scanf("%d",&sub3); printf("Enter sub4 marks:"); scanf("%d",&sub4); printf("Enter sub5 marks:"); scanf("%d",&sub5); float t_marks=(sub1+sub2+sub3 +sub4+sub5)/5; float perct=t_marks*100; if(perct > 75) { printf("Grade: A"); } else if(perct > 60 && perct = 50 && perct Output: Enter sub1 marks:100 Enter sub2 marks:100 Enter sub3 marks:100 Enter sub4 marks:100 Enter sub5 marks:100 Grade: A