Ghislain_Mike

quiz

Feb 15th, 2019
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.45 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.     sum = sum + num;
  22.  
  23.     printf("The sum = %d", sum);
  24.  
  25.     return 0;
  26. }
Advertisement
Add Comment
Please, Sign In to add comment