Showing posts with label bca assignment. Show all posts
Showing posts with label bca assignment. Show all posts

9.27.2011

search prime number

Q. Write a C program to find whether a number is prime or not.
Definition of prime number:A prime number is one,which is divisible only by one or itself. And its must greater than 1.
And if number is not prime, it is called composite number and vice versa.

Ans.

#include<stdio.h>
#include<stdio.h>
int main()
{
 int x,num;
 printf("Enter number : ");
 scanf("%d",&num);
 x=2;
 while(x<=num-1)
 {
   if(num%x==0)
   {
      printf("Number is not prime!!");
      break;
   }
   x++;
 }
 if(x==num)
    printf("Number is prime!!");
 getch();
 return 0;
}

    output of above program :

Enter number : 7
Number is prime!!


Related Programs:

  1. Generate first n Prime number C program
  2. Print Prime Number 1 to 100 C program
  3. Flowchart for search prime number

9.12.2011

Example of Array

Q. Write a C program to read the internal test marks of 25 students in a class and show the number of students who have scored more than 50% in the test.

Ans.
/*We assume that maximum marks in internal test is 500. */
#include<stdio.h>
#include<conio.h>
#define SIZE 5
int main()
{
 int arr[SIZE];
 int i,j,max=0,min=0;
 for(i=1; i<=SIZE; i++)
 {
   printf("Enter %d student marks : ",i);
   scanf("%d",&arr[i]);
 }
 for(i=1; i<=SIZE; i++)
 {
  if(arr[i]/5 > 50)
  {
    max++;
    printf("\nMarks which scored more than 50%% is %d",arr[i]);
  }
  else
  {
    min++;
    printf("\nMarks which scored less than 50%% is %d",arr[i]);
  }
 } 
 printf("\n");
 printf("\nTotal number of students who scored more  than 50%% = %d",max);
 printf("\nTotal number of students who scored less than 50%% = %d",min);
 getch();
 return 0;
}


      Output of the above program :
Enter 1 student marks : 450
Enter 2 student marks : 152
Enter 3 student marks : 266
Enter 4 student marks : 65
Enter 5 student marks : 123

Marks which scored more than 50% is 450
Marks which scored less than 50% is 152
Marks which scored more than 50% is 266
Marks which scored less than 50% is 65
Marks which scored less than 50% is 123

Total number of students who scored more than 50% =  2 
Total number of students who scored less than 50% =  3 

9.05.2011

Star (*) Praymid

Q. Write a C program to print the following triangle:







*








* * *






* * * * *




* * * * * * *


* * * * * * * * *
* * * * * * * * * * *




Ans.

 /*c program for star pyramid*/
 #include<stdio.h>
 #include<conio.h>

 int main()
 {
  int num=6,r,c,sp;

  for(r=1; num>=r; r++)
  {
   for(sp=num-r; sp>=1; sp--)
       printf(" ");
   for(c=r; c>=1; c--)
        printf("*");
   for(c=r; c>1; c--)
        printf("*");
   printf("\n");
  }

  getch();
  return 0; 
 }


/***************OUTPUT***************








*








***






*****




*******


*********
***********



***************************************/