Explore Ebooks
Categories
Explore Audiobooks
Categories
Explore Magazines
Categories
Explore Documents
Categories
(Basics) 1. WAP to print text on the screen. 2. WAP to check if number is odd or even. 3. WAP to check which of the two entered numbers is greater. 4. WAP to check whether entered number is a leap year or not. 5. WAP to convert temperature in Fahrenheit to Celsius. (Looping) 6. WAP to display the multiplication table of entered number. 7. WAP to check if number is Palindrome or not. 8. WAP to check if number is an Angstrom number or not. 9. WAP to check if number is a prime or not. 10. WAP to find the sum of Fibonacci series. (Arrays) 11. WAP to find the sum and average of 10 numbers using arrays. 12. WAP to add elements of two 3x3 matrices. (Pointers & Functions) 13. WAP to understand pointers. 14. WAP to swap two numbers. 15. WAP to Swap two numbers using pointers (and functions). 16. WAP to find the factorial of a number using recursive function. (Structures) 17. WAP using structures to input and display details of student. (Strings) 18. WAP to enter two strings and get them to display. (Data File Handling) 19. WAP to enter and retrieve a character from a file. 20. WAP to copy the contents of one file to another.
3 4 5 6 7
8 9 10 11 12
13 14
16 17 18 19
20
21
22 23
1 2 3 4 5 6 7
#include<stdio.h> int main() { printf(" Welcome to Neil's Practical File. XD "); return 0; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
#include<stdio.h> int main() { int num; printf(" Enter the number: "); scanf(" %d ", &num); if(num%2==0) printf("\n Number is Even. "); else printf("\n Number is Odd. "); return 0; }
OUTPUT:
Enter the number: 5 Number is Odd. Enter the number: 8 Number is Even.
OUTPUT: Enter two Numbers: 5 357 Greater number of the two is : 357
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
#include <stdio.h> main() { int Y; printf("Enter any year: "); scanf("%d", &Y); if((Y%4==0)) printf("\nThe entered year is a Leap Year."); else printf("\nThe entered year is not a Leap Year."); return 0; }
OUTPUT: Enter any year: 1991 The entered year is not a Leap Year. Enter any year: 1994 The entered year is a Leap Year.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
#include<stdio.h> int main() { int i,n,a; printf("\nEnter the number whose table is to be printed : "); scanf("%d",&n); for(i=1;i<11;i++) { a=n*i; printf("%dx%i=%d \n",n,i,a); } return 0; }
OUTPUT:
Enter the number whose table is to be printed : 5 5x1=5 5x2=10 5x3=15 5x4=20 5x5=25 5x6=30 5x7=35 5x8=40 5x9=45 5x10=50
printf(" Enter the number to check if it's Palindrome or not: "); scanf("%d", &num); n=num; do { digit=n%10; rev=(rev*10)+digit; n=n/10; } while(n>0); if(rev==num) { printf("\n The number is a palindrome. "); } else { printf("\n The number is not a palindrome. "); } }
OUTPUT: Enter the number to check if it's Palindrome or not: 121 The number is a palindrome. Enter the number to check if it's Palindrome or not: 153 The number is not a palindrome.
OUTPUT: Enter the number to check if it's Angstrom or not: 121 The number is not an Angstrom number. Enter the number to check if it's Angstrom or not: 153 The number is an Angstrom number.
10
OUTPUT: Enter the number to check whether prime or not: 1 The number is not prime. Enter the number to check whether prime or not: 5 The number is prime. Enter the number to check whether prime or not: 12 The number is not prime.
11
OUTPUT: Till which term should the Fibonacci series be found: 8 The Fibonacci Series: 0 + 1 + 1 + 2 + 3 + 5 + 8 + 13 Sum = 33
12
Write a Program to find the sum and average of 10 numbers using arrays.
SOURCE CODE:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 #include <stdio.h> int main() { //INITIAL DECLARATIONS int x[10]; int sum=0; float avg; int i;
//INPUT printf("\n Enter the 10 numbers: \n "); for(i=0; i<10; i++) { scanf(" %d ", &x[i]); // *Note the & for array element } //CALCULATIONS for(i=0; i<10; i++) { sum+=x[i]; } avg=sum/10.0; //OUTPUT printf("\n The Sum of the numbers: %d ",sum); printf("\n The Average of the numbers: %f \n",avg); return 0; }
OUTPUT: Enter the 10 numbers: 1 2 3 4 5 6 7 8 9 10 The Sum of the numbers: 55 The Average of the numbers: 5.500000
13
14
OUTPUT: Enter the elements of matrix A: 1 2 3 1 2 3 3 2 1 Enter the elements of matrix B: 3 2 1 3 2 1 1 2 3 Adding matrices A and B = matrix C Matrix C is: 4 4 4 4 4 4 4 4 4
15
OUTPUT: Enter an integer: 7 Address of a: 3219592736 Address of p: 3219592732 Value of p: -1075374560 Value of a: 7 Value of a: 7
16
main() { printf("\n Enter Names, Marks & Age of the students: \n"); scanf("%s %f %d",&b1.name,&b1.marks,&b1.age); scanf("%s %f %d",&b2.name,&b2.marks,&b2.age); printf("\n This is what you have entered: \n"); printf("\n %s %f %d ",b1.name,b1.marks,b1.age); printf("\n %s %f %d ",b2.name,b2.marks,b2.age); }
OUTPUT: Enter Names, Marks & Age of the students: Neil 94 18 Bugger 0 100 This is what you have entered: Neil 94.000000 18 Bugger 0.000000 100
17
18
19
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
#include<stdio.h> int fact(int f) { if( f==1 || f==0) { return 1; } else { f=f*fact(f-1); return f; } }
main() { int num; int factorial; printf(" Enter the number whose factorial needs to be found: "); scanf(" %d ", &num); factorial=fact(num); printf("\n The factorial of %d is %d. ",num,factorial); }
OUTPUT:
Enter the number whose factorial needs to be found: 4 The factorial of 4 is 24.
20
OUTPUT: Enter the first string: Hello Enter the second string: World The Strings are: 1st: Hello 2nd: World Enter the first string: New York Enter the second string: The Strings are: 1st: New 2nd: York
21
Write a Program to enter and retrieve a character from a file using DATA FILE HANDLING.
SOURCE CODE:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 #include <stdio.h> main() { char ch; FILE *file; file = fopen("abc.txt", "w"); printf("\nEnter any character into FILE: "); scanf("%c", &ch); putc(ch, file); fclose(file); file = fopen("abc.txt", "r"); ch = getc(file); printf("\nEntered Character from FILE: %c", ch); }
OUTPUT:
22
Write a program to copy the contents of one file to another using DATA FILE HANDLING.
SOURCE CODE:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 #include <stdio.h> main() { char ch; FILE *fp1, *fp2; fp1 = fopen("abc.txt", "r"); fp2 = fopen("xyz.txt", "w"); while((ch = getc(fp1)) != EOF) putc(ch, fp2); fclose(fp1); fclose(fp2); return 0; }
OUTPUT: (none)
23