Year 2015
Q.No. 2 Write function that takes list of integers of size 10 as parameter and display all the prime numbers of the list.
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 35 36 37 |
#include<stdio.h> void chk(int a[]) { printf("Prime numbers:\n"); int c; for(int i=0;i<10;i++) { c=0; for(int j=2;j=a[i]/2;j++) { if(a[i]%j==0) { c=1; break; } } if(c==0) printf("%d\n",a[i]); } } void main() { int a[10]; printf("Enter 10 numbers: "); for(int i=0;i,<10;i++) scanf("%d",a[i]); chk(a); } Output: Enter 10 numbers: 5 6 7 8 9 10 11 1 2 3 Prime numbers: 5 7 11 1 2 3<input id="2029.6740362804351" class="cdbx-try-code cdbx-btn-main" style="background-color: #ffffff; margin-bottom: 0; color: #008b8b; border: 1px solid rgba(231, 231, 230, 1); border-radius: 10px; font-size: 13px; height: 30px; min-width: 60px; max-width: 150px; padding: 4px; font-weight: normal; outline: none; display: none; float: right;" type="button" value="Run" data-code="1534082630476.9202" data-highlight="" data-lang="0" data-filename="Filename" /> |
Q.no 3 Write a program that displays the line “Best of Luck” 5 times, using a function.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
#include<stdio.h> void dis() { for(int i=0;i<5;i++) printf("Best of Luck\n"); } void main() { dis(); } Output: Best of Luck Best of Luck Best of Luck Best of Luck Best of Luck |
Q.No. 5 Write a program to read a line of text, and display the number of vowels in it.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
#include<stdio.h> #include<string.h> void main() { char a[50]; int i=0,c=0; printf("Enter line:\n"); gets(a); strlwr(a); while(a[i]!='\0') { if(a[i]=='a'||a[i]=='e'||a[i]=='i'||a[i]=='o'||a[i]=='u') c++; i++; } printf("Number of vowels in the user given string is: %d.",c); } Output: Enter line: AEIOU Number of vowels in the user given string is: 5. |
Q.No. 6 Write a program that prints three different strings in three different lines.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
#include<stdio.h> void main() { char a[3][30];int i; printf("Enter 3 texts:\n"); for(i=0;i<3;i++) gets(a[i]); for (i=0;i<3;i++) printf("%s\n",a[i]); } Output: Enter 3 texts: Hello How Are you? Hello How Are you?<input id="4990.2283172804351" class="cdbx-try-code cdbx-btn-main" style="background-color: #ffffff; margin-bottom: 0; color: #008b8b; border: 1px solid rgba(231, 231, 230, 1); border-radius: 10px; font-size: 13px; height: 30px; min-width: 60px; max-width: 150px; padding: 4px; font-weight: normal; outline: none; display: none; float: right;" type="button" value="Run" data-code="1534082713822.0994" data-highlight="" data-lang="0" data-filename="Filename" /> |
Q.No. 7
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
#include<stdio.h> #include<conio.h> void main(){ FILE * fp; char ch; char name[100]; fp = fopen("a.txt","a"); printf("y/n"); scanf("%c", &ch); printf("%c", ch); while(ch == 'y'){ printf("Enter name"); scanf("%s", name); printf("%s", name); if(name[0] == 'a') fprintf(fp,"%s\n", name); printf("add y/n"); ch = getche(); } fclose(fp); getch(); } |
Q.No. 8
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
#include<stdio.h> #include<conio.h> void main(){ int i,j,k,l; for(i = 1; i<=4;i++){ for(k=4;k>=i;k--){ printf(" "); } for(j = i; j>=1;j--){ printf("%d", j); } j = 1; for(l = j+1; l<=i;l++) { printf("%d", l); } printf("\n"); } getch(); } |
Q.No. 9
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
#include<stdio.h> #include<conio.h> struct employee{ char name[100]; int age; }; void main(){ int i, age = 0, averageAge; struct employee e[5]; for(i = 0; i < 5; i++){ printf("Enter name of employee %d: ", (i+1)); scanf("%s", e[i].name); printf("Enter age of employee %d: ", (i+1)); scanf("%d", &e[i].age); } for(i = 0; i < 5; i++){ age = age + e[i].age; } averageAge = age/5; printf("\nThe average age of the employees is %d", averageAge); getch(); } |