ALL SIR NOTES HAVE BEEN UPLOADED HERE.
Q. Write a program to print your name?
// Program to print the name
#include<stdio.h>
int main()
{
printf("Name :- Your name \n");
return 0;
}
Q.Write a program to print your personal details ?
#include<stdio.h>
int main()
{
printf("----------------------------------------------------\n");
printf("Name :- Your name \n");
printf("Father's Name :- Your father name \n");
printf("DOB :- Your date of birth \n");
printf("Address :- Your address \n");
return 0;
}
Q. Write a program to perform arithmetic operations on number ?
//Program to perform arithmetic operations
#include<stdio.h>
int main()
{
int n1=10,n2=4;
printf("Addition=%d \n",n1+n2);
printf("Subtractiion=%d \n",n1-n2);
printf("Multiplication=%d \n",n1*n2);
printf("Quotient=%d \n",n1/n2);
printf("Remainder=%d \n",n1%n2);
return 0;
}
Q. Write a program to swap two numbers ?
//Program to swap two numbers
#include<stdio.h>
void main() // Here I use void main() instead of int main() so no requirement to use return0;
{
int a=20,b=10,c;
printf("\n Values before swapping a=%d \n b=%d ",a,b);
c=a;
a=b;
b=c;
printf("\n Values after swapping a=%d \n b=%d",a,b);
}
Q. Write a program to calculate area and perimeter of a rectangle ?
#include<stdio.h>
int main()
{
int l, b, area, perimeter ;
printf("\n Enter the length and Breadth of rectange:-");
scanf("%d %d",&l, &b);
area=l*b;
perimeter=2*(l+b);
printf("\n Area of Rectangle=%d",area);
printf("\n Perimeter of rectangle=%d",perimeter);
return 0;
}
Q. Write a program to check whether the input number is ‘Odd’ or ‘Even’ ?
#include<stdio.h>
int main()
{
int n;
printf("\n Enter the number to check even or not:-");
scanf("%d",&n);
if(n%2==0)
printf("\n Number =%d is even ",n);
else
printf("\n Number =%d is odd",n);
return 0;
}
Q. Write a program to find out maximum among three numbers using if else statement ?
#include<stdio.h>
int main()
{
int n1,n2,n3;
printf("Enter the values of three nu:-");
scanf("%d %d %d",&n1,&n2,&n3);
if(n1>n2)
{
if(n1>n3)
printf("\n N1=%d is Maximun",n1);
else
printf("\n N3=%d is Maximum",n3);
}
else
{
if(n2>n3)
printf("\n N2=%d is Maximum",n2);
else
printf("\n N3=%d is Maximum",n3);
}
}
Q. Write a program to check whether the input character is vowel or not ?
#include<stdio.h>
int main()
{
char ch;
printf(''\n Enter the character:-");
scanf("%c",&ch);
if(ch=='a' || ch=='e' || ch=='i' || ch=='o' || ch=='u' || ch=='A' || ch=='E' || ch=='I' || ch=='O' || ch=='U' )
printf("\n Character is vowel");
else
printf(" \n Chacracter is not vowel");
return 0;
}
Q. Write a program to implement simple calculator using switch case statement. (Operations: +, -, *, /, %) ?
#include<stdio.h>
int main()
{
int n1,n2,result,choice;
printf("\n Enter two numbers");
scanf("%d %d",&n1,&n2);
printf("\n Enter 1. Addition");
printf("\n Enter 2. Subtraction");
printf("\n Enter 3. Multiplication");
printf("\n Enter 4. Division");
printf("\n Enter 5. Remainder");
printf("\n Enter your choice(1-5)");
scanf("%d",&choice);
switch(choice)
{
case 1 :
result=n1+n2;
printf("Addition of two nu. %d+%d =%d ",n1,n2,result);
break;
case 2 :
result=n1-n2;
printf("Subtraction of two nu. %d-%d =%d ",n1,n2,result);
break;
case 3 :
result=n1*n2;
printf("Multiplication of two nu. %d*%d =%d ",n1,n2,result);
break;
case 4 :
result=n1/n2;
printf(" Division of two nu. %d/%d =%d ",n1,n2,result);
break;
case 5 :
result=n1%n2;
printf("Remainder of two nu. %d % %d = %d ",n1,n2,result);
break;
default :
printf("\n Wrong choice ");
}
return 0;
}
Q. Write a program to pritnt the sum of digits of a given integer?
#include<stdio.h>
void main()
{
int n,r,s=0,digit=0;
printf("\n Enter the number");
scanf("%d",&n);
while(n>0)
{
r=n%10;
s=s+r;
n=n/10;
digit++;
}
printf("\n Sum of digits=%d",s);
printf("\n no of digits =%d",digit);
}
Q. Write a program to check whether a given no. is palindrome or not?
#include<stdio.h>
void main()
{
int n,r,s=0,temp;
printf("Enter the number:");
scanf("%d",&n);
temp=n;
while(n>0)
{
r=n%10;
s=s*10+r;
n=n/10;
}
if(temp==s)
printf("\n Number is Palindrome");
else
printf("\n Number is not Palindrome");
}
Q. Write a program to check whether a number is prime or not?
// write a program to check whether a nu is prime or not
#include<stdio.h>
int main()
{
int n,i,flag=0;
scanf("%d",&n);
for(i=2;i<n;i++)
{
if(n%i==0)
{
flag=1;
break;
}
}
if(flag==0)
printf("Number is Prime Number");
else
printf("Number is not Prime");
}
Q. Write a Program to implement the following pattern?
*
**
***
*****
#include<stdio.h>
int main()
{
int n,i,j;
printf("Enter no of rows");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
printf("\n");
for(j=1;j<=i;j++)
{
printf("*");
}
printf("\n");
}
return 0;
}
Q. Write a Program to implement the following pattern?
1
12
123
1234
#include<stdio.h>
int main()
{
int n,i,j;
printf("Enter number of rows");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
for(j=1; j<=i; j++)
{
printf("%d" , j);
}
}
return 0;
}
Q. Write a program to implement the following pattern?
A
BB
CCC
DDDD
#include<stdio.h>
int main()
{
int n,i,j;
char ch='A';
printf("Enter number of rows");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
printf("*");
for(j=1;j<=i;j++)
{
printf("%c",ch);
}
ch=ch+1; //ch++
}
return 0;
}
Q. Write a program ot print the sum and avg of n no. of elements in a array?
#include<stdio.h>
int main()
{
int i,n,sum=0;
float avg;
printf("Enter the nu. of elements");
scanf("%d",&n);
int arr[n];
printf("Enter %d numbers",n);
for(i=0;i<n;i++)
{
scanf("%d",&arr[i]);
sum=sum+arr[i];
}
avg=(float)sum/n;
printf("Sum of all numbers=%d \n",sum);
printf("Average of all numbers=%2f \n",avg);
return 0;
}
Q. Write a program to print the sum and avg of n no. of elements in a array?
#include<stdio.h>
#define MAX 100
int main()
{
int i,n,arr[MAX],item,flag;
printf("Enter the size of array");
scanf("%d",&n);
int arr[n];
printf("Enter %d numbers",n);
for(i=0;i<n;i++)
{
scanf("%d",&arr[i]);
}
printf("Enter item you want to search");
scanf("%d",&item);
for(i=0;i<n;i++)
{
if(arr[i]==item)
{
flag=1;
printf("Present at position%d \n"i++);
}
}
if(flag!=1)
printf("Item is not present in the array \n");
return 0;
}
Q. Write a program to find the lagest number in an array of a integer?
#include<stdio.h>
int main()
{
int i,n,arr[10],max;
printf("Enter the size of array");
scanf("%d",&n);
int arr[n];
printf("Enter %d numbers",n);
for(i=0;i<n;i++)
{
scanf("%d",&arr[i]);
}
max=arr[0];
for(i=0;i<n;i++)
{
if(arr[i]>max)
{
max=arr[i];
}
}
printf("Maximum element=%d",max);
return 0;
}
Q. Write a program to perform the addition and subtraction in matrix?
// write the program to perform the addition and subtraction in matrix
#inlude<stdio.h>
# define M 10
void input (int a[][M],int,int);
void display (int a[][M],int,int);
int main()
{
int mat1[M][M],mat2[M][M],add[M][M],sub[M][M];
int row,col,i,j;
printf("Enter the no of rows for matrix 1");
scanf("%d",&row);
printf("Enter the no of colmns for matrix 1");
scanf("%d",&col);
printf("Enter %d number for mat1:",row*col);
input(mat1,row,col);
printf("Enter %d number for mat2:",row*col);
input(mat2,row,col);
// logic code for add two matrix
for(i=0;i<row;i++)
{
for(j=0;j<col;j++)
{
add[i][j]=mat1[i][j]+mat2[i][j];
}
}
//Displaying elements of matrix 1
printf("Elements of matrix1:\n");
display(mat1,row,col);
//Displaying elements of matrix 2
printf("Elements of matrix1:\n");
display(mat2,row,col);
//Addition of two matrices
printf("Addition of matrices:\n");
display(add,row,col);
//Subtraction of two matrices
printf("Subtraction of matrices:\n);
display(sub,row,col);
return 0;
}
void input(int a[][M],int r ,int c)
{
int i,j;
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
scanf("%d",&a[i][j]);
}
}//end of input function
void display(int a[][M],int r ,int c)
{
int i,j;
for(i=0;i<r;i++)
{
printf("\n");
for(j=0;j<n,j++)
printf("%d",a[i][j]);
}
}//end of display function