Commit 04f78ce1 by tekalj

lab4

parent 372958ac
File added
/*
#include <stdio.h>
/*
int main() {
int i;
int j;
for (i = 0; i < 3; i++) {
printf("%d\n", i);
//perform the following FOR EACH loop
for (j = 0; j < 9; j++) {
//perform the following FOR EACH loop
printf (">>%d\n", j);
}
}
return 0;
}
*/
/*
int main(){
int array[3][5] = {
{4, 2, 4, 2, -1},
{-3, 55, 1, 223, 2},
{2, 4, 5, 2, 1,}
};
for(int i = 0; i < 3; i++){
for(int j = 0; j < 5; j++){
printf("%d, ", array[i][j]);
}
printf("\n");
}
return 0;
}
*/
/*
#include <stdlib.h>
int main (){
int array[3][5];
for(int i = 0; i < 3; i++){
for(int j = 0; j < 5; j++){
array[i][j] = rand() % 500 ;
}
}
for(int i = 0; i < 3; i++){
for(int j = 0; j < 5; j++){
printf("%d,", array[i][j]);
}
printf("\n");
}
return 0;
}
*/
/*
#include <string.h>
int main(){
char array[40] = "this is a string";
int breakPoint;
printf("|");
for(int i = 0; i < 40; i++){
printf("%c", array[i]);
}
printf("|\n|");
printf("%s", array);
printf("|");
return 0;
}
*/
/*
#include <string.h>
int main(){
char string1[40] = "this is a string";
char string2[] = "so is this";
int lenght = strlen(string1);
printf("%d", lenght);
strcat(string1, string2);
printf("%s", string1);
return 0;
}
*/
/*
#include <stdio.h>
#include <string.h>
int main(){
float orthogonalMatrix[6][6];
float initialVector[6] = {0.3, 0.4, -2, -4.4, 2.2, 3};
memcpy(orthogonalMatrix[0], initialVector, 6*sizeof(float));
float sumOfSquares;
for(int i = 1; i < 6; i++){
sumOfSquares = 0;
if(initialVector[i]==0){
orthogonalMatrix[i] [i - 1]= 1;
}
for(int j = i ;j < 6; j++){
sumOfSquares += initialVector[j]*initialVector[j];
}
if(sumOfSquares == 0){
for(int j = i; j < 6; j++){
orthogonalMatrix[j][j] = 1;
}
}
initialVector[i - 1] = -1*sumOfSquares/initialVector[i - 1];
memcpy(orthogonalMatrix[i], initialVector, 6*sizeof(float));
initialVector[i - 1] = 0;
}
for(int i = 0; i < 6; i++){
for(int j = 0; j < 6; j++){
printf("%f,", orthogonalMatrix[i][j]);
}
printf("\n");
}
return 0;
}
*/
#include <stdio.h>
int main(){
int mat[3][3];
printf("Enter your matrix\n");
for(int i = 0; i < 3; i++){
for(int j = 0; j < 3; j++){
scanf("%d", &mat[i][j]);
}
}
for(int i = 0; i < 3; i++){
for(int j = 0; j < 3; j++){
printf("%d, ", mat[i][j]);
}
printf("\n");
}
int mat2[3][3];
printf("Enter 2nd matrix\n");
for(int i = 0; i < 3; i++){
for(int j = 0; j < 3; j++){
scanf("%d", &mat2[i][j]);
}
}
for(int i = 0; i < 3; i++){
for(int j = 0; j < 3; j++){
printf("%d, ", mat2[i][j]);
}
printf("\n");
}
int sum[3][3];
printf("Sum of matrices\n");
for(int i = 0; i < 3; i++){
for(int j = 0; j < 3; j++){
sum[i][j] = mat[i][j] + mat2[i][j];
printf("%d\t", sum[i][j]);
}
printf("\n");
}
printf("Difference of matrices\n");
for(int i = 0; i < 3; i++){
for(int j = 0; j < 3; j++){
printf("%d\t", mat[i][j] - mat2[i][j]);
}
printf("\n");
}
return 0;
}
File added
File added
#include <stdio.h>
/*
int main () {
int score = 20;
int passingScore = 35;
if(score < passingScore) {
printf("you didn't pass");
}else if (score == passingScore) {
printf("please beg the professor for mercy");
}else{
printf("you passed! go home");
}
return 0;
}
*/
/*
int main (){
int i = 0;
int x = 2;
while(i < 10) {
x += i;
x = x + i;
printf("%d %d\n", x, i);
i += 1 ;
}
return 0;
}
*/
/*
int main () {
int x;
char c;
float y;
scanf("%d", &x);
scanf("%c", &c);
scanf("%f", &y);
printf("%d, %c, %f", x, c, y);
return 0;
}
*/
/* //task 1
int main() {
int array[10];
int i ;
for ( i=0; i<10; i++){
array[i]= i+1;
printf("%d\n", array[i]);
}
for( i=0; i<10; i++) {
if (array[i]%2 == 0)
printf("%d\n", array[i]);
}
for( i=0; i<10; i+=2){
if (array[i]% 2 == 1)
printf("%d\n", array[i]);
}
for( i=9; i>-1; i--) {
printf("%d\n", array[i]);
}
return 0;
}
*/
int main(){
int x;
scanf("%d", &x);
int array[x];
int i, t1 = 0, t2 = 1, nextTerm;
for(i = 0; i < x; i++)
{
array[i]= t1;
nextTerm = t1 + t2;
t1 = t2;
t2 = nextTerm;
printf("%d\n", array[i]);
}
printf("\n");
for( i=0; i<x; i++) {
if (array[i]%2 == 0)
printf("%d\n", array[i]);
}
return 0;
}
File added
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment