Write a function that takes a string from the user, if the length of the string is 7 then it displays the middle character of that string, and the function returns, otherwise the user is asked to input another string. [BIM 2014]
#include<stdio.h>
#include<string.h>
int main()
{
char a[30];char b;int i;
start:printf(“enter a string of 7 character “);
scanf(“%s”,a);
if(strlen(a)!=7)
goto start;
else
printf(“the mid char is %c”,a[3]);
return 0;
}

Write a program that stores information of students in a file new record of students can be added without affected existing records of students. Students have name, age and address as attributes. [BIM 2014]

#include <stdio.h>
struct student{
char name[20],address[30];
int age;
}p;
int main()
{
FILE *A;
printf(“enter a std name,address and age for 10 std; “);
scanf(“%s%s%d%d”,p.name,p.address,&p.age);
A= fopen(“a.txt”,”a+”);
fprintf(A,”\n\n%s\n%s\n%d\n%d”,p.name,p.address,p.age);
fclose(A);
return 0;
}

Write a program which display sum of all elements of two different 3-D integer arrays. [BIM 2014]

#include<stdio.h>
#include<conio.h>

www.spastakhabar.com

void main()
{
int a[2][2][2],b[2][2][2];
int i,j,k,sum1=0 ,sum2=0;
clrscr();
printf(“enter the element in frst array”);
for (i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
for(k=0;k<2;k++)
{
scanf(“%d”,&a[i][j][k]);
sum1+=a[i][j][k];
}
}
}
printf(“enter the element in seecond array”);
for (i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
for(k=0;k<2;k++)
{
scanf(“%d”,&b[i][j][k]);
sum2+=a[i][j][k];
}
}
}
printf(“the sum of all element is %d”,sum1+sum2);
getch();
}

Write a function that takes list of integers of size ten as parameter and displays all the prime numbers of the list. [BIM 2015]

#include <stdio.h>
int main()
{
int n[10], i,j, flag = 0;

printf(“Enter 10 positive integer: “);
for (i=0;i<10;i++)
scanf(“%d”,&n[i]);
printf(“All the prime numbers in the array are -“);
for (i=0;i<10;i++)
{ flag=0;
for(j=2; j<=n[i]/2; j++)
{
if(n[i]%j==0)
{
flag=1;
break;
}
}
if (flag==0)
printf(“%4d “,n[i]);
}

return 0;
}

Write a program to read a line of text and display number of vowels in it. [BIM 2015]

#include <stdio.h>
int main()
{
char line[150];
int i, vowels;

printf(“Enter a line of string: “);
scanf(“%[^\n]”, line);

for(i=0; line[i]!=’\0′; ++i)
{
if(line[i]==’a’ || line[i]==’e’ || line[i]==’i’ ||
line[i]==’o’ || line[i]==’u’ || line[i]==’A’ ||
line[i]==’E’ || line[i]==’I’ || line[i]==’O’ ||
line[i]==’U’)
{
++vowels;
}
}
printf(“Vowels: %d”,vowels);
return 0;
}

Write a program that prints three different texts in three different lines. [BIM 2015]

#include<stdio.h>
int main()
{
char a[3][30];int i;
printf(“enter 3 text :”);
for (i=0;i<3;i++)
scanf(“%s”,&a[i]);
for (i=0;i<3;i++)
printf(“%s\n”,a[i]);
return 0;
}

Leave a Reply

Your email address will not be published. Required fields are marked *