warfareknow
BANNED
- Joined
- Apr 4, 2015
- Messages
- 463
- Reaction score
- -6
- Country
- Location
Hi guys, I am right now a cs stud and I am behind everybody else since I have literally 0 experience with coding.
I have a homework I have to finish till 23:59 o'clock today and send it to my tutor at the uni.
One of the tasks was that I should program something that calculates the sum and sqaure sum of 1-n
I was able to do it this way:
Now the next task is to write a program that will tell you if your positive number (n) is a prime number or not.
I know i have to use somehow "for" but i failed several times and i dont know how to use it and whats its purpose, other studs say we have to use modulo rest? . Oh also my program should give an error if number that is entered is negative, i did master this part.
this is my unfinished code:
If you could help me I would be very grateful.
I have a homework I have to finish till 23:59 o'clock today and send it to my tutor at the uni.
One of the tasks was that I should program something that calculates the sum and sqaure sum of 1-n
I was able to do it this way:
Code:
//ADIP Aufgabe 2: Die Summe und Quadratsumme von 1 bis n.
#include <stdio.h>
int main()
{
int n;
printf("\nIch berechne Dir die Summe und Quadratsumme von 1 bis n :)\n");
printf("\nBitte eine positive, ganze Zahl eingeben:\n");
scanf("%d", &n);
if (n>0){
printf("\nKorrekte Eingabe.\n");
}else if(n<1){printf("\nFalsche Eingabe. Bitte neustarten :(.\b");
return 0;
}
printf("\nDie Summe lautet: %d\n", ((n+1)*n)/2);
printf("\nDie Quadratsumme lautet %d\n", (n*(n+1)*(2*n+1))/6);
return 0;
}
Now the next task is to write a program that will tell you if your positive number (n) is a prime number or not.
I know i have to use somehow "for" but i failed several times and i dont know how to use it and whats its purpose, other studs say we have to use modulo rest? . Oh also my program should give an error if number that is entered is negative, i did master this part.
this is my unfinished code:
Code:
#include <stdio.h>
int main()
{
int input, i,;
printf("\n\=== Aufgabe 3 ===\n"); //Task 3
printf("\nBitte eine positive, ganze Zahl eingeben :"); //Please enter a positive and integer number
scanf("%i", &input);
if(input<0){
printf("\nAchtung: Die eingegebene Zahl '%i' war negativ!\n", input); //Warning: Number entered was negative.
return 0;
}
}
If you could help me I would be very grateful.
Last edited: