

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!


Name (printed):
Student ID #:
Section # (or TA’s: name and time)
#include <stdio.h>
void writechars(char c, int i){ int cnt; if (i > 0){ for(cnt = 0; cnt < i; cnt++){ printf("%c", c); } printf("\n"); } return; }
int main(){ writechars(’a’,4); //output would be aaaa writechars(’b’,3); //output would be bbb writechars(’x’,6); //output would be xxxxxx return 0; }
It is called like this: int retvalue; retvalue = getOneDigit();
It looks like this when run: Give a single integer: 12 Error - Give a single integer: - Error - Give a single integer: - Error - Give a single Integer: 4
int getVal(){ int i; do{ printf("Give a single Intgeer:"); scanf("%d", &i); if(i > 9 || i < 1){ printf("Error - "); } }while(i > 9 || i < 1); return i; }
#include <stdio.h> void f1(int a, int b){ int x = 99; a = x - b++; printf("f1: %d, %d, %d\n",a,b,x); return; } int f2(){ int x = 5, y = 9; return x * y; } int main(){ int x = 1, y = 2, z = 3; f1(x,y); x = f2(); printf("main: %d, %d, and %d\n",x,y,z); }
f1: 97, 3, 99 main: 45, 2, and 3