Professional Documents
Culture Documents
#include <stdio.h>
struct weight{
int grams;
int kg;
}w1, w2, hanum;
int main() {
scanf("%d", &w1.kg);
scanf("%d", &w1.gram);
scanf("%d", &w2.kg);
scanf("%d", &w2.gram);
if (wl-grams > w2.grams && w1.kg>w2.kg) {
hanum.grams = wl.grams - w2.grams;
hanum.kg = w1.kg - w2.kg;
else {
hanum.grams = w2.grams - w1.grams;
hanum.kg - w2.kg - w1.kg;
}
printf ("%d grams \n %d kg", hanum.grams, hanum.kg);
return 0;
};
-----------------------------------------------------------------------------------
-
#include <stdio.h>
struct weight{
int grams;
int kilograms;
}w1, w2, sum;
int (main){
return 0;
}
----------------------
tarberak 2
#include <stdio.h>
#include <stdlib.h>
struct weight{
int grams;
int kilograms;
}w1, w2, difference;
int main(){
printf("Enter the kilograms ");
scanf("%d"‚&w1.kilograms);
printf("Enter thr grams ");
scanf("%d",&wl.grams);
difference.grams=w1. grams-w2.grams;
difference.kilograms=w1.kilograms-w2.kilograms;
while(difference.grams<0){
difference.kilograms=difference.kilograms-1;
difference.grams=1000-(w2.grams-wl.grams);
}
printf("the answer is %d and %d" ,difference.kilograms, difference.grams);
return 0;
----------------------------------------------------------------------
#include <stdio.h>
#include <stdlib.h>
int main(){
int n;
printf("Enter n: ");
scanf("%d", &n);
printf("%d" , F(n) );
return 0;
}
-----------------------------------------------------------------------------------
---
#include <stdlib.h>
#include <stdio.h>
int main() {
int arr[8]= {1, 2, 3, 4, 5, 6, 7};
FILE*fptr;
fptr = fopen("array.txt", "w")
int i;
for(i=0; i<7; i++){
fprintf(fptr, "%d," ,arr[i]);
}
fclose(fptr);
return 0;
}
-----------------------------------------------------------------------------------
---
5.
#include <stdlib.h>
#include <stdio.h>
int main() {
int n;
printf("Enter n:");
scanf("%d", &n);
int i=2;
int f=1;
while(i<=n){
f *=(i+8);
i++;
}
printf("%d", f);
return 0;
}
-----------------------------------------------------------------------------------
-----
#include <stdlib.h>
#include <stdio.h>
void circle_length(int*a);
int main() {
int r = 3;
circle_length(&r);
return 0;
}
-----------------------------------------------------------------------------------
-
7.You have 2D array. Please write program for finding row's number with maximal
average of
elements.
#include <stdio.h>
#include <stdlib.h>
int main(){
int arr[10][10];
int r, c;
int i , j;
for(i = 0; i<r; i++){
for(j = 0; j<c; j++){
printf("enter a number: ");
scanf("%d", &arr[i][j]);
}
}
return 0;
}
-----------------------------------------------------------------------------------
-
8. You have 2D array. Please write program for finding colums's number with maximal
average of
elements.
#include <stdio.h>
#include <stdlib.h>
int main(){
int arr[10][10];
int r, c;
int i , j;
for(i = 0; i<r; i++){
for(j = 0; j<c; j++){
printf("enter a number: ");
scanf("%d", &arr[i][j]);
}
}
return 0;
}
--------------------------------------------------------------------------------
9. User enters the x end n= 1,3 which is number of action using switchconsturction
calculate
#include <stdio.h>
int main(){
int x, n;
printf("Enter x);
scanf ("%d", &x);
printf("Enter n (1, 2, 3): ");
scanf("%d", &n);
switch (n){
case 1;
printf("%d", (-5*x*x-4));
break;
case 2:
printf("%d", (8*x+2));
break;
case 3:
printf("%d", (15-3*x));
break;
default:
printf("n is not correct);
}
return 0;
----------------------------------------------------------------------------------
10.Using dynamic memory allocation create arry of students structure. array size is
5.
#include <stdio.h>
#include <stdlib.h>
int main(){
struct Students *ptr;
ptr = (struct Students*) malloc(5 sizeof (struct Students));
if(ptr == NULL){
exit(1);
}
int i, j;
for(i = 0; i<5; i++){
printf("Enter first name and last name, age, midterm exam grade and final exam
grade;");
scanf("%s %s %d %d %d", (ptr +i)->firstName, (ptr+i)->lastName, &(ptr+i)-
>age,&(ptr+i)->midtermExamGrade, &(ptr+i)->finalExamGrade);
}
return 0;
};
-----------------------------------------------------------------------------------
---