C Practical€¦ · Web viewC Practical. Practical of C Write a c program to find Area and...
Transcript of C Practical€¦ · Web viewC Practical. Practical of C Write a c program to find Area and...
ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccfghjklzxcvbnmqwertyuiopasdfghjklzxc
C Practical
Practical of C
[Type text] Page 1
Write a c program to find Area and Circumference of circle.#include<stdio.h>#include<conio.h>#define PI 3.14void main (){
int r;float area, cir;clrscr();printf(“Enter value of radious : “);scanf(“%d”,&r);area = PI*r*r;cir = 2*PI*r;
printf(“The Area = %f”,area);printf(“The circumference = %f”,cir);getch();
}
Write a c program to find the square root of a given number.#include<stdio.h>#include<conio.h>#include<math.h>void main(){
int x,d;clrscr();printf(“Enter a Number : “);scanf(“%d”,&d);x=sqrt(d);printf(“Root = %d”,x);getch();
}
Write a c program to calculate Simple Interest, Where interest = (P*R*N)/100.#include<stdio.h>
#include<conio.h>void main(){
float prn,rate,year;clrscr();printf(“Enter Principal : “);scanf(“%f”, &prn);printf(“Enter Rate : “);scanf(“%f”, &rate);printf(“Enter No. of Year : “);scanf(“%f”, &year);amount = (prn * rate * year) / 100;printf(“Interest = %f”, amount);getch();
}
Write a c program which will read marks of students give grade A if mark is more than 80 otherwise give grade B.
#include<stdio.h> #include<conio.h> #define PI 3.14
void main(){
int marks;clrscr();printf(“Enter marks of student : “);scanf(“%d”,&marks);if(marks >= 80){
printf(“Grade A”);}else{
Printf(“Grade B”);}getch();}
Write a c program which will read salary of employee. Give House Rent Rs. 3000 if salary is more than 10000 otherwise House Rent is Rs. 1500. Also Display total salary.
#include<stdio.h> #include<conio.h>
void main(){
int sal,hra,total;clrscr();printf(“Enter salary of employee : “);scanf(“%d”,&sal);if(sal >= 10000){
hra = 3000;}else{
hra = 1500;}total = sal + hra;printf(“House Rent = Rs %d \n”,hra);printf(“House Rent = Rs %d \n”,hra);getch();
}
Read marks of Students give Grade A+ if marks >80, Grade A if marks >=70 and marks <80, Grade B if marks >=50 and marks <=70, Grade C if marks >=35 and marks <50 otherwise FAIL.
#include<stdio.h>#include<conio.h>void main(){
int marks;clrscr();printf(“Enter marks of Student : “);scanf(“%d”,&marks);if (marks >= 80){
printf(“Grade A+”);}else if(marks >= 70){
printf(“Grade A”);
}else if(marks >= 50){
printf(“Grade B”);}else if(marks >= 35){
printf(“Grade C”);}else {
printf(“Fail”);}getch();
}
Write a c program which will check whether a given number is EVEN or ODD (Use % operator)
#include<stdio.h>#include<conio.h>void main(){
int no, rem;clrscr();printf(“Enter A no. : “);scanf(“%d”,&no);rem=no%2;if(rem==0){
printf(“The no. is Even”);}else{
printf(“The no. is Odd”);}getch();
} Write a c program, which will check if a given number is divisible by 5, or not.
#include<stdio.h>#include<conio.h>
void main(){
int no,rem;clrscr();printf(“ Enter the no. : “);scanf(“%d”,&no);Rem = no % 5;if(rem == 0){
Printf(“The no. is divisible by 5”);}else{
Printf(“The no. is not divisible by 5”);}getch();
} Write a c program, which will find out Largest of 3 numbers.
#include<stdio.h>#include<conio.h>void main(){
int a,b,c;clrscr();printf(“ Enter the First no. : “);scanf(“%d”,&a);printf(“ Enter the Second no. : “);scanf(“%d”,&b);printf(“ Enter the Third no. : “);scanf(“%d”,&c);if(a>b){
if(a>c){
printf(“a is largest”);}else{
printf(“c is largest”);}
}else{
if(b>c){
printf(“b is largest“);}else{
printf(“c is largest“);}
}getch();
}
Write a c program, which will execute as a calculator using switch-case.#include<stdio.h>#include<conio.h>void main(){
int a, b, ch, ans;clrscr();printf(“ Enter the First no. : “);scanf(“%d”,&a);printf(“ Enter the Second no. : “);scanf(“%d”,&b);printf(“1. Addition\n”);printf(“2. Subtraction\n”);printf(“3. Multiplication\n”);printf(“4. Division\n”);printf(“Enter Your Chouce (1 – 4) : ”);scanf(“%d”,&ch);switch(ch){
case 1 : ans = a + b; break;case 2 : ans = a - b; break;case 3 : ans = a * b;
break;
case 4 : ans = a / b; break;default : printf(“Wrong Choice … \n”);
break;}if(ch <= 4 && ch >=1)printf(“Answer : %d\n “,ans);getch();
}
Write a c program which will generate Series of natural Numbers 1, 2, 3… N.#include<stdio.h>#include<conio.h>void main(){
int a,n;clrscr();printf(“Enter the value of N : “);scanf(“%d”,&n);for(a=1;a<=n;a++){
printf(“%d \n”,a);}getch();
}
Write a c program, which will generate following series [Even Numbers] 0, 2, 4, 6… n.
#include<stdio.h>#include<conio.h>void main(){
int a,n;clrscr();printf(“Enter the value of N : “);scanf(“%d”,&n);for(a=0;a<=n;a=a+2){
printf(“%d\n”,a);}
getch();}
Write a c program, which will generate following series [Even Numbers] 0, 2, 4, 6… n.
#include<stdio.h>#include<conio.h>void main(){
int a,n;clrscr();printf(“Enter the value of N : “);scanf(“%d”,&n);for(a=1;a<=n;a=a+2){
printf(“%d\n”,a);}getch();
} Write a c program which will generate following series.
10,9,8,7,…,1. Or N,n-1,n-2,…,1.#include<stdio.h>#include<conio.h>void main(){
int a,n;clrscr();printf(“Enter value of N : “);scanf(“%d”,&n);for(a=n; a >= 1; a --){
printf(“%d\n”,a);}getch();
}
Write a c program, which will generate following series [square of natural numbers]. 1, 4, 9 … N2.
#include<stdio.h>#include<conio.h>
void main(){
int a,n,sq;clrscr();printf(“Enter the value of N : “);scanf(%d”,&n);for(a=1;a <= n; a++){
sq = a * a;printf(“%d * %d =%d\n”,a,a,sq);
}getch();
}
Write a c program, which will display the table of the given number.#include<stdio.h>#include<conio.h>void main(){
int a,n,t;clrscr();printf(“Table of which number : “);scanf(“#d”,&n);for(a=1;a<=10;a++) {
t = n * a;printf(“ %d * %d = %d\n”,n,a,t);
}getch();
}
Write a c program, which will display the factorial of the given number.#include<stdio.h>#include<conio.h>void main(){
int a,n,f;clrscr();printf(“Factorial of which number : “);scanf(“#d”,&n);
for(a=1;a<=n;a++) {
f = f * a;printf(“ factorial of %d is %d \n”,n,f);
}getch();
}
Write a c program, which will check whether a given number is prime, or not?#include<stdio.h>#include<conio.h>void main(){
int a,n,f;clrscr();printf(“Enter a Number : “);scanf(“%d”,&n);f=0;for(a=2;a<n;a++){
if(n % a == 0){
f=1;break;
}}if(f==0){
printf(“%d is Prime Number”,n);}else{
printf(“%d is not Prime Number”,n);}getch();
}
Write a c program, which will generate Prime Numbers between 1…100.#include<stdio.h>#include<conio.h>
void main(){
int a,n,f;clrscr();for(n=1;n<=100;n++){
f=0;for(a=2;a<n;a++){
if(n%a==0){
f=1;break;
}}
if(f==0)printf(“%d”,n);}getch();
} Write a c program, which will find out sum of digits of a given number. Also print
the number in reverse order.#include<stdio.h>#include<conio.h>void main(){
int a,n,sum,rem;clrscr();printf(“Enter a Number : ”);scanf(“%d”,&n);sum=0;while(n>0){
rem=n%10;n=n/10;sum=sum+rem;printf(“%d”,rem);
}printf(“Sum of digits is %d %d”,sum);getch();
} Write a c program, which will check whether the given number is Armstrong or not?
#include<stdio.h>#include<conio.h>void main(){
int a,n,sum,no,cb;clrscr();printf(“Enter a Number : “);scanf(“%d”,&n);sum=0;no=n;while(n>0){
rem=n%10;n=n/10;cb=rem*rem*rem;sum = sum + cb;
}if(no==sum){
printf(“%d is Armstrong Number”,no);}else{
printf(“%d is not Armstrong Number”,no);}getch();
}
Write a c program, which will generate Armstrong number between 1…1000.#include<stdio.h>#include<conio.h>void main(){
int a,n,sum,rem,no,cb;clrscr();for(n=1;n<=1000;n++){
sum=0;
no=n;while(no>0){
rem=no%10;no=no/10;cb=rem*rem*rem;sum=sum+cb;
}if(n==sum){
printf(“%d is Armstrong Number”,sum);}
}getch();
} Write a c program, which will enter age of N persons and find out how many per sons
are between 40 and 60.#include<stdio.h>#include<conio.h>void main(){
int a,n,age,c;clrscr();printf(“Enter the value of N : ”);scanf(“%d”,&n);c=0;for(a=1;a<=n;a++){
printf(Enter Age : “);scanf(“%d”,&n);if(age>=40 && age<=60){
c=c+1;}
}printf(“No. of person between 40 and 60 are %d”,c);getch();
}
Write a c program, which will find out sum of following series.
1+2+3+….+N#include<stdio.h>#include<conio.h>void main(){
int a,n,sum;clrscr();printf(“Enter the value of N : ”);scanf(“%d”,&n);sum=0;for(a=1;a<=n;a++){
sum=sum+a;}printf(“Sum = %d\n”,sum);getch();
}
Write a c program, which will find out sum of following series.0+2+4+….+N#include<stdio.h>#include<conio.h>void main(){
int a,n,sum;clrscr();printf(Enter value of N : );scanf(“%d”,&n);sum=0;for(a=0;a<=n;a=a+2){
sum=sum+a;}printf(“Sum = %d\n”,sum);getch();
}
Write a c program, which will find out sum of following series. 1+3+5+…+N#include<stdio.h>#include<conio.h>
void main(){
int a,n,sum;clrscr();printf(Enter value of N : );scanf(“%d”,&n);sum=0;for(a=1;a<=n;a=a+2){
sum=sum+a;}printf(“Sum = %d\n”,sum);getch();
}
Write a c program, which will find out sum of following series. 1+1/2+1/3+……1/N#include<stdio.h>#include<conio.h>void main(){
int a,n;float sum;clrscr();printf(Enter value of N : );scanf(“%d”,&n);sum=0;for(a=1;a<=n;a=a+1){
sum=sum+(float)1/a;}printf(“Sum = %d\n”,sum);getch();
}
Write a c program, which will find out sum of following series. 1+1/22+1/32+……1/N2
#include<stdio.h>#include<conio.h>void main(){
int a,n,sq;float sum;clrscr();printf(Enter value of N : );scanf(“%d”,&n);sum=0;for(a=1;a<=n;a=a+1){
sq = a * a;sum=sum+(float)1/sq;
}printf(“Sum = %d\n”,sum);getch();
}
Write a c program to generate following shape11 21 2 3 1 2 3 41 2 3 4 5#include<stdio.h>#include<conio.h>void main(){
int i,j;float sum;clrscr();for(i=1;i<=5;i++){
for(j=1;j<=i;j++){
printf(“”%d”,j);}printf(“\n”);
}getch();
}
Write a c program to generate following shape
12 23 3 3 4 4 4 45 5 5 5 5#include<stdio.h>#include<conio.h>void main(){
int i,j;float sum;clrscr();for(i=1;i<=5;i++){
for(j=1;j<=i;j++){
printf(“”%d”,i);}printf(“\n”);
}getch();
}
Write a c program to generate following shape1 2 3 4 51 2 3 41 2 31 21#include<stdio.h>#include<conio.h>void main(){
int i,j;float sum;clrscr();for(i=5;i>=1;i--){
for(j=1;j<=i;j++){
printf(“”%d”,i);}printf(“\n”);
}getch();
}
Write a c program to generate following shape5 4 3 2 15 4 3 25 4 3 5 4 5#include<stdio.h>#include<conio.h>void main(){
Int i,j;float sum;clrscr();for(i=1;i<=5;i++){
for(j=5;j<=i;j++){
printf(“”%d”,j);}printf(“\n”);
}getch();
}
Write C Program to add 10 numbers using Arrays.#include<stdio.h>#include<conio.h>void main(){
int a[30];int n,i,sum=0;clrscr();printf(“Enter the value of N : ”);
scanf(“%d”,&n);for(i=0;i<n;i++){
scanf(“%d”,&a[i]);}sum=0;for(i=0;i<n;i++){
sum=sum+a[i];}printf(“Sum = %d”,sum);getch();
}
Write C Program to find maximum and minimum of N numbers using#include<stdio.h>#include<conio.h>void main(){
int a[30];int n,i,max=0,min;clrscr();printf(“Enter value of N : ”);ccanf(“%d”,&n);for(i=0;i<n;i++){
scanf(“%d”,&a[i]);}max=a[0];min=a[0];for(i=0;i<n;i++){
if(a[i]>max){
max=a[i];}else{
min=a[i];
}}printf(“Maximum = %d\n”,max);printf(“Minimum = %d\n”,min);getch();
}
Write C Program to read marks of N students and display the data in following format.
Roll No Marks Grade 1 40 B 2 80 A 3 70 A 4 54 B 5 45 B Total 289#include<stdio.h>#include<conio.h>void main(){
int a[30];int n,i,max=0;clrscr();printf(“Enter value of N : ”);scanf(“%d”,&n);for(i=0;i<n;i++){
printf(“Enter Marks : ”);scanf(“%d”,&a[i]);
}printf(“Roll No. \t\t Marks \t\t Grade \n”);sum=0;for(i=0;i<n;i++){
printf(“%d %d”,i+1,a[i]);if(a[i]>=80){
printf(“A/n”);}else
{printf(“B/n”);
}sum=sum+a[i];
}printf(“Total = %d”,sum);getch();
}
Write C Program to search a given number in an array [Linear Search]#include<stdio.h>#include<conio.h>void main(){
int a[30];int n,i,s,f=0;clrscr();printf(“Enter value of N : ”);scanf(“%d”,%n);printf(“Enter the Number to be searched… “);scanf(“%d”,&s);for(i=0;i<n;i++){
printf(“Enter Number : ”);scanf(“%d”,&a[i]);
}for(i=0;i<n;i++){
if(a[i]==s){
f=1;}
}if(f==1){
printf(%d Found Successfully”,s););}else{
printf(“%d not found”,s);}getch();
}
Write C Program to search a given number in an array [Binary Search]#include<stdio.h>#include<conio.h>void main(){
int a[30];int n,i,s,f=0,mid,top,bottom;clrscr();printf(“Enter value of N : ”);scanf(“%d”,&n);printf(“Enter the number to be searched …”);scanf(“%d”,&s);for(i=0;i<n;i++){
printf(“Enter Number : “);scanf(“%d”,&a[i]);
}top = 0;bottom = n-1;f=0;while(top<=bottom && f==0){
mid=(top+bottom)/2;if(s>a[i]){
top=mid+1;}else{
if(s<a[i]){
bottom=mid-1;}else{
f=1;}
}}if(f==1){
printf(“%d Found Successfully”,s);}else{
printf(“%d not Found ”,s);}getch();
}
Write C Program to sort a given array og integers [Bubble Sort]#include<stdio.h>#include<conio.h>void main(){
int a[30];int n,i,j,temp;clrscr();printf(“Enter value of N : ”);scanf(“%d”,&n);for(i=0;i<n;i++){
printf(“Enter Number : ”);scanf(“%d”,&a[i]);
}printf(“\n Unsorted Array \n”);for(i=0;i<n;i++){
printf(“%d”,a[i]);}for(i=0;i<n;i++){
for(j=0;j<n-1;j++){
if(a[j]>a[j+1])
{temp=a[j];a[j]=a[j+1];a[j+1]=temp;
}}
}printf(“\n Sorted Array \n”);for(i=0;i<n;i++){
printf(“%d”,a[i]);}getch();
} Write C Program to sort a given array og integers [Selection Sort]
#include<stdio.h>#include<conio.h>void main(){
int a[30];int n , i ,temp,j,pos;
int min = 0 clrscr0; printf(“Enter Number: “); scanf(“%d”,&n); for (i=0;i<n;i++)
{printf(“Enter Number: “)scanf(“%d”,&a[i]);
}printf(“\nUnSorted Array \n”);for (i=0;i<n;i++){
printf(“%d”,a[i]);}for(i=0,i<n;i++){
min = a[i];pos = 0;for(j=i+1; j<n;j++)
{if(a[i] < min){
min = a[j];pos = 0;for(j= i+l;j<n;j++){
if (a[j] < min){
min = a[j];post= j;}
}}if(pos>0){
temp=a[i];a[i]=a[pos];a[pos]=temp;
}}print(“\n sorted array \n”);for(i=0;<n;i++){printf(“%d”,a[i]);}getch();
} Write C Program to read and print the sales of 3 salesmen for 12 months, also print
the Total sales made by each salesman.#include<stdio.h>#include<conio.h>void main(){
int sales[3][12];int n,i,j,total=0;clrscr();for(i=0;i<3;i++){
for(j=0;j<12;j++)
{printf(“Enter Sales [%d] [%d] : ”,I,j);scanf(“%d”,&sales[i][j]);
}}for(i=0;i<3;i++){
total=0;for(j=0;j<12;j++){
printf(“%d”,sales[i][j]);total=total+sales[i][j];
}printf(“ = %d \n”,total);
}getch();
}
Write C Program to read two 3*3 matrix and display multiplication of 2 matrices.#include<stdio.h>#include<conio.h>void main(){
int a[10][10],b[10][10],c[10][10];int n,i,temp,j,p,q,m,n;clrscr();printf(“Enter Row and Column of first matrix \n”);scanf(“%d %d”,&m,&n);printf(“Enter Row and Column of Second matrix \n”);scanf(“%d %d”,&p,&q);printf(“Enter Elements of First Matrix \n”);for(i=0;i<m;i++){
for(j=0;j<n;j++){
printf(“Enter number a[%d][%d] : ”,I,j);scanf(“%d”,&a[i][j]);
}}printf(“Enter elements of second matrix \n”);
for(i=0;i<p;i++){
for(j=0;j<q;j++){
printf(“Enter number a[%d][%d] : ”,I,j);scanf(“%d”,&b[i][j]);
}}printf(“First matrix \n\n”);for(i=0;i<m;i++){
for(j=0;j<n;j++){
printf(“%d”,a[i][j]);}printf(“\n”);
}printf(“Second Matrix \n\n”);for(i=0;i<p;i++){
for(j=0;j<q;j++){
printf(“%d”,b[i][j]);}printf(“\n”);
}printf(“Multiplication of Matrices \n”);for(i=0;i<m;i++){
for(j=0;j<q;j++){
c[i][j]=0;for(k=0;k<n;k++){
c[i][j]=c[i][j]+(a[i][j]*b[i][j]);}printf(“%d”,c[i][j]);
}printf(“\n”);
}
getch();}
Write C Program to read a 3*3 matrix and display its Transpose.#include<stdio.h>#include<conio.h>void main(){
int a[10][10],b[10][10],c[10][10];int m,n;clrscr();printf(“Enter Row and Column of first matrix \n”);scanf(“%d %d”,&m,&n);printf(“Enter Row and Column of Second matrix \n”);scanf(“%d %d”,&p,&q);printf(“Enter Elements of First Matrix \n”);for(i=0;i<m;i++){
for(j=0;j<n;j++){
printf(“Enter number a[%d][%d] : ”,i,j);scanf(“%d”,&a[i][j]);
}}printf(“Matrix U Entered Is \n”);for(i=0;i<m;i++){
for(j=0;j<n;j++){
printf(“%d”,&a[i][j]);}printf(“\n”);
}printf(“Transpose of Matrix is \n\n”);for(i=0;i<m;i++){
for(j=0;j<n;j++){
b[i][j]=a[i][j];printf(“%d”,b[i][j]);
}printf(“\n”);
}getch();
}
Write C Program to generate Pascal Triangle11 11 2 11 3 3 11 4 6 4 11 5 10 10 5 1#include<stdio.h>#include<conio.h>void main(){
int a[6][6]={0,0,0,0,0,0};int I,j;clrscr();for(i=0;i<=5;i++){
for(j=0;j<=i;j++){
if(j==0||i==j){
a[i][j]=1;}else
{
a[i][j]=a[i-1][j-]+a[i-1][j];}
}}
for(i=0;i<=5;i++){
for(j=0;j<=i;j++){
printf(“%d”,a[i][j]);}printf(“\n”);
}getch();
} Write C Program to find factorial of a given number using functions.
#include<stdio.h>#include<conio.h>void main(){
int n,f;clrscr();printf(“Enter value of n : ”);scanf(“%d”,n);f=fact(n)printf(“Factorial = %d”,f);getch();
}int fact(int n){
int i,f=1;for(i=1;i<=n;i++){
f=f*I;}return f;
} Write C Program to find cube of a given number using functions.
#include<stdio.h>#include<conio.h>void main(){
int x,y;clrscr();printf(“Enter a no. whose cube is to be calculated”);scanf(“%d”,&x);y=cube(x);printf(“The cube of %d is %d”,x,y);
getch();}int cube(int a){
int y;y=a*a*a;return y;
} Write C Program which will search given value from an array (Using Function).
#include<stdio.h>#include<conio.h>int search(int a[10],int,int);void main(){
int a[10],s,I,n;int f;printf(“Enter N : ”);scanf(“%d”,&n);for(i=0;i<5;i++){
printf(“Enter value : ”);scanf(%d”,&a[i]);
}printf(“Enter a number to be searched”);scanf(“%d”,&s);f=search(a,n,s); //calling search functionif(f==0){
printf(“search not found”);}else{
printf(“search successful”);}
}int search(int a[10],int n,int si){
int f=o,i;for(i=0;i<n;i++);{
if(a[i]==s){
}}return f;
} Write C Program to sort a given array of integers using function.
#include<stdio.h>#include<conio.h>void main(){
int a[10],n,i;clrscr();printf(“Enter value of n : “);scanf(“%d”,&n);for(i=0;i<n;i++){
printf(“Enter No. : “);scanf(“%d”,&a[i]);
}display(a,n);sort(a,n);display(a,n);getch();
}// Sorting Functionvoid sort(int a[10],int n){
int i,j,temp;for(i=0;i<n;i++){
for(j=0;j<n-1;j++){
if(a[j]>a[j+1]){
temp=a[j];a[j]=a[j+1];a[j+1]=temp;
}
}}
}// Display Arrayvoid display(int a[10];int n){
int i;for(i=0;i<n;i++){
printf(“%d”,a[i]);}
} Write C Program to read two 3*3 matrix and display sum of 2 matrices (Using
Function).#include<stdio.h>#include<conio.h>void readmat(int a[10][10]);void printmat(int p[10][10]);void sum(int a[10][10],int b[10][10],int c[10][10]);void main(){
int a[10][10],b[10][10],c[10][10];int n,i,temp,j;clrscr();printf(“Enter element of first matrix : \n”);readmat(a);printf(“Enter element of second matrix : \n”);readmat(b);printf(“First matrix \n\n”);printmat(a);printf(“Second matrix \n\n”);printmat(b);printf(“Sum of Matrices \n”);sum(a,b,c);getch();
}// Reading Matrixvoid readmat(int a[10][10]){
int i,j;
for(i=0;i<3;i++){
for(j=0;j<3;j++){
printf(“Enter number a[%d][%d] : “,I,j);scanf(“%d”,&a[i][j]);
}}
}// Printing Matrixvoid printmat(int p[10][10]){
int i,j;for(i=0;i<3;i++){
for(j=0;j<3;j++){
printf(“%d”,p[i][j]);}
}}//Additional of Two Matrixvoid sum(int a[10][10],int b[10][10],int c[10][10]){
int i,j;for(i=0;i<3;i++){
for(j=0;j<3;j++){
c[i][j]=a[i][j]+ b[i][j];printf(“%d”,c[i][j]);
}printf(“\n”);
}}
Write C Program to display given string in reverse order.#include<string.h>#include<stdio.h>#include<conio.h>
void main(){
char str[30];int len,k;clrscr();printf(“Enter Your Name : );scanf(“%s”,str);len=strlen(str);printf(“Reverse : “);for(k=len-1;k>=0;k--){
printf(“%c”,str[k]);}getch();
}
Write C Program to accept a word and count how many vowels are there?#include<string.h>#include<stdio.h>#include<conio.h>void main(){
char str[30];int len,k,v=0;clrscr();printf(“Enter a word in small letters not capitals : ”);scanf(“%s”,&str);len=strlen(str);for(k=0;k<len;k++){
switch(str[k]){
case ’a’;case ‘e’;case ‘i’;case ‘o’;case ‘u’;V++;
}}
printf(“No of vowel are %d”,v);getch();
}
Write C Program to convert an alphabet or character into its uppercase.#include<string.h>#include<stdio.h>#include<conio.h>void main(){
char ch,m;clrscr();printf(“Enter a Character : ”);scanf(“%c”,&ch);m=ch-32;printf(“%c”,m);getch();
}
Write C Program to convert a string into its uppercase equivalent.#include<string.h>#include<stdio.h>#include<conio.h>void main(){
char str[30];int len,k;clrscr();printf(“Enter your name : ”);scanf(“%s”,&str);len=strlen(str);printf(“Uppercase : “);for(k=0;k<len;k++){
m=str[k]-32;printf(“%c”,m);
}getch();
}
Write C Program to extract a portion of a character strintg and print the extracetd string. Assume that m characters are extracted, string with nth character.
#include<stdio.h>#include<conio.h>void main(){
char str[30];int I,j,m,n;clrscr();printf(“Enter a string : “);scanf(“%s”,&str);printf(“Enter the string no of character : “);scanf(“%d”,&n);printf(“Enter how many character are extracted : “);scanf(“%d”,&m);for(i=n-1;i<(n+m)-1;i++){
printf(“%c,str[i]);}getch();
} Write C Program, which will read a string and rewrite it in alphabetical order. For
example the word STRING should be written as GINRST.#include<stdio.h>#include<conio.h>void main(){
char str[30],temp;int n,i,j;clrscr();printf(“Enter String : );scanf(“%s”,&str);n=strlen(str);for(i=0;i<n;i++){
for(j=0;j<n;j++){
if(str[i]>str[j+1])
{temp=str[j];str[j]=str[j+1];str[j+1]=temp;
}}
}printf(“sorted String %s”,str);getch();
}
Write C Program OF Quiz and Question can be “Who is developer of C Language”.#include<string.h>#include<stdio.h>#include<conio.h>void main(){
char str[30];char ans={“Dennis”};clrscr();printf(“Who is Developer of C Language : ”);scanf(“%s”,&str);len=strlen(str);if(strcmp(str,ans)==0){
printf(“Very Good”);}else{
printf(“Wrong Answer”);}getch();
} Write a C Program, which will read two strings and combine them into third string.
(An example of strcpy and strcat)#include<string.h>#include<stdio.h>#include<conio.h>void main()
{char a[30],b[30],c[30];clrscr();printf(“Enter First String : ”);scanf(“%s”,&a);printf(“Enter Second String : ”);scanf(“%s”,&b);strcpy(c,a);strcat(c,b);printf(“Thinrd String %s”,c);getch();
}
Write a C Program, which will read 5 strings and search a given word into these.#include<string.h>#include<stdio.h>#include<conio.h>void main(){
char s[5][30];int i,flag=0;clrscr();for(i=0;i<5;i++){
printf(“Enter String : ”);scanf(“%s”,&s[i]);
}printf(“Enter a word to be searched … ”);scanf(“%s”,&b);for(i=0;i<5;i++){
if(strcmp(s[i],b)==0;flag=1;
}if(flag==1){
printf(“Word Found… \n”);}else{
printf(“Word not found… \n”);}getch();
}
Write a C Program, which will read 5 strings and arrange them in Alphabetic Order.#include<string.h>#include<stdio.h>#include<conio.h>void main(){
char s[5][30],temp[30];int i,flag=0;clrscr();for(i=0;i<5;i++){
printf(“Enter first string : “);scanf(“%s”,&s[i]);
}for(i=0;i<5;i++){
for(j=i+1;i<5;i++){
if(strcmp(s[i],s[j])>0){
strcpy(temp,s[i]);strcpy(s[i],s[j]);strcpy(s[j],temp);
}}
}printf(“Sorted List \n”);for(i=0;i<5;i++){
printf(“%s”,s[i]);}getch();
}
Write a C Program, which will read a string and find its length without using Library Function.
or Write a user defined function for finding String Length.
#include<string.h>#include<stdio.h>#include<conio.h>int StLen(char s[30]);void main(){
char s[30];int len,I,flag=0;clrscr();printf(“Enter String : ”);scanf(“%s”,&s);len=StLen(s);printf(“Length=%d”,len);getch();
}int StLen(char s[30]){
int i=0;while(s[i]!=’\0’){
i++;}return i;
}
Write a C Program, which will read a strring and check whether a given string is palindrome or not. The strings MADAM,MALAYALAM are palindrome strings as its reverse results into same strings.
#include<string.h>#include<stdio.h>#include<conio.h>void main(){
char str[30],temp[30]={“”};int i,len,k;clrscr();
printf(“Enter String : “);scanf(“%s”,&str);len=strlen(str)k=0;for(i=len-1;i>0;i--){
temp[k]=str[i];k++;
}if(strcmp(str,temp)==0){
printf(“String is Palindrom”);}else{
printf(“String is not Palindrom”);}getch();
}
Write a C Program to read data for 5 employees using structure and display the total salary of employees.
struct employee{
int empno;char empname[30];int sal;
};void main(){
struct employee emp[10];int i,sum=0;for(i=0;i<5;i++){
printf(“Enter Employee No. : ”);scanf(“%d”,&emp[i].empno);printf(“Enter Employee Name : ”);scanf(“%s”, &emp[i].name);printf(“Enter Employee Salary : ”);scanf(“%d”, &emp[i].sal);
}printf(“EmpNo Name Salary\n”);for(i=0;i<5;i++){
printf(“%d %s %d \n”, emp[i].empno, emp[i].name, emp[i].sal);sum=sum+emp[i]sal;
}printf(“Total Salary = %d”,sum);getch();
}
Write a C Program to read data for 5 employee using structure and display the total salary of employees; also search a given employee from the given array of structure when empno is given to you. (Using Function)
struct employee{
int empno;char empname[30];int sal;
};void reademp(struct employee emp[10]);void dispemp(struct employee emp[10]);void search(struct employee emp[10],int);void main(){
struct employee emp[10];int i,s;printf(“Enter Data for 5 Employee \n\n”);reademp(emp);printf(“The details of Employee \n\n”);disemp(emp);printf(“Enter Emp No you want to search \n\n”);search(emp,s);getch();
}// Function for Readingvoid reademp(struct employee emp[10]){
int i;for(i=0;i<5;i++)
{printf(“Enter Employee No. : ”);scanf(“%d”,&emp[i].empno);printf(“Enter Employee Name : ”);scanf(“%s”, &emp[i].name);printf(“Enter Employee Salary : ”);scanf(“%d”, &emp[i].sal);
}}// Function for Displaying and Calculation Sum of Salaryvoid sispemp(struct employee emp[10]){
int i,sum=0;printf(“EmpNo Name Salary \n”);for(i=0;i<5;i++){
printf(“%d %s %d \n”, emp[i].empno, emp[i].name, emp[i].sal);sum=sum+emp[i]sal;
}printf(“Total Salary = %d”,sum);getch();
}//Function for Searchingvoid search(struct employee emp[10],int s){
int i,f=0;for(i=0;i<5;i++){
if(emp.empno[i]==s){
F=1;}
}if(f==0){
printf(“Employee does not exist \n”);}else{
printf(“Employee Found \n”);
}}
Write a C Program to read data for 5 employees using structure; also search a given employee from the given array of structure when employee name is given to you. Also sort the above data salary-wise (Using Function)?
struct employee{
int empno;char empname [30];int sal;
};//Function Declarationvoid reademp(struct employee emp[10]);void dispemp(struct employee emp[10]);void search(struct employee emp[10],charnm[30]);void dispemp(struct employee emp[10]);void main(){
struct employee emp[10];char nm[30];int i,sum=0,s;printf(“Enter Data for 5 employee \n\n”);reademp[emp);printf(“The details of employee \n\n”);dispemp[emp);printf(“Enter employee name you want to search : \n\n”);scanf(“%s”,&nm);search(emp,nm);sort(emp);printf(“The sorted Data of Employees Salary-wise \n\n”);dispemp(emp);getch();
}//Function for Readingvoid reademp(struct employee emp[10]){
int i;for(i=0;i<5;i++){
printf(“Enter Employee No. : “);
scanf(“%d”,&emp[i].empno);printf(“Enter Employee Name : “);scanf(“%s”,&emp[i].empname);printf(“Enter Employee Salary : “);scanf(“%d”,&emp[i].sal);
}}//Function for Displaying and Calculationing sum of Salaryvoid dispemp(struct employee emp[10]){
int i;printf(“EmpNo Name Salary \n”);for(i=0;i<5;i++){
printf(“%d %s %d \n”, emp[i].empno, emp[i].name, emp[i].sal);}
}//Function for Searchingvoid search(struct employee emp[10],char nm[30]){
int i,f=0;for(i=0;i<5;i++){
if(strcmp(emp.empname,nm)==0){
f=1;}
}if(f==0){
printf(“Employee does not exist \n”);}else{
printf(“Employee Found”);}
}//Function for sorting of Structuresvoid sort(struct employee emp[10]){
struct employee temp;int i,j;for(i=0;i<5;i++){
for(j=i+1;j<5;j++){
if(emp[i].sal>emp[j].sal){
temp=emp[i];emp[i]= emp[j];emp[j]=temp;
}}
}}
Write a C Program to read an array of n integers and print its sum (using Pointers).#include<string.h>#include<stdio.h>#include<conio.h>void main(){
int a[20];int i,sum=0,*p,n;clrscr();printf(“Enter value of N : “);scanf(“%d”,&n);for(i=0;i<n;i++){
printf(“Enter Number : “);scanf(“%d”,&a[i]);
}p=&a[0];for(i=0;i<5;i++){
printf(“%d”,*(p+1));sum=sum+*(p+1);
}printf(“Sum = %d”,sum);getch();
}
Write a program using pointer to print the address and value of String.#include<stdio.h>#include<conio.h>#include<string.h>void main(){
char *str;clrscr();str=”hello”;printf(“String is %s \n”,str”);printf(“Address is %u \n”,str);getch();
}
Write a C Program to find the length of the string using Pointer without using strlen() function.#include<stdio.h>#include<string.h>#include<conio.h>int length(char *s);void main(){
char str[30];int m;clrscr();printf(“Enter the String : ”);gets(str);m=length(str);printf(“Length = %d”,m);getch();
}int length(char *s){
int m=0;while(*s != ‘\0’){
s++;m++;
}
return m;}
Write a C Program to make user defined strcpy() function using Pointer without using strcpy function.#include<stdio.h>#include<string.h>#include<conio.h>void string cpy(char *b,char *a){
char a[30],b[30];clrscr();printf(“Enter the first String : ”);gets(a);stringcpy(b,a);printf(“Copied String = %s”,b);getch();
}//User-Defined string copy Functionvoid stringcpy(char *b,char *a){
int m=0;while(*a!=’\0’){
*b=*a;a++;b++;
}}
Write a C Program to compare one string with another without using Library strcpy() Library function.
#include<stdio.h>#include<string.h>#include<conio.h>int stringcmp(char *a,char *b)void main(){
char a[30],b[30];int n;clrscr();
printf(“Enter the first string : ”);gets(a);printf(“Enter the Second string : ”);gets(b);n=stringcmp(a,b);if(n==0){
printf(“Both string are Equal “);}else if(n>0){
printf(“First string is bigger than second”);}else{
printf(“Second string is bigger than first”);}getch();
}int stringcmp(char *a,char *b){
while(*a!=’\0’ && *b!=’\0’){
if(*a!=*b){
return(*a-*b);}else{
a++;b++;
}}if(*a==’\0’ && *b==’\0’){
return 0;}else if(*a==’\0’){
return-1;
}else if(*b==’\0’){
return 1;}
}
Write a C Program which will create a file of Students.#include<stdio.h>#include<conio.h>void main(){
int rno,marks;char name[30];int i;FILE *p;clrscr();p=fopen(“student.dat”,”w”);for(i=1;i<=5;i++){
printf(“\nEnter Roll No. : “);scanf(“%d”,&rno);printf(“\nEnter Name : “);scanf(“%d”,&name);printf(“\nEnter Marks : “);scanf(“%d”,&marks);fprintf(p,“%3d %10s %4d”,rno,name,marks);
}fclose(p);
}
Write a C Program which will display the student data created in last program.#include<stdio.h>#include<conio.h>void main(){
int rno,marks;char name[30];int i;
FILE *p;clrscr();p=fopen(“student.dat”,”r”);for(i=1;i<=5;i++){
fscanf(p,“%3d %10s %4d ”,&rno,&name,&marks);printf(“%d %s %d \n”,rno,name,marks);
}fclose(p);
}
Write a C Program, which will read the text file “test.txt” and display its contents on the screen.#include<stdio.h>#include<conio.h>Void main(){
FILE *p;char a;clrscr();p=fopen(“test.txt”,”r”);while(!feof(p)){
a=getc(p);printf(“%c”,a);
}fclose(p);getch();
}
Write a C Program, which will read the text file “test.txt” and display its contents on the screen. Also count number of vowels in the file.#include<stdio.h>#include<conio.h>void main(){
FILE *p;int c=0;char a;clrscr();
p=fopen(“test.txt”,”r”);while(!feof(p)){
a=getc(p);printf(“%c”,a);switch(a){
case ‘a’:case ‘e’:case ‘i’:case ‘o’:case ‘u’:c=c+1;break;
}}printf(“\n\n No. of vowel in File are %d”,c);fclose(p);getch();
}
Write a C Program, which will copy a text file “test.txt” and display its contents on the screen. Also count number of characters in the file
#include<stdio.h>#include<conio.h>void main(){
FILE *p;int c=0;char a;clrscr();p=fopen(“test.txt”,”r”);while(!feof(p)){
a=getc(p);printf(“%c”,a);c=c+1;
}printf(“\n\n No. of Characters in File are %d”,c);fclose(p);
getch();}
Write a C Program, which will copy a text file into another.#include<stdio.h>#include<conio.h>void main(){
clrscr();FILE *p *q;char a;p=fopen(“test.txt”,”r”);q=fopen(“newtest.txt”,”w”);while(!feof(p)){
ch=getc(p);putc(ch,q);
}fclose(p);fclose(q);getch();
}
Write a C Program to copy a text file into another by changing case.#include<stdio.h>#include<conio.h>void main(){
FILE *p *q;char ch,m;clrscr();p=fopen(“test.txt”,”r”);q=fopen(“newtest.txt”,”w”);while(!feof(p)){
ch=getc(p);if(ch>=’a’ && ch<=’z’){
m=ch-32;putc(m,q);
}else if(ch>=’a’ && ch<=’z’){
m=ch+32;putc(m,q);
}else{
putc(ch,q);}
}fclose(p);fclose(q);getch();
}
Write a C Program, which will replace single space with consecutive spaces.#include<stdio.h>#include<conio.h>void main(){
int f=0;FILE *p *q;char ch;clrscr();p=fopen(“test.txt”,”r”);q=fopen(“newtest.txt”,”w”);while(!feof(p)){
ch=getc(p);if(ch==’ ’ && f==0){
putc(ch,q);f=1;
}else if(ch==’ ’ && f==1){
continue;}else
{putc(ch,q);f=0;
}}fclose(p);fclose(q);getch();
}
Write a C Program to create a file of Integers. [Using putw]#include<stdio.h>#include<conio.h>void main(){
int a,i;FILE *p;clrscr();p=fopen(“test.dat”,”w”);for(i=1;i<=5;i++){
printf(“Enter Number :”)scanf(“%d”,&a);putw(a,p);
}fclose(p);getch();
}
Write a C Program to read a file of Integers. [Using getw]#include<stdio.h>#include<conio.h>void main(){
int a,i;FILE *p;clrscr();p=fopen(“test.dat”,”r”);
for(i=1;i<=5;i++){
a=getw(p);printff(“%d \n”,a);
}fclose(p);getch();
}
Write a C Program, which will read a file of Integers and write even number to one file and odd numbers into another file.
#include<stdio.h>#include<conio.h>void main(){
clrscr();FILE *p,*q,*r;int a,i;p=fopen(“test.dat”,”r”);q=fopen(“even.dat”,”w”);r=fopen(“odd.dat”,”w”);while(!feof(p)){
a=getw(p);if(a%2==0){
putw(a,q);}else{
putw(a,r);}
}fclose(p);fclose(q);fclose(r);getch();
}