Slip 1.AProgram to accept a four digit number from user and count zero , odd and even digits of the entered number. #include <stdio.h> #include
void main() { int rem,num,evencnt=0,oddcnt=0,zerocnt=0; printf("Enter an integer: "); scanf("%d", &num); while(num >0) { rem= num % 10; num=num /10; if((rem!= 0) && (rem % 2 == 0)) { evencnt++; } else if(rem== 0) { zerocnt++; } else { oddcnt++; } } getch(); printf("Number of even: %d",evencnt); printf("\n number of add :%d",oddcnt); printf("\n number of zero:%d",zerocnt); getch(); }
1B.program name:- menu driven program _ Add book information _ Display book information #include<stdio.h> #include #include<string.h> void main() { struct book { int bno; char bname[20]; char author[20]; }b[5]; int i,n,ch; char name[20],c; clrscr(); while(1) { printf("\n menues"); printf("\n 1.Add book information"); printf("\n 2.display book information"); printf("\n 3. exit from program"); printf("\n Enter your choice="); scanf("%d",&ch); switch(ch) { case 1: printf("\n How many info.you want to add="); scanf("\n %d",&n); for(i=0;i
printf("\n %d\t%s\t%s",b[i].bno,b[i].bname,b[i].author); break; case 3: exit(0); default :printf("\nEnter you correct choice"); } } getch(); }
Slip 2A.Write a C program to generate the following pattern for n lines: Aa Aa Aa Aa #include<stdio.h> #include main() { int i,j; char c,ch; clrscr(); for(i=1;i<=4;i++) { c='A'; ch='a'; for(j=1;j<=i;j++) { printf(" %c%c",c,ch); c=c+1; ch=ch+1; } printf("\n"); } getch(); }
Bb Bb Bb
Cc Cc
Dd
*/
2 B.program name:=factorial of given number by using recursion #include<stdio.h> #include int recfact(int n); void main() { int n,ans; printf("\n enter the number"); scanf("\n %d",&n); ans= recfact(n); printf("\n factorial is %d",ans); getch(); } int recfact(int n1) { int rem,fact=0; if(n1==1) { return 1; } else { fact=n1*recfact(n1-1); } return fact; }
Slip 3A. Program to check whether a given number is Armstrong or not #include<stdio.h> #include void main() { int num,sum=0,rem,temp; clrscr(); printf("\n enter the value of num"); scanf("\n %d",&num); temp=num; while(num>0) { rem=num%10; sum=sum+(rem*rem*rem); num=num/10; } if(temp==sum) { printf("\n number is armstrong"); } else { printf("\n number is not armstrong"); } getch(); }
3 B.Program to do the following a) Create a text file ‘input.txt’ b) Print the contents of file in reverse order #include<stdio.h> #include void main() { FILE *fp; char ch,s[100]; int i=0; clrscr(); printf("Enter the content of file\n"); fp=fopen("E:\input.txt","w"); while((ch=getchar())!=EOF) { fputc(ch,fp); } fclose(fp); fp=fopen("E:\input.txt","r"); while((s[i]=fgetc(fp))!=EOF) { i++; } while(i>=0) { printf("%c",s[i]); i--; } fclose(fp); getch(); }
Slip 4A.program name:program to calculate the sum of digits of a given number #include<stdio.h> #include void main() { int num,rem,sum=0; clrscr(); printf("\n enter the value of num"); scanf("\n %d",&num); while(num>0) { rem=num%10; sum=sum+rem; num=num/10; } printf("\n %d",sum); getch(); } /* output enter the value of num678 21 */
4B.program to accept customer details such as: Account_no, Name, Balance in account,. Assume Maximum 10 customers in the bank. Write a function to print the account no and name of each customer with balance below Rs.100. (using structure) #include<stdio.h> #include struct customer { int accno; char name[20]; int balance; }cust[5]; void display(struct customer[5]); void main() { struct customer c[5]; clrscr(); display(c); getch(); } void display(struct customer cust[5]) { int i; printf("\n enter customer information"); for(i=0;i<5;i++) { printf("\n enter the account no:"); scanf("%d",&cust[i].accno); printf("\n enter the custmer name:"); scanf("%s",&cust[i].name); printf("\n enter the balance:"); scanf("%d",&cust[i].balance); } printf("\n the customer details are"); printf("\n Account no\tname"); for(i=0;i<5;i++) { if(cust[i].balance<100) { printf("\n\t%d",cust[i].accno); printf("\t%s",cust[i].name); } }
} /* output enter customer information enter the account no:101 enter the custmer name:mane enter the balance:23456 enter the account no:102 enter the custmer name:sane enter the balance:78 enter the account no:103 enter the custmer name:sharma enter the balance:5098 enter the account no:104 enter the custmer name:raj enter the balance:34 enter the account no:105 enter the custmer name:rahul enter the balance:4567 the customer details are Account no name 102 sane 104 raj */
Slip 5A .Program to accept a string from user and generate following pattern (e.g. input is string “abcd”). a ab abc abcd abc ab a #include<stdio.h> #include #include<string.h> void main() { char s[10]; int l=0,i,j; clrscr(); printf("Enter the string="); gets(s); l=strlen(s); for(i=0;i0;i--) { for(j=0;j
5B.Program name write a c program to copy the content of file into another file #include<stdio.h> #include void main() { FILE *fs,*ft; char ch; clrscr(); fs=fopen("a.txt","r"); if(fs==NULL) { printf("\n unable to open file"); } ft=fopen("b.txt","w"); if(ft==NULL) { printf("cannot open target file"); } while((ch=fgetc(fs))!=EOF) { fputc(ch,ft); } fclose(fs); fclose(ft); getch(); }
Slip 6A.Write a ‘C’ program to accept a string from user and delete all the vowels from that string & display the result #include<stdio.h> #include void main() { int i=0,flag=0; char s[50]; clrscr(); printf("\n enter the string:-"); gets(s); while(s[i]!=NULL) { if(s[i]=='a'||s[i]=='e'||s[i]=='i'||s[i]=='o'||s[i]=='u'||s[i]=='A' || s[i]=='E' || s[i]=='I'|| s[i]=='O' || s[i]=='U') { continue; } else { printf("%c",s[i]); } i++; } getch(); }
6B.program to display transpose of matrix using user defined function #include<stdio.h> #include #include void main() { int a[3][3],sum=0; int i,j,n; clrscr(); printf("\n enter the value of row and col"); scanf("\n %d",&n); a[i][j]=(int)calloc(n,sizeof(int)); printf("\n enter the array element-"); for(i=0;i
7A. Write a C program to generate the following pattern for n lines: 1 2 3 4 5 6 7 8 9 10 */ #include<stdio.h> int main() { int i,j,k; k=1; clrscr(); for(i=1;i<=5;i++) { for(j=4;j>=i;j--) { printf("%d",k++); } printf("\n"); } getch(); }
7B.Write a C program to perform the following operations on string using user defined function a. Calculate length of string. b. Copy one string into another. # include<stdio.h> void main() { int ch; void len(); void copy(); clrscr(); while(1) { printf("\n- : User Defined String Functions : -"); printf("\n1 Find String Length "); printf("\n 2String Copy "); printf("\n3 Exit"); printf("\n Enter Your Choice: "); scanf("%d",&ch); switch(ch) { case 1: len(); break; case 2: copy(); break; case 3: exit(); } getch(); } } void len() { char str[50]; int l;
printf("\nEnter String : "); scanf("%s",str); l=strlen(str); printf("\nLength = %d",l); }
void copy() { char str1[50],str2[50]; int i,j,n,k; clrscr(); printf("\n Please Give The STRING1 : "); scanf("%s",str1); printf("\n Please Give The STRING2: "); scanf("%s",str2); strcpy(str1,str2); printf("\n AFTER COPYING STRING2 INTO STRING1 IS %s .",str1); }
Slip 8A.Write a C program to generate following pattern for n lines: * * * *
* *
*
* *
#include<stdio.h> #include main() { int i,j,k,row,col; clrscr(); printf("input the number of rows="); scanf("%d",&row); printf("input the number of column="); scanf("%d",&col); for(i=0;i
*
8 B.Write a ‘C’ Program to calculate sum of elements of a mXn matrix #include<stdio.h> #include void main() { int a[10][10],i,j,m,n,sum=0; clrscr(); printf("\nEnter the 3*3 matrix="); for(i=0;i<3;i++) { for(j=0;j<3;j++) { scanf("%d",&a[i][j]); } } for(i=0;i<3;i++) { for(j=0;j<3;j++) { sum=sum+a[i][j]; } } printf("\nsum of elements of matrix is=%d",sum); getch(); }
Slip 9A.Write a C program to calculate sum of Fibonacci series up to a given number. #include<stdio.h> #include void main() { int n,a=0,b=1,i,c; clrscr(); printf("\n enter two many term u want"); scanf("\n %d",&n); printf("\n %d",a); printf("\n %d",b); for(i=1;i<=n;i++) { c=a+b; printf("\n %d",c); a=b; b=c; } getch(); } /* output
9 B. Write a ‘C’ Program to accept ‘n’ numbers from user, store these numbers into an array and count the number of occurrence of each number. #include<stdio.h> #include void main() { int n,i,j,cnt,a[10],temp,no; clrscr(); printf("\nenter the limit = "); scanf("%d",&n); printf("\n Enter the %d number",n); for(i=0;ia[j]) { temp=a[i]; a[i]=a[j]; a[j]=temp; } } } for(i=0;i
Slip 10A. Write a C program to calculate x(y+z) by using user defined function #include<stdio.h> void power(int x,int y, int z); void main() { int x,y,z; printf("Enter value of x: "); scanf("%d",&x); printf("Enter value of y: "); scanf("%d",&y); printf("Enter value of z: "); scanf("%d",&z); power(x,y,z); } void power(int x,int y, int z) { int ans = 1, i; for(i = 1; i <= (y+z); i++) ans *= x; printf("%d ^ (%d+%d) = %d",x,y,z,ans); }
10B. program name:- write a menu driven prodram in 'c' which performs the following ,operations on string . write separate function for each option, -cheak if one string is substring of another string , -count number of occurrences of acharacter in the string, -Exit. #include<stdio.h> #include #include<string.h> void main() { int ch; char str1[30],str2[30],occ; int i=0,cnt=0; clrscr(); while(1) { printf("\n menues"); printf("\n1. check if one string is substring of another string"); printf("\n2. count number of occurrences of characters in the string"); printf("\n3.exit"); printf("\nEnter Your choice: "); scanf("%d",&ch); switch(ch) { case 1:printf("\n enter the first string"); scanf("%s",str1); printf("\n enter the second string"); scanf("%s",str2); if(strstr(str1,str2)==NULL) { printf("\n second string is not substring of first string"); } else { printf("\n second string is substring of first string"); } break; case 2: printf("\n enter the string"); scanf("%s",&str1); printf("\n enter the character to find occurences"); scanf("%s",&occ); i=0,cnt=0; while(str1[i]!='\0')
{ if(str1[i]==occ) { cnt++; } i++; } printf("\n the number of occurencs is %d",cnt); break; case 3:exit(0); } } getch(); }
Slip 11A. program to accept character & display its ASCII value and its next & previous character #include<stdio.h> #include void main() { char ch; clrscr(); printf("\n enter the value ch"); scanf("\n %c",&ch); printf("\n the ascii value of character is %d",ch); printf("\n the next ascii character is %c",ch+1); printf("\n the privious ascii character is %c",ch-1); getch(); }
11B. Write a ‘C’ Program to accept ‘n’ numbers and store all prime numbers in an
array and display this array #include<stdio.h> #include void main() { int a[10],n,i,j,sum=0,prime[10],t=0; clrscr(); printf("Enter the value of n="); scanf("%d",&n); printf("Enter the array=\n"); for(i=0;i
Slip 12A.Write a C program to calculate the x to the power y without using standard function. #include<stdio.h rel="nofollow"> #include void main() { int i,x,y, ans; clrscr(); ans=1; printf("Enter the value of x"); scanf("%d", &x); printf("Enter the value of y"); scanf("%d", &y); for(i=1; i<=y; i++) { ans= ans*x; } printf(" %d to the power %d is %d", x, y, ans); getch(); }
12B.program name Name Write a 'C' program to store the records of student (stud_no,stud_name,stud_addr,stud_percentage )in a file using structure. #include<stdio.h> #include void main() { struct stud { int sno; float per; char name[20],add[20]; }s; int i,n; char ch; FILE *fp; fp=fopen("a.txt","w"); if(fp==NULL) { printf("\nUnable to open file!"); } else { printf("\nEnter the stud no:->"); scanf("%d",&s.sno); printf("\nEnter the stud name:->"); scanf("%s",s.name); printf("\nEnter the stud add:->"); scanf("%s",s.add); printf("\nEnter the stud per:->"); scanf("%f",&s.per); fprintf(fp,"%d\n%s\n%s\n%f",s.sno,s.name,s.add,s.per); } fclose(fp); getch(); }
Slip 13A. Write characters #include<stdio.h>
a
‘C’
Program
#include void main() { char str[20]; int i=0; clrscr(); printf("\n enter the string"); scanf("\n %s",str); for(i=0;i<strlen(str);i=i+2) { printf("%c",str[i]); } getch(); }
to
accept
a
string
from
user
and
display
the
alternate
13B. Write a ‘C’ Program to sort elements of an array in ascending order using
dynamic memory allocation #include<stdio.h> #include #include void main() { int a[5]; int i,j,n,temp; clrscr(); printf("\n enter the limit of array"); scanf("\n %d",&n); a[i]=(int) calloc(n,sizeof(int)); printf("\n enter the array element"); for(i=0;ia[j]){ temp=a[i]; a[i]=a[j]; a[j]=temp; }}} printf("\n the asending elements are"); for(i=0;i
Slip 14A. Write a C program to calculate the area of following: i. Circle i. Rectangle
ii.
Triangle
#include<stdio.h> #include #include<math.h> void main() { int ch; clrscr(); while(1) { printf("\n1. For are of triangle"); printf("\n2. For area of circle"); printf("\n3. For area of ractangle"); printf("\n4. For are of square"); printf("\n5.exit"); printf("\nEnter your choice:"); scanf("%d",&ch); switch(ch) { case 1: { int b,h,area; printf("Enter base and height:"); scanf("%d%d",&b,&h); area=(b*h)/2; printf("The aree of triangle=%d",area); break; } case 2: { float r,area; printf("Enter readius"); scanf("%g",&r); area=3.14594*r*r; printf("\n area of circle=%g",area); break; } case 3: { int l,b,area; printf("Enter lenght and breadth:"); scanf("%d%d",&l, &b);
area=l*b; printf("Area of rectangle:%d\n",area); break; } case 4: { int area,l; printf("Enter lenght:"); scanf("%d",&l); area=l*l; printf("The are of square:%d",area); break; } case 5: { exit(0); } } } getch(); }
14B. Write a ‘C’ Program to count the number of characters, number of words and number of lines from a text file and display the result #include<stdio.h> #include void main() { FILE *fp; char ch; int noc=0,now=0,nol=0,not=0; clrscr(); fp=fopen("a.txt","r"); if(fp==NULL) { printf("\n unable to open file"); } while((ch=fgetc(fp))!=EOF) { if(ch==EOF) { break; } noc++; if(ch==' ') { now++; } if(ch=='\n') { nol++; } if(ch=='\t') { not++; } } fclose(fp); printf("\n the no of characters are %d",noc); printf("\n the no of words are %d",now+nol); printf("\n the no of lines are %d",nol); printf("\n the no of tabs are %d",not); getch(); }
Slip 15A. program to check whether given number is Palindrome or not. #include<stdio.h> #include void main() { int num,rem,sum=0,temp; clrscr(); printf("\n enter the value of num"); scanf("\n %d",&num); temp=num; while(num>0) { rem=num%10; sum=rem+(sum*10); num=num/10; } if(temp==sum) { printf("\n number is palindrome"); } else { printf("\n number is not palindrome"); } getch(); } /*output enter the value of num121 number is palindrome */
15B. Write a ‘C’ Program to find the union and intersection of the two sets of integer (Store it in two arrays) #include<stdio.h> #include void main() { int i,k=0,x[10],y[10],c[25],j,n,n1,d[25],f=0; clrscr(); printf("\n how many elements in SET 1:"); scanf("%d",&n); printf("\n please enter the elements" ); for(i=0;i
for(j=0;j
Slip 16A. C program to check whether given number is perfect or not. #include<stdio.h> #include void main() { int i,num,sum=0,temp; clrscr(); printf("\n enter the value of num"); scanf("\n %d",&num); temp=num; for(i=1;i<=num;i++) { if(num%i==0) { sum=sum+i; } } if(num==temp) { printf("\n the num is perfect"); } getch(); }
16B. Write a C program to accept string from the user & replace all occurrences of character ‘a’ by ‘*’ symbol.*/ #include<stdio.h> #include void main() { int i=0,flag=0; char s[50]; clrscr(); printf("\n enter the string:-"); gets(s); while(s[i]!=NULL) { if(s[i]=='a') { s[i]='*'; } i++; } printf("\n the string is %s",s); getch(); }
Slip 17A. program to generate following pattern for n lines. A B B C C C D D D D E E E E E */ #include #include<stdio.h> void main() { int i,j,n; char c='A'; clrscr(); printf("\nEneter the no of lines to be printed: "); scanf("%d",&n); for(i=0;i
Slip 17B. Program to accept ‘n’ numbers from user, store these numbers into an array. Find out Maximum and Minimum number from an Array(using function). #include<stdio.h> #include void minmax(int a[5],int n); void main() { int a[5]; int i,n,max,min; clrscr(); printf("\n entre the limit of array"); scanf("\n %d",&n); printf("\n enter the array element"); for(i=0;imax) { max=a1[i]; } if(a1[i]<min) { min=a1[i]; } } printf("\n the largest element is %d",max); printf("\n the smallest element is %d",min); }
Slip 18A. Write a C program to convert a given string into uppercase & vice versa. #include<stdio.h> #include #include<string.h> void main() { char s1[20]; clrscr(); printf("\n enter a string with upper and lowercase letters"); gets(s1); printf("\The string after converting to uppercase\t%s",strupr(s1)); printf("\n The string after converting to lowercase\t%s",strlwr(s1)); getch(); }
18 B.C’ Program to create student structure having fields roll_no, stud_name, mark1, mark2, mark3. Calculate the total and average of marks and arrange the records in descending order of marks. #include<stdio.h> #include void main() { struct student { int rollno; char name[20]; int marks[3]; int total; float avg; }stud[2]; int i,j; struct student temp; clrscr(); printf("\n enter studentinfo"); for(i=0;i<2;i++) { printf("\n enter rollno"); scanf("\n %d",&stud[i].rollno); printf("\n enter name"); scanf("\n %s",&stud[i].name); stud[i].total=0; printf("\n enter marks"); for(j=0;j<3;j++) { scanf("\n %d",&stud[i].marks[j]); stud[i].total=stud[i].total+stud[i].marks[j] ; stud[i].avg=stud[i].total/3; } } for(i=0;i<2;i++) { for(j=i+1;j<2;j++) { if(stud[i].total<stud[j].total) { temp=stud[i]; stud[i]=stud[j]; stud[j]=temp; }
} } printf("\n the student info are"); printf("\n ROLLNO NAME TOTAL AVG"); for(i=0;i<2;i++) { printf("\n %d\t %s\t %d\t %f",stud[i].rollno,stud[i].name,stud[i].total,stud[i].avg); } getch(); }
Slip 19A. program to generate following pattern for n lines: 1 3 5 7 9 11 #include<stdio.h> #include void main() { int i,j,temp=1,n; clrscr(); printf("\n enter the number of lines"); scanf("\n %d",&n); for(i=1;i<=n;i++) { for(j=1;j<=i;j++) { printf("%d",temp); temp=temp+2; } printf("\n"); } getch(); }
19B. Program to accept Book details of ‘n’ books as book_title, author, publisher and cost. Assign the accession number to each book in increasing order Display these details as 1. Books of a specific author 2. Books by a specific Publisher 3. All Books costing Rs. 500 and above. 4. All Books. (Using Structure Array) #include<stdio.h> #include #include<string.h> void main() { struct book { int bno,bcost,baccno; char bname[20],bpub[20],bauthor[20]; }p[10]; int n,i,f,ch; char pubname[20],authorname[20]; clrscr(); printf("Enter the limit of structure array="); scanf("%d",&n); for(i=0;i
printf("\nEnter the choice="); scanf("%d",&ch); switch(ch) { case 1: printf("Enter the author name you want="); flushall(); gets(authorname); f=0; for(i=0;i=500) { printf("\nbno=%d\nbname=%s\ncost=%d\t accession no=%d",p[i].bno,p[i].bname,p[i].bcost,p[i].baccno); } } break; case 4: for(i=0;i
printf("\nbno=%d\nname=%s\nauthor=%s",p[i].bno,p[i].bname,p[i].bauthor); printf("\npublisher=%s\ncost=%d\t accession no=%d",p[i].bpub,p[i].bcost); } break; case 5: exit(0); } } getch(); }
Slip 20A. Write a function is Even, which accepts an integer as parameter and returns 1 if the number is even, and 0 otherwise. Use this function in main to accept n numbers and check if they are even or odd. #include<stdio.h> #include int iseven(int num); void main() { int num,ans; clrscr(); printf("\n enter the value of num"); scanf("\n %d",&num); ans=iseven(num); if(ans==1) { printf("\n number is even"); } if(ans==0) { printf("\n number is odd"); } getch(); } int iseven(int num1) { if(num1%2==0) { return 1; } else { return 0; } }
20B. Write a C program for multiplication of two matrices using dynamic memory
#include<stdio.h> #include #include void main() { int a[3][3],b[3][3],multi[3][3]; int i,j,k,row,col; clrscr(); printf("\n enter the value of row") scanf("\n %d",&row); printf("\n enter the value of col") scanf("\n %d",&col); a[i][j]=(int)calloc(n,sizeof(int)); printf("\n enter first matrix-"); for(i=0;i
allocation
multi[i][j]=multi[i][j]+(a[i][k]*b[k][j]); } } } printf("\n the matrix multiplication is-"); for(i=0;i<3;i++) { for(j=0;j<3;j++) { printf("\t %d",multi[i][j]); } printf("\n"); } getch(); }
Slip 21A. Write a C program to display multiplication table up to 10 number. #include <stdio.h> int main() { int n, i; printf("Enter an integer to find multiplication table: "); scanf("%d",&n); for(i=1;i<=10;++i) { printf("%d * %d = %d\n", n, i, n*i); } getch();; } /* iutput Enter an integer to find multiplication table: 5 5*1=5 5 * 2 = 10 5 * 3 = 15 5 * 4 = 20 5 * 5 = 25 5 * 6 = 30 5 * 7 = 35 5 * 8 = 40 5 * 9 = 45 5 * 10 = 50 */
21B. A scooter company has serial numbers from AA0 to FF9, the other characteristics of scooter are year of manufacture, colour, horsepower. Use a structure pointer and do the following: a. Retrieve all information of scooters within a range BB0 and CC9 b. Display the oldest scooter #include<stdio.h> #include void main() { struct scooter { char srno[5]; int year; char color[10]; int hp; }sc[10]; int i,ch,n; clrscr(); while(1) { printf("\n 1:add scooter info"); printf("\n 2:information of scooters within a range BB0 and CC9"); printf("\n 3:Display the oldest scooter"); printf("\n 4:exit"); printf("\n enter the choice"); scanf("\n %d",&ch); switch(ch) { case 1: printf("\n how many record u add"); scanf("\n %d",&n); for(i=0;i
for(i=0;i="bb0" || sc[i].srno<="cc9") { printf("\n srno is%s",sc[i].srno); printf("\n year is%d",sc[i].year); printf("\n color is%s",sc[i].color); printf("\n hp is%d",sc[i].hp); } } break; case 3:printf("\n the oldest scooter is %c",sc[0]); printf("\n srno is%s",sc[0].srno); printf("\n year is%d",sc[0].year); printf("\n color is%s",sc[0].color); printf("\n hp is%d",sc[0].hp); break; case 4:exit(0); } } getch(); }
Slip 22A. Write a program, which accepts a character from the user and checks if it is an alphabet, digit or punctuation symbol. If it is an alphabet, check if it is uppercase or lowercase and then change the case. #include<stdio.h> #include void main() { char ch; clrscr(); printf("\n enter the character"); scanf("\n %c",&ch); if(ch>=65 && ch<=90 || ch>=97 && ch<=122) { printf("\n the given character is alphabet"); if(ch>=65 && ch<=90) { printf("\n character is uppercase"); } else { printf("\n character is lowercase"); } } if(ch>=48 && ch<=57) { printf(" the given character is digit"); } if(ch>=58 && ch<=64 || ch>=91 && ch<=96) { printf("\n the given character is symbol"); } getch(); }
22B. Write a C program to calculate the sum of following series using function. Sum=1+1/x+1/x2+1/x3+1/x4+………*/ #include<stdio.h> #include #include<math.h> void series(int x); void main() { int x; clrscr(); printf("\n enter the value od x"); scanf("\n %d",&x); series(x); getch(); } void series(int x1) { int i,limit; float sum=0; printf("\n enter the limit"); scanf("\n %d",&limit); for(i=1;i<=limit;i++) { sum=sum+(1/(pow(x1 ,i))); } printf("\n sum of series is %f",(1+sum)); getch(); }
Slip 23A. program to covert temperature from Celsius to Fahrenheit. #include<stdio.h> #include void main() { float c,f; clrscr(); printf("\n enter the value of c"); scanf("\n %f",&c); f=(c*1.8)+32; printf("\n convert into fahrenfite %f ",f); getch(); }
23B. Write a C program to accept two strings str1 and str2 and compare them. if they are equal display their length. if str1 > str2 , convert str1 to uppercase and str2 to lowercase and display the strings and vice versa. #include<stdio.h> #include #include<string.h> #include<process.h> void main() { char str1[30],str2[30],copy[60]; int cmp,length,ch; clrscr(); printf("\n Enter a string1 :"); scanf("\n %s",&str1); printf("\n Enter a string2 :"); scanf("\n %s",&str2); cmp=strcmp(str1,str2); if(strcmp(str1,str2)==0) { length=strlen(str1); printf("\n string are equals and length is %d",length); } if(strcmp(str1,str2)>0) { printf("\n string1 is greater"); printf("\n string1 in uppercase is %s",strupr(str1)); printf("\n string2 in lowercase is %s",strlwr(str2)); } else { printf("\n string2 is greater"); printf("\n string2 in uppercase is %s",strupr(str2)); printf("\n string1 in lowercase is %s",strlwr(str1)); } getch(); }
Slip 24A. Program to swap two numbers using bitwise operator. #include<stdio.h> #include void main() { int a,b,t; clrscr(); printf("Enter the value of a="); scanf("%d",&a); printf("Enter the value of b="); scanf("%d",&b); a=a>>0; b=b<<0; t=a; a=b; b=t; printf("The swaped value of \n a=%d \n b=%d",a,b); getch(); }
24B. Write a C program to calculate sum of digits till it reduces to a single digit using recursion. #include<stdio.h> #include int recsum(int n); void main() { int n,ans; clrscr(); printf("\n enter the number"); scanf("\n %d",&n); ans= recsum(n); /* if(ans>9) { n=ans; ans=0; } */ printf("\n sum is%d",ans); getch(); } int recsum(int n1) { int rem,sum=0; if(n1==0) { return 0; } else { rem=n1%10; sum=rem+recsum(n1/10); } if(sum>9) { n1=sum; sum=recsum(n1); } return sum; }
Slip 25A. Write a C program to accept n different numbers and display sum of all +ve & -ve numbers.
#include<stdio.h> #include main() { int arr[10]; int i,n,psum=0,nsum=0; clrscr(); printf("\n enter how many number u want"); scanf("\n %d",&n); printf("Enter number="); for(i=0;i0) { psum= psum+arr[i]; } else { nsum= nsum+arr[i]; } } printf("\n the sum of positive number is is=%d",psum); printf("\n the sum of negative number is is=%d",nsum); getch(); }
25B. Write a menu driven program in C to create a structure employee having fields empid , empname,salary. Accept the details of n Employees from user and perform the following operations using function - Search by EmpId - Display Names of Employee having salary is greater than 10000 #include <stdio.h> #include void main() { struct details { char name[30]; int eid; int salary; }emp[5]; int n,i,id,ch; clrscr(); while(1) { printf("\n 1:add employee"); printf("\n 2:search employee"); printf("\n 3:Display Names of Employee having salary is greater than 10000 "); printf("\n 4:exit"); printf("\n enter the choice"); scanf("\n %d",&ch); switch(ch) { case 1: printf("\n enter how many record u add"); scanf("\n %d",&n); printf("\n enter employee record"); for(i=0;i
{ if(emp[i].eid==id) { printf("\n employee id is %d",emp[i].eid); printf("\n employee name is %s",emp[i].name); printf("\n employee salary is %d",emp[i].salary); } } break; case 3: for(i=0;i10000) { printf("\n Name of the Employee : %s ",emp[i].name); printf("\n id of the Employee : %d ",emp[i].eid); printf("\n Salary of the Employee : %d ",emp[i].salary); } } break; case 4:exit(0); } } getch(); }
Slip 26A. Write a program, which accepts a number n and displays each digit in words. Example: 6702 Output = Six-Seven-Zero-Two. #include<stdio.h> #include main() { int num,rem=0,digit; clrscr(); printf("Enter number="); scanf("%d",&num); while(num>0) { rem=rem*10+num%10; num=num/10; } while(rem>0) { digit=rem%10; //rem=rem/10; switch(digit) { case 1:printf(" one"); break; case 2:printf(" two"); break; case 3:printf(" three"); break; case 4:printf(" four"); break; case 5:printf(" five"); break; case 6:printf(" six"); break; case 7:printf(" seven"); break; case 8:printf(" eight"); break; case 9:printf(" nine"); } } getch(); return(0); }
26B. Write a C program to display transpose of matrix using user defined function. #include<stdio.h> #include void transpose(int a[3][3],int n); void main() { int a[3][3],trans[3][3]; int i,j,n; clrscr(); printf("\n enter the limit"); scanf("\n %d",&n); printf("\n enter the array element-"); for(i=0;i
Slip 27A. C program to calculate sum of all even numbers in an array. #include<stdio.h> #include void main() { int a[5]; int i,sum=0; clrscr(); printf("\n enter the array element-"); for(i=0;i<5;i++) { scanf("\n %d",&a[i]); } for(i=0;i<5;i++) { if(a[i]%2==0) { sum=sum+a[i]; } } printf("\n the sum of even number is %d",sum); getch(); }
27B. Write a C program to create structure student having fields Rollno, Name. Accept the details of students from the user store it into the file and Calculate the size of File. #include<stdio.h> #include void main() { struct stud { int sno; float per; char name[20],add[20]; }s; int i,n; int size = 0; char ch; FILE *fp; fp=fopen("a.txt","w"); if(fp==NULL) { printf("\nUnable to open file!"); } else { printf("\nEnter the stud no:->"); scanf("%d",&s.sno); printf("\nEnter the stud name:->"); scanf("%s",s.name); fprintf(fp,"%d\n%s",s.sno,s.name); } fseek(fp, 0, 2); /* file pointer at the end of file */ size = ftell(fp); /* take a position of file pointer un size variable */ printf("The size of given file is : %d\n", size); fclose(fp); getch(); }
Slip 28A. Write a C program to accept string from user and display alternate character of
string in upper case .(eg: I/P hello O/P hElLo) #include<stdio.h> #include void main() { char str[30]; int i; clrscr(); printf("\n enter the string"); gets(str); for(i = 0; str[i] != 0; i++) { if( (i % 2) == 0) str[i] = tolower(str[i]); else str[i] = toupper(str[i]); } printf("%s\n", str); getch(); }
28B. C program to accept n employee information(eno, enme, salary) and display the employee information having maximum salary. Use array of structure #include<stdio.h> #include void main() { struct employee { int eno; char ename[20]; int salary; }emp[3]; int i,j,max; clrscr(); printf("\n enter employee info"); for(i=0;i<2;i++) { printf("\n enter employeeno"); scanf("\n %d",&emp[i].eno); printf("\n enter name"); scanf("\n %s",&emp[i].ename); printf("\n enter employee salary"); scanf("\n %d",&emp[i].salary); } max=emp[0].salary; for(i=0;i<2;i++) { if(emp[i].salary>max) { max=emp[i].salary; } } printf("\n the employee who have maximum salary is"); printf("\n EMPNO NAME SALARY"); for(i=0;i<2;i++) { if(emp[i].salary==max) { printf("\n %d\t %s\t %d",emp[i].eno,emp[i].ename,emp[i].salary); } getch
Slip 29A. Write a C program to check whether a given number is palindrome or not. #include<stdio.h> #include void main() { int num,rem,sum=0,temp; clrscr(); printf("\n enter the value of num"); scanf("\n %d",&num); temp=num; while(num>0) { rem=num%10; sum=rem+(sum*10); num=num/10; } if(temp==sum) { printf("\n number is palindrome"); } else { printf("\n number is not palindrome"); } getch(); }
29B. Write a C program to accept three integers as command line arguments and find the minimum, maximum and average of the three numbers. Display error message if the number of arguments entered are invalid #include<stdio.h> #include void main(int argc , char * argv[]) { int i,sum=0; float avg; int max; int min; clrscr(); if(argc!=4) { printf("you have forgot to type numbers."); exit(1); } for(i=1;i<argc;i++) { sum = sum + atoi(argv[i]); avg=sum/3; } printf("the average is%f",avg); //for max max=argv[1]; min=argv[1]; for(i=1;i<argc;i++) { if(atoi(argv[i])>max) { max=atoi(argv[i]); } } if(atoi(argv[i])<min) { min=atoi(argv[i]); } printf("\n the maximum number is %d",max); printf("\n the minimum number is %d",min); getch() }
Slip 30A. program to check whether given number is Palindrome or not. #include<stdio.h> #include void main() { int num,rem,sum=0,temp; clrscr(); printf("\n enter the value of num"); scanf("\n %d",&num); temp=num; while(num>0) { rem=num%10; sum=rem+(sum*10); num=num/10; } if(temp==sum) { printf("\n number is palindrome"); } else { printf("\n number is not palindrome"); } getch(); } /*output enter the value of num121 number is palindrome */
30B. Write menu driven program to convert decimal number in to binary, octal and hexadecimal.Write separate user defined function for each option. #include<stdio.h> #include #include<math.h> int D2B(int); int D2O(int); int D2H(int); main() { int ch,num; clrscr(); while(1) { printf("\n1.Decimal 2 Binary."); printf("\n2.Decimal 2 Octal."); printf("\n3.Decimal 2 Hexa."); printf("\n4.Exit."); printf("\nEnter your Choice:"); scanf("%d",&ch); switch(ch) { case 1: clrscr(); printf("\nEnter any Decimal number:"); scanf("%d",&num); D2B(num); //calling functione break; case 2: clrscr(); printf("\nEnter any Decimal number:"); scanf("%d",&num); D2O(num); //calling function break; case 3: clrscr(); printf("\nEnter any Decimal number:"); scanf("%d",&num); D2H(num); //calling function break; case 4: exit(0);
} } getch(); } int D2B(int dec) //decimal to binary { int bin=0,*bin_arr,count=0; while(dec>0) { bin=dec%2; dec/=2; *(bin_arr+count)=bin; count++; } printf("\nBINARY="); while(count > 0) { --count; printf("%d",*(bin_arr+count)); } return 0; } int D2O(int dec) //decimal to octal { int oct=0,*oct_arr,count=0; while(dec>0) { oct=dec%8; dec/=8; *(oct_arr+count)=oct; count++; } printf("\nOCTAL="); while(count > 0) { --count; printf("%d",*(oct_arr+count)); } return 0; } int D2H(int dec) //decimal to hexa {
int hexa=0,*hexa_arr,count=0; while(dec>0) { hexa=dec%16; dec/=16; *(hexa_arr+count)=hexa; count++; } printf("\nHEXA="); while(count > 0) { --count; switch(*(hexa_arr+count)) { case 10: printf("A"); break; case 11: printf("B"); break; case 12: printf("C"); break; case 13: printf("D"); break; case 14: printf("E");break; case 15: printf("F");break; default: printf("%d",*(hexa_arr+count)); break; } } }