Advertisement
QUIZERA

quiz for prime number and sum of entered number

Feb 15th, 2019
414
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.43 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int main() {
  5.     int num,i,j,c, sum = 0;
  6.  
  7.     printf("please enter the number = ");
  8.     scanf("%d",&num);
  9.  
  10.     for (j=1;j<=num;j++){
  11.         for (i=1,c=0;i<=j;i++){
  12.             if (j%i==0){
  13.                 c++;
  14.             }
  15.         }
  16.         if (c==2){
  17.              printf("%d\n",j);
  18.              sum = sum + j;
  19.         }
  20.     }
  21.  
  22.     printf("The sum = %d", sum);
  23.  
  24.     return 0;
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement